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.

  • 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 '14 at 14:06

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.


import sys, re
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"
        onoff = "0"



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" ]



    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"]:

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


if __name__ == "__main__":
  • 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 '14 at 23:52
  • @AndréFernandes I put it in /usr/sbin/fence_x (with chmod +x)
    – C-Otto
    Nov 7 '14 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 '14 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.