Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > d236c5da97a239a1b6991cfba2865b66 > files > 47

cman-2.0.115-68.el5_6.1.src.rpm

From f2f0db60469f811f26123eec87cfc09d9002f35d Mon Sep 17 00:00:00 2001
From: Marek 'marx' Grac <mgrac@redhat.com>
Date: Sat, 25 Sep 2010 00:47:06 +0200
Subject: [PATCH] fence_cisco_ucs: New fence agent for Cisco UCS

Resolves: rhbz#579859
---
 fence/agents/Makefile                     |    3 +
 fence/agents/cisco_ucs/Makefile           |   38 ++++++++
 fence/agents/cisco_ucs/fence_cisco_ucs.py |  138 +++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100644 fence/agents/cisco_ucs/Makefile
 create mode 100755 fence/agents/cisco_ucs/fence_cisco_ucs.py

diff --git a/fence/agents/Makefile b/fence/agents/Makefile
index 4a043ae..0055288 100644
--- a/fence/agents/Makefile
+++ b/fence/agents/Makefile
@@ -22,6 +22,7 @@ all:
 	${MAKE} -C brocade all
 	${MAKE} -C bullpap all
 	${MAKE} -C cisco_mds all
+	${MAKE} -C cisco_ucs all
 	# ${MAKE} -C cpint all
 	${MAKE} -C drac all
 	${MAKE} -C egenera all
@@ -54,6 +55,7 @@ install: all
 	${MAKE} -C brocade install
 	${MAKE} -C bullpap install
 	${MAKE} -C cisco_mds install
+	${MAKE} -C cisco_ucs install
 	# ${MAKE} -C cpint install
 	${MAKE} -C drac install
 	${MAKE} -C egenera install
@@ -86,6 +88,7 @@ clean:
 	${MAKE} -C brocade clean
 	${MAKE} -C bullpap clean
 	${MAKE} -C cisco_mds clean
+	${MAKE} -C cisco_ucs clean
 	# ${MAKE} -C cpint clean
 	${MAKE} -C drac clean
 	${MAKE} -C egenera clean
diff --git a/fence/agents/cisco_ucs/Makefile b/fence/agents/cisco_ucs/Makefile
new file mode 100644
index 0000000..5875ba0
--- /dev/null
+++ b/fence/agents/cisco_ucs/Makefile
@@ -0,0 +1,38 @@
+###############################################################################
+###############################################################################
+##
+##  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
+##  Copyright (C) 2004 Red Hat, Inc.  All rights reserved.
+##  
+##  This copyrighted material is made available to anyone wishing to use,
+##  modify, copy, or redistribute it subject to the terms and conditions
+##  of the GNU General Public License v.2.
+##
+###############################################################################
+###############################################################################
+
+SOURCE= fence_cisco_ucs.py
+TARGET= fence_cisco_ucs
+
+top_srcdir=../..
+include ${top_srcdir}/make/defines.mk
+
+all: $(TARGET)
+
+fence_cisco_ucs: fence_cisco_ucs.py
+	: > $(TARGET)
+	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(SOURCE) >> $(TARGET)
+	echo "FENCE_RELEASE_NAME=\"${RELEASE}\";" >> $(TARGET)
+	${top_srcdir}/scripts/define2var ${top_srcdir}/config/copyright.cf sh REDHAT_COPYRIGHT >> $(TARGET)
+	echo "BUILD_DATE=\"(built `date`)\";" >> $(TARGET)
+	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(SOURCE) >> $(TARGET)
+	chmod +x $(TARGET)
+
+install: all
+	if [ ! -d ${sbindir} ]; then \
+		install -d ${sbindir}; \
+	fi
+	install -m755 ${TARGET} ${sbindir}
+
+clean:
+	rm -f $(TARGET)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
new file mode 100755
index 0000000..07375b3
--- /dev/null
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -0,0 +1,138 @@
+#!/usr/bin/python
+
+import sys, re, pexpect, socket
+import pycurl, StringIO
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New Cisco UCS Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="March, 2008"
+#END_VERSION_GENERATION
+
+re_cookie = re.compile("<aaaLogin .* outCookie=\"(.*?)\"", re.IGNORECASE);
+re_status = re.compile("<lsPower .*? state=\"(.*?)\"", re.IGNORECASE);
+re_get_dn = re.compile(" dn=\"(.*?)\"", re.IGNORECASE)
+re_get_desc = re.compile(" descr=\"(.*?)\"", re.IGNORECASE)
+
+def get_power_status(conn, options):
+	try:
+		res = send_command(options, "<configResolveDn cookie=\"" + options["cookie"] + "\" inHierarchical=\"false\" dn=\"org-root/ls-" + options["-n"] + "/power\"/>")
+	except pycurl.error, e:
+		sys.stderr.write(e[1] + "\n")
+		fail(EC_TIMED_OUT)
+
+	result = re_status.search(res)
+	if (result == None):
+		fail(EC_STATUS)
+	else:
+		status = result.group(1)
+
+	if (status == "up"):
+		return "on"
+	else:
+		return "off"
+
+def set_power_status(conn, options):
+	action = {
+		'on' : "up",
+		'off' : "down"
+	}[options["-o"]]
+	
+	try:
+		res = send_command(options, "<configConfMos cookie=\"" + options["cookie"] + "\" inHierarchical=\"no\"><inConfigs><pair key=\"org-root/ls-" + options["-n"] + "/power\"><lsPower dn=\"org-root/ls-" + options["-n"] + "/power\" state=\"" + action + "\" status=\"modified\" /></pair></inConfigs></configConfMos>")
+	except pycurl.error, e:
+		sys.stderr.write(e[1] + "\n")
+		fail(EC_TIMED_OUT)
+	
+	return
+
+def get_list(conn, options):
+	outlets = { }
+
+	try:
+		try:
+			res = send_command(options, "<configResolveClass cookie=\"" + options["cookie"] + "\" inHierarchical=\"false\" classId=\"lsServer\"/>")
+		except pycurl.error, e:
+			sys.stderr.write(e[1] + "\n")
+			fail(EC_TIMED_OUT)
+
+		lines = res.split("<lsServer ")
+		for i in range(1, len(lines)):
+			dn = re_get_dn.search(lines[i]).group(1)
+			desc = re_get_desc.search(lines[i]).group(1)
+			outlets[dn] = (desc, None)
+	except AttributeError:
+		return { }
+	except IndexError:
+		return { }
+
+	return outlets
+
+def send_command(opt, command):
+	## setup correct URL
+	if opt.has_key("-z"):
+		url = "https:"
+	else:
+		url = "http:"
+
+	url += "//" + opt["-a"] + ":" + str(opt["-u"]) + "/nuova"
+
+	## send command through pycurl
+	c = pycurl.Curl()
+	b = StringIO.StringIO()
+	c.setopt(pycurl.URL, url)
+	c.setopt(pycurl.HTTPHEADER, [ "Content-type: text/xml" ])
+	c.setopt(pycurl.POSTFIELDS, command)
+	c.setopt(pycurl.WRITEFUNCTION, b.write)
+	c.setopt(pycurl.TIMEOUT, int(opt["-Y"]))
+	c.setopt(pycurl.SSL_VERIFYPEER, 0)
+	c.perform()
+	result = b.getvalue()
+
+	if opt["log"] >= LOG_MODE_VERBOSE:
+		opt["debug_fh"].write(command + "\n")
+		opt["debug_fh"].write(result + "\n")
+
+	return result
+
+def main():
+	device_opt = [  "help", "version", "agent", "quiet", "verbose", "debug",
+			"action", "ipaddr", "login", "passwd", "passwd_script",
+			"ssl", "inet4_only", "inet6_only", "ipport", "port", 
+			"web", "separator", "power_wait", "power_timeout",
+			"shell_timeout" ]
+
+	atexit.register(atexit_handler)
+	
+	options = check_input(device_opt, process_input(device_opt))
+
+	docs = { }
+	docs["shortdesc"] = "Fence agent for Cisco UCS"
+	docs["longdesc"] = "fence_cisco_ucs is an I/O Fencing agent which can be \
+used with Cisco UCS to fence machines."
+	docs["vendorurl"] = "http://www.cisco.com"
+	show_docs(options, docs)
+
+	### Login
+	res = send_command(options, "<aaaLogin inName=\"" + options["-l"] + "\" inPassword=\"" + options["-p"] + "\" />")
+	result = re_cookie.search(res)
+	if (result == None):	
+		## Cookie is absenting in response
+		fail(EC_LOGIN_DENIED)
+
+	options["cookie"] = result.group(1);
+
+	##
+	## Fence operations
+	####
+	result = fence_action(None, options, set_power_status, get_power_status, get_list)
+
+	### Logout; we do not care about result as we will end in any case
+	send_command(options, "<aaaLogout inCookie=\"" + options["cookie"] + "\" />")
+	
+	sys.exit(result)
+
+if __name__ == "__main__":
+	main()
-- 
1.6.0.6