[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Linux-cluster] fence_ovh - Fence agent for OVH (Proxmox 3)



Hi Adrian,

On 06/26/2013 07:55 PM, Adrian Gibanel wrote:
   I've improved my former fence_ovh script so that it works in Proxmox 3 and so that it uses suds library as I was suggested in the linux-cluster mailing list.

1) What is fence_ovh

fence_ovh is a fence agent based on python for the big French datacentre provider OVH. You can get information about OVH on: http://www.ovh.co.uk/ . I also wanted to make clear that I'm not part of official OVH staff.

Thanks, you have done a great job in that rewrite. I have modified it a little to better fit into our existing infrastructure (--verbose, --plug). The only real change that I have added is that SOAP is not disconnected after every operation. Please take a look at it and (very likely) fix minor errors which I have introduced as I was not able to test it.

m,
>From 53b13691d119a9bb3686bc2bc6848147a0c37186 Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac redhat com>
Date: Tue, 9 Jul 2013 23:37:59 +0200
Subject: [PATCH] fence_ovh: New fence agent for OVH

---
 configure.ac                  |    1 +
 fence/agents/ovh/Makefile.am  |   17 +++++
 fence/agents/ovh/fence_ovh.py |  138 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 fence/agents/ovh/Makefile.am
 create mode 100644 fence/agents/ovh/fence_ovh.py

