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