I'm trying to raise a Proxmox HA cluster with OVH rootsevers. One must-have requirement is a working fence device. As I could not find other ways to implement this with OVH, I wrote a own quick-and-dirty fence agent in python. It's working that far, but it's not really good in any way. In fact, it's quite bad Besides the ugly Python code - What is really bad for using it in productive environments: there is not yet any verification of success.
I post it here hoping that you can help to improve it. If you need the OVH SOAP API reference, you can find it at http://www.ovh.com/soapi/en/
Dennis Busch
I post it here hoping that you can help to improve it. If you need the OVH SOAP API reference, you can find it at http://www.ovh.com/soapi/en/
Code:
#!/usr/bin/python
#This is a fence agent for use at OVH
#As there are no other fence devices available, we must use OVH's SOAP API #Quick-and-dirty assemled by Dennis Busch, secofor GmbH, Germany #Thanks to Elbrunz's Blog for the config parsing code [URL]http://elbrunz.wordpress.com[/URL] #This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
import sys
from SOAPpy import WSDL
import time
def action_do(nodename,login,passwd,email,mode):
soap = WSDL.Proxy('https://www.ovh.com/soapi/soapi-re-1.47.wsdl')
session = soap.login(login, passwd, 'de', 0)
#dedicatedNetbootModifyById changes the mode of the next reboot
result = soap.dedicatedNetbootModifyById(session, nodename, mode, '')
#dedicatedHardRebootDo initiates a hard reboot on the given node
soap.dedicatedHardRebootDo(session, nodename, 'Fencing initiated by cluster', '', 'de')
soap.logout(session)
#print stderr to file
save_stderr = sys.stderr
errlog = open("/var/log/fence_ovh_error.log","a")
sys.stderr = errlog
#I use a own logfile for debugging purpose logfile=open("/var/log/fence_ovh.log", "a"); logfile.write(time.strftime("%d.%m.%Y %H:%M:%S \t"))
logfile.write("Parameter:\t")
for val in sys.argv:
logfile.write(val + " ")
logfile.write("\n")
logfile.write("Optionen\t")
#fenced hands over the attributes via stdin #thanks to Elbrunz for the following parser lines COMMENT_CHAR = '#'
OPTION_CHAR = '='
options = {}
for line in sys.stdin.readlines():
logfile.write(line)
# First, remove comments:
if COMMENT_CHAR in line:
# split on comment char, keep only the part before
line, comment = line.split(COMMENT_CHAR, 1)
# Second, find lines with an option=value:
if OPTION_CHAR in line:
# split on option char:
option, value = line.split(OPTION_CHAR, 1)
# strip spaces:
option = option.strip()
value = value.strip()
# store in dictionary:
options[option] = value
for val in options:
logfile.write(val + "\n")
logfile.write("\n")
if 'action' in options:
action=options['action']
else:
logfile.write("nothing to do")
sys.exit()
if 'login' in options:
login=options['login']
if 'passwd' in options:
passwd=options['passwd']
if 'email' in options:
email=options['email']
if 'nodename' in options:
nodename=options['nodename']
if nodename[-8:] != '.ovh.net':
nodename += '.ovh.net'
if action == 'off':
action_do(nodename,login,passwd,email,'29') #Reboot in vKVM elif action == 'on':
action_do(nodename,login,passwd,email,'1') #Reboot from HD elif action == 'reboot':
action_do(nodename,login,passwd,email, '1') #Reboot from HD
else:
logfile.write("nothing to do")
sys.exit()
errlog.close()
logfile.close()
Last edited by a moderator: