Centos

Centos 7 中的簡單圍欄/STONITH 腳本

  • December 2, 2014

我正在使用 Centos 7 安裝一個簡單的 Corosync/pacemaker/drbd 高可用性集群,並希望使用自定義硬體(使用 USB 連接的電源開關)提供防護/STONITH。因此,我需要將這些設備作為 STONITH 資源添加到我的集群中。我可以從一個簡單的虛擬腳本開始嗎?我在 中找到了幾個文件/usr/sbin/fence_*,但這些文件似乎是通過某種網路連接的,並且只接受預配置的選項。

這是一個基於fence_cisco_ucs. 我不知道為什麼密碼欄位是強制性的,我也不知道get_list應該做什麼。

例如,./script.py -o status -p x -s y給出“狀態:開啟”。如果get_power_status和中的功能進行了set_power_status相應的修改,則此腳本實際上可能很有用。

#!/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()

引用自:https://serverfault.com/questions/627006