Centos – Simple fencing/STONITH script in Centos 7

centoscorosyncfencinghigh-availabilitypacemaker

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.

Best Answer

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()
Related Topic