2

I am installing a simple Corosync/pacemaker/drbd high availability cluster using Centos 7 and would like to provide fencing/STONITH using custom hardware (power switches using USB connections). As such, I need to add these devices as STONITH resources in my cluster. Is there a simple dummy script I can start with? I found several files in /usr/sbin/fence_*, but these seem to connect via some sort of network and only accept pre-configured options.

1
  • fence_cisco_ucs defines new arguments in define_new_opts using the predefined all_opt hash. I guess I can work with that.
    – C-Otto
    Sep 8, 2014 at 14:06

1 Answer 1

1

Here's a minimal script based on fence_cisco_ucs. I do not know why the password field is mandatory, and I have no idea what get_list is supposed to do.

For example, ./script.py -o status -p x -s y gives "Status: ON". If the functionality in get_power_status and set_power_status is modified accordingly, this script might actually be useful.

#!/usr/bin/python

import sys, re
sys.path.append("/usr/share/fence")
from fencing import *

def get_power_status(conn, options):
    someoption = options["--someoption"]

    #status = send_command(someoption)
    status = "on"

    return status

def set_power_status(conn, options):
    action = options["--action"]
    if action == "on":
        onoff = "1"
    else:
        onoff = "0"

    #send_command(onoff)

    return

def get_list(conn, options):
    outlets = { }

    return outlets

def define_new_opts():
    all_opt["someoption"] = {
        "getopt" : "s:",
        "longopt" : "someoption",
        "help" : "--someoption=[string]       Some option.",
        "required" : "1",
        "shortdesc" : "Some option.",
        "order" : 1 }

def main():
    device_opt = [ "passwd", "someoption" ]

    atexit.register(atexit_handler)

    define_new_opts()

    options = check_input(device_opt, process_input(device_opt))

    docs = { }
    docs["shortdesc"] = "Short Description"
    docs["longdesc"] = "Longer Description"
    docs["vendorurl"] = "http://somewhere"
    show_docs(options, docs)

    ## Do the delay of the fence device before logging in
    ## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
    if options["--action"] in ["off", "reboot"]:
        time.sleep(int(options["--delay"]))

    result = fence_action(None, options, set_power_status, get_power_status, get_list)

    sys.exit(result)

if __name__ == "__main__":
    main()
3
  • how did you integrate it into pcs so that it can be referred to in the config and mentioned in pcs stonith create fence_x? Nov 6, 2014 at 23:52
  • @AndréFernandes I put it in /usr/sbin/fence_x (with chmod +x)
    – C-Otto
    Nov 7, 2014 at 7:21
  • To further detail your answer to my question: integration is done via the fence script's -o metadata option. pcs will call fence_x -o metadata and expect some XML which describes the arguments and commands that the script will accept. Nov 7, 2014 at 10:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .