Blame SOURCES/bz1216997-support_for_hp_superdome.patch

44709c
From 3d712dab6d8b1dc7c011a3d9399c3d278329387f Mon Sep 17 00:00:00 2001
44709c
From: Marek 'marx' Grac <mgrac@redhat.com>
44709c
Date: Wed, 17 Jun 2015 09:30:55 +0200
44709c
Subject: [PATCH 2/6] fence_hpblade: Add support for HP Integrity Superdome X
44709c
 (BL920s)
44709c
44709c
Resolves: rhbz#1216997
44709c
---
44709c
 fence/agents/hpblade/fence_hpblade.py | 85 ++++++++++++++++++++++++++++-------
44709c
 1 file changed, 68 insertions(+), 17 deletions(-)
44709c
44709c
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
44709c
index e0b8866..832819c 100644
44709c
--- a/fence/agents/hpblade/fence_hpblade.py
44709c
+++ b/fence/agents/hpblade/fence_hpblade.py
44709c
@@ -3,31 +3,62 @@
44709c
 #####
44709c
 ##
44709c
 ## The Following Agent Has Been Tested On:
44709c
-##  * BladeSystem c7000 Enclosure
44709c
+##  * HP BladeSystem c7000 Enclosure
44709c
+##  * HP Integrity Superdome X (BL920s)
44709c
 #####
44709c
 
44709c
 import sys, re
44709c
+import pexpect, exceptions
44709c
 import atexit
44709c
 sys.path.append("@FENCEAGENTSLIBDIR@")
44709c
 from fencing import *
44709c
 from fencing import fail, EC_STATUS
44709c
 
44709c
 #BEGIN_VERSION_GENERATION
44709c
-RELEASE_VERSION="New Bladecenter Agent - test release on steroids"
44709c
-REDHAT_COPYRIGHT=""
44709c
-BUILD_DATE="March, 2008"
44709c
+RELEASE_VERSION="4.0.11-HP"
44709c
+BUILD_DATE="(built Mon Mar 30 08:31:24 EDT 2015)"
44709c
+REDHAT_COPYRIGHT="Copyright (C) Red Hat, Inc. 2004-2010 All rights reserved."
44709c
 #END_VERSION_GENERATION
44709c
 
44709c
+def get_enclosure_type(conn, options):
44709c
+	conn.send_eol("show enclosure info")
44709c
+	conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
44709c
+
44709c
+	type_re=re.compile(r"^\s*Enclosure Type: (\w+)(.*?)\s*$")
44709c
+	enclosure="unknown"
44709c
+	for line in conn.before.splitlines():
44709c
+		res = type_re.search(line)
44709c
+		if res != None:
44709c
+			enclosure=res.group(1)
44709c
+
44709c
+	if enclosure == "unknown":
44709c
+		fail(EC_GENERIC_ERROR)
44709c
+
44709c
+	return enclosure.lower().strip()
44709c
+
44709c
 def get_power_status(conn, options):
44709c
-	conn.send_eol("show server status " + options["--plug"])
44709c
+	if options["enc_type"] == "superdome":
44709c
+		cmd_send = "parstatus -M -p " + options["--plug"]
44709c
+		powrestr = "^partition:\\d\\s+:\\w+\\s+/(\\w+)\\s.*$"
44709c
+	else:
44709c
+		cmd_send = "show server status " + options["--plug"]
44709c
+		powrestr = "^\\s*Power: (.*?)\\s*$"
44709c
+
44709c
+	conn.send_eol(cmd_send)
44709c
 	conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
44709c
 
44709c
-	power_re = re.compile(r"^\s*Power: (.*?)\s*$")
44709c
+	power_re = re.compile(powrestr)
44709c
 	status = "unknown"
44709c
 	for line in conn.before.splitlines():
44709c
 		res = power_re.search(line)
44709c
 		if res != None:
44709c
-			status = res.group(1)
44709c
+			if options["enc_type"] == "superdome":
44709c
+				if res.group(1) == "DOWN":
44709c
+					status = "off"
44709c
+				else:
44709c
+					status = "on"
44709c
+			else:
44709c
+				status = res.group(1)
44709c
 
44709c
 	if status == "unknown":
44709c
 		if options.has_key("--missing-as-off"):
44709c
@@ -38,23 +69,37 @@ def get_power_status(conn, options):
44709c
 	return status.lower().strip()
44709c
 
44709c
 def set_power_status(conn, options):
44709c
+	if options["enc_type"] == "superdome":
44709c
+		dev="partition "
44709c
+	else:
44709c
+		dev="server "
44709c
+
44709c
 	if options["--action"] == "on":
44709c
-		conn.send_eol("poweron server " + options["--plug"])
44709c
+		conn.send_eol("poweron " + dev + options["--plug"])
44709c
 	elif options["--action"] == "off":
44709c
-		conn.send_eol("poweroff server " + options["--plug"] + " force")
44709c
+		conn.send_eol("poweroff " + dev + options["--plug"] + " force")
44709c
 	conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
44709c
 
44709c
-def get_blades_list(conn, options):
44709c
+def get_instances_list(conn, options):
44709c
 	outlets = {}
44709c
-
44709c
-	conn.send_eol("show server list")
44709c
+	if options["enc_type"] == "superdome":
44709c
+		cmd_send = "parstatus -P -M"
44709c
+		listrestr = "^partition:(\\d+)\\s+:\\w+\\s+/(\\w+)\\s+:OK.*?:(\\w+)\\s*$"
44709c
+	else:
44709c
+		cmd_send = "show server list"
44709c
+		listrestr = "^\\s*(\\d+)\\s+(.*?)\\s+(.*?)\\s+OK\\s+(.*?)\\s+(.*?)\\s*$"
44709c
+
44709c
+	conn.send_eol(cmd_send)
44709c
 	conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
44709c
 
44709c
-	list_re = re.compile(r"^\s*(.*?)\s+(.*?)\s+(.*?)\s+OK\s+(.*?)\s+(.*?)\s*$")
44709c
+	list_re = re.compile(listrestr)
44709c
 	for line in conn.before.splitlines():
44709c
 		res = list_re.search(line)
44709c
 		if res != None:
44709c
-			outlets[res.group(1)] = (res.group(2), res.group(4).lower())
44709c
+			if options["enc_type"] == "superdome":
44709c
+				outlets[res.group(1)] = (res.group(3), res.group(2).lower())
44709c
+			else:
44709c
+				outlets[res.group(1)] = (res.group(2), res.group(4).lower())
44709c
 
44709c
 	return outlets
44709c
 
44709c
@@ -64,14 +109,17 @@ def main():
44709c
 	atexit.register(atexit_handler)
44709c
 
44709c
 	all_opt["cmd_prompt"]["default"] = ["c7000oa>"]
44709c
+	all_opt["login_timeout"]["default"] = "10"
44709c
 
44709c
 	options = check_input(device_opt, process_input(device_opt))
44709c
 
44709c
 	docs = {}
44709c
 	docs["shortdesc"] = "Fence agent for HP BladeSystem"
44709c
 	docs["longdesc"] = "fence_hpblade is an I/O Fencing agent \
44709c
-which can be used with HP BladeSystem. It logs into an enclosure via telnet or ssh \
44709c
-and uses the command line interface to power on and off blades."
44709c
+which can be used with HP BladeSystem and HP Integrity Superdome X. \
44709c
+It logs into the onboard administrator of an enclosure via telnet or \
44709c
+ssh and uses the command line interface to power blades or partitions \
44709c
+on or off."
44709c
 	docs["vendorurl"] = "http://www.hp.com"
44709c
 	show_docs(options, docs)
44709c
 
44709c
@@ -80,7 +128,10 @@ and uses the command line interface to power on and off blades."
44709c
 	######
44709c
 	options["eol"] = "\n"
44709c
 	conn = fence_login(options)
44709c
-	result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
44709c
+
44709c
+	options["enc_type"] = get_enclosure_type(conn, options)
44709c
+
44709c
+	result = fence_action(conn, options, set_power_status, get_power_status, get_instances_list)
44709c
 	fence_logout(conn, "exit")
44709c
 	sys.exit(result)
44709c
 
44709c
-- 
44709c
1.9.3
44709c