diff --git a/configure.ac b/configure.ac
index f3acb13..910cab8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,7 @@ AC_CONFIG_FILES([Makefile
 		 fence/agents/mcdata/Makefile
 		 fence/agents/nss_wrapper/Makefile
 		 fence/agents/rackswitch/Makefile
+		 fence/agents/ovh/Makefile
 		 fence/agents/rhevm/Makefile
 		 fence/agents/rsa/Makefile
 		 fence/agents/rsb/Makefile
diff --git a/fence/agents/ovh/Makefile.am b/fence/agents/ovh/Makefile.am
new file mode 100644
index 0000000..c6d7d01
--- /dev/null
+++ b/fence/agents/ovh/Makefile.am
@@ -0,0 +1,17 @@
+MAINTAINERCLEANFILES	= Makefile.in
+
+TARGET			= fence_ovh
+
+SRC			= $(TARGET).py
+
+EXTRA_DIST		= $(SRC)
+
+sbin_SCRIPTS		= $(TARGET)
+
+man_MANS		= $(TARGET).8
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+
+clean-local: clean-man
+	rm -f $(TARGET)
diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py
new file mode 100644
index 0000000..23375c4
--- /dev/null
+++ b/fence/agents/ovh/fence_ovh.py
@@ -0,0 +1,138 @@
+#!/usr/bin/python
+# Copyright 2013 Adrian Gibanel Lopez (bTactic)
+# Adrian Gibanel improved this script at 2013 to add verification of success and to output metadata
+
+# Based on:
+# 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
+# This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
+
+import sys, time
+from datetime import datetime
+from suds.client import Client
+from suds.xsd.doctor import ImportDoctor, Import
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+OVH_RESCUE_PRO_NETBOOT_ID = '28'
+OVH_HARD_DISK_NETBOOT_ID  = '1'
+
+STATUS_HARD_DISK_SLEEP = 240 # Wait 4 minutes to SO to boot
+STATUS_RESCUE_PRO_SLEEP = 150 # Wait 2 minutes 30 seconds to Rescue-Pro to run
+
+def define_new_opts():
+	all_opt["email"] = {
+		"getopt" : "Z:",
+		"longopt" : "email",
+		"help" : "-Z, --email=<email>          email for reboot message: admin domain com",
+		"required" : "1",
+		"shortdesc" : "Reboot email",
+		"default" : "",
+		"order" : 1 }
+
+def netboot_reboot(conn, options, mode):
+	# dedicatedNetbootModifyById changes the mode of the next reboot
+	conn.service.dedicatedNetbootModifyById(options["session"], options["--plug"], mode, '', options["--email"])
+ 
+	# dedicatedHardRebootDo initiates a hard reboot on the given node
+	conn.service.dedicatedHardRebootDo(options["session"], options["--plug"], 'Fencing initiated by cluster', '', 'es')
+
+def reboot_time(conn, options):
+	result = conn.service.dedicatedHardRebootStatus(options["session"], options["--plug"])
+	tmpstart = datetime.strptime(result.start,'%Y-%m-%d %H:%M:%S')
+	tmpend = datetime.strptime(result.end,'%Y-%m-%d %H:%M:%S')
+	result.start = tmpstart
+	result.end = tmpend
+
+	return result
+
+def soap_login(options):
+	imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
+	url = 'https://www.ovh.com/soapi/soapi-re-1.59.wsdl'
+	imp.filter.add('http://soapi.ovh.com/manager')
+	d = ImportDoctor(imp)
+
+	try:
+		soap = Client(url, doctor=d)
+		session = soap.service.login(options["--username"], options["--password"], 'es', 0)
+	except Exception, ex:
+		fail(EC_LOGIN_DENIED)   
+
+	options["session"] = session
+	return soap
+	
+def main():
+	device_opt = [ "login", "passwd", "port", "email" ]
+
+	atexit.register(atexit_handler)
+
+	define_new_opts()
+	options = check_input(device_opt, process_input(device_opt))
+
+	docs = { }
+	docs["shortdesc"] = "Fence agent for OVH"
+	docs["longdesc"] = "fence_ovh is an Power Fencing agent \
+which can be used within OVH datecentre. \
+Poweroff is simulated with a reboot into rescue-pro mode."
+
+	docs["vendorurl"] = "http://www.ovh.net";
+	show_docs(options, docs)
+
+	if options["--action"] in [ "list", "status"]:
+		fail_usage("Action '" + options["--action"] + "' is not supported in this fence agent")
+
+	if options["--plug"].endswith(".ovh.net") == False:
+		options["--plug"] += ".ovh.net"
+
+	if options.has_key("--email") == False:
+		fail_usage("You have to enter e-mail address which is notified by fence agent")
+
+	conn = soap_login(options)
+
+	# Save datetime just before changing netboot
+	before_netboot_reboot = datetime.now()
+
+	if options["--action"] == 'off':
+		# Reboot in Rescue-pro
+		netboot_reboot(conn, options,OVH_RESCUE_PRO_NETBOOT_ID)
+		time.sleep(STATUS_RESCUE_PRO_SLEEP)
+	elif options["--action"] in  ['on', 'off' ]:
+		# Reboot from HD
+		netboot_reboot(conn, options,OVH_HARD_DISK_NETBOOT_ID)
+		time.sleep(STATUS_HARD_DISK_SLEEP)
+
+	# Save datetime just after reboot
+	after_netboot_reboot = datetime.now()
+
+	# Verify that action was completed sucesfully
+	reboot_t = reboot_time(conn, options)
+
+	if options.has_key("--verbose"):
+		options["debug_fh"].write("reboot_start_end.start: "+ reboot_t.start.strftime('%Y-%m-%d %H:%M:%S')+"\n")         
+		options["debug_fh"].write("before_netboot_reboot: " + before_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S')+"\n")
+		options["debug_fh"].write("reboot_start_end.end: "  + reboot_t.end.strftime('%Y-%m-%d %H:%M:%S')+"\n")        
+		options["debug_fh"].write("after_netboot_reboot: "  + after_netboot_reboot.strftime('%Y-%m-%d %H:%M:%S')+"\n")  
+                
+	if reboot_t.start < after_netboot_reboot < reboot_t.end:
+		result = 0
+		if options.has_key("--verbose"):
+			options["debug_fh"].write("Netboot reboot went OK.\n")
+	else:
+		result = 1
+		if options.has_key("--verbose"):
+			options["debug_fh"].write("ERROR: Netboot reboot wasn't OK.\n")
+
+        ##
+        ## Logout from system
+        #####
+	try:
+		conn.service.logout(options["session"])
+	except Exception, ex:
+		pass
+
+	sys.exit(result)
+
+
+if __name__ == "__main__":
+	main()
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]