Gitweb:
http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=752879...
Commit: 752879cf1f77c85149925f0a48f03215d544ee4f
Parent: 614e01c03d5ff5356caf0652baf9898f3c882d6f
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 15:01:53 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Nov 5 15:01:53 2012 +0100
fence agents: Exceptions (EOF/TIMEOUT) should be handled in fencing library, not in every
fence agent
Basic exception which can happends during get/set/list should be handled in fencing
library and not in
every fence agent. This patch simplify code of fencing agents which uses pexpect and
pycurl.
---
fence/agents/alom/fence_alom.py | 30 +---
fence/agents/apc/fence_apc.py | 229 ++++++++++++-------------
fence/agents/bladecenter/fence_bladecenter.py | 91 ++++------
fence/agents/cisco_ucs/fence_cisco_ucs.py | 28 +---
fence/agents/drac5/fence_drac5.py | 61 +++----
fence/agents/hpblade/fence_hpblade.py | 68 +++-----
fence/agents/ilo/fence_ilo.py | 7 +-
fence/agents/ilo_mp/fence_ilo_mp.py | 38 ++---
fence/agents/ldom/fence_ldom.py | 46 ++---
fence/agents/lib/fencing.py.py | 172 ++++++++++---------
fence/agents/lpar/fence_lpar.py | 108 +++++--------
fence/agents/rhevm/fence_rhevm.py | 20 +--
fence/agents/rsa/fence_rsa.py | 18 +--
fence/agents/rsb/fence_rsb.py | 42 ++---
fence/agents/sanbox2/fence_sanbox2.py | 8 -
fence/agents/virsh/fence_virsh.py | 22 +--
fence/agents/wti/fence_wti.py | 43 ++---
17 files changed, 423 insertions(+), 608 deletions(-)
diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py
index 8d5a4bd..3f39b2d 100644
--- a/fence/agents/alom/fence_alom.py
+++ b/fence/agents/alom/fence_alom.py
@@ -16,31 +16,19 @@ BUILD_DATE=""
#END_VERSION_GENERATION
def get_power_status(conn, options):
- result = ""
- try:
- conn.send_eol("showplatform")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- status = re.search("standby", conn.before.lower())
- result = (status!=None and "off" or "on")
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send_eol("showplatform")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ status = re.search("standby", conn.before.lower())
+ result = (status != None and "off" or "on")
return result
def set_power_status(conn, options):
- try:
- cmd_line = (options["-o"]=="on" and "poweron" or
"poweroff -f -y")
- conn.send_eol(cmd_line)
- conn.log_expect(options, options["-c"], int(options["-g"]))
- #Get the machine some time between poweron and poweroff
- time.sleep(int(options["-g"]))
-
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ cmd_line = (options["-o"] == "on" and "poweron" or
"poweroff -f -y")
+ conn.send_eol(cmd_line)
+ conn.log_expect(options, options["-c"], int(options["-g"]))
+ # Get the machine some time between poweron and poweroff
+ time.sleep(int(options["-g"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script", "cmd_prompt", "secure",
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index fa1c3a6..743627a 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -27,64 +27,60 @@ BUILD_DATE="March, 2008"
def get_power_status(conn, options):
exp_result = 0
outlets = {}
- try:
- conn.send_eol("1")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- version = 0
- admin = 0
- switch = 0
+ conn.send_eol("1")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE |
re.S).match(conn.before)):
- switch = 1
- if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before)):
- if (0 == options.has_key("-s")):
- fail_usage("Failed: You have to enter physical switch number")
- else:
- if (0 == options.has_key("-s")):
- options["-s"] = "1"
+ version = 0
+ admin = 0
+ switch = 0
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before)):
- version = 2
+ if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE |
re.S).match(conn.before)):
+ switch = 1
+ if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before)):
+ if (0 == options.has_key("-s")):
+ fail_usage("Failed: You have to enter physical switch number")
else:
- version = 3
+ if (0 == options.has_key("-s")):
+ options["-s"] = "1"
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE |
re.S).match(conn.before)):
- admin = 0
- else:
- admin = 1
-
- if switch == 0:
- if version == 2:
- if admin == 0:
- conn.send_eol("2")
- else:
- conn.send_eol("3")
- else:
+ if (None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before)):
+ version = 2
+ else:
+ version = 3
+
+ if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE |
re.S).match(conn.before)):
+ admin = 0
+ else:
+ admin = 1
+
+ if switch == 0:
+ if version == 2:
+ if admin == 0:
conn.send_eol("2")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- conn.send_eol("1")
+ else:
+ conn.send_eol("3")
else:
- conn.send_eol(options["-s"])
+ conn.send_eol("2")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send_eol("1")
+ else:
+ conn.send_eol(options["-s"])
- while True:
- exp_result = conn.log_expect(options, [ options["-c"], "Press
<ENTER>" ], int(options["-Y"]))
- lines = conn.before.split("\n")
- show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*')
- for x in lines:
- res = show_re.search(x)
- if (res != None):
- outlets[res.group(2)] = (res.group(3), res.group(4))
- conn.send_eol("")
- if exp_result == 0:
- break
- conn.send(chr(03))
- conn.log_expect(options, "- Logout", int(options["-Y"]))
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ while True:
+ exp_result = conn.log_expect(options, [ options["-c"], "Press
<ENTER>" ], int(options["-Y"]))
+ lines = conn.before.split("\n")
+ show_re = re.compile('(^|\x0D)\s*(\d+)- (.*?)\s+(ON|OFF)\s*')
+ for x in lines:
+ res = show_re.search(x)
+ if (res != None):
+ outlets[res.group(2)] = (res.group(3), res.group(4))
+ conn.send_eol("")
+ if exp_result == 0:
+ break
+ conn.send(chr(03))
+ conn.log_expect(options, "- Logout", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
if ["list", "monitor"].count(options["-o"]) == 1:
return outlets
@@ -101,86 +97,81 @@ def set_power_status(conn, options):
'off': "2"
}[options["-o"]]
- try:
- conn.send_eol("1")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send_eol("1")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+
+ version = 0
+ admin2 = 0
+ admin3 = 0
+ switch = 0
+
+ if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE |
re.S).match(conn.before)):
+ switch = 1
+ ## MasterSwitch has different schema for on/off actions
+ action = {
+ 'on' : "1",
+ 'off': "3"
+ }[options["-o"]]
+ if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before)):
+ if (0 == options.has_key("-s")):
+ fail_usage("Failed: You have to enter physical switch number")
+ else:
+ if (0 == options.has_key("-s")):
+ options["-s"] = 1
- version = 0
- admin2 = 0
- admin3 = 0
- switch = 0
-
- if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE |
re.S).match(conn.before)):
- switch = 1
- ## MasterSwitch has different schema for on/off actions
- action = {
- 'on' : "1",
- 'off': "3"
- }[options["-o"]]
- if (None != re.compile('.* MasterSwitch plus 2', re.IGNORECASE |
re.S).match(conn.before)):
- if (0 == options.has_key("-s")):
- fail_usage("Failed: You have to enter physical switch number")
- else:
- if (0 == options.has_key("-s")):
- options["-s"] = 1
+ if (None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before)):
+ version = 2
+ else:
+ version = 3
- if (None == re.compile('.*Outlet Management.*', re.IGNORECASE |
re.S).match(conn.before)):
- version = 2
- else:
- version = 3
+ if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE |
re.S).match(conn.before)):
+ admin2 = 0
+ else:
+ admin2 = 1
- if (None == re.compile('.*Outlet Control/Configuration.*', re.IGNORECASE |
re.S).match(conn.before)):
- admin2 = 0
- else:
- admin2 = 1
-
- if switch == 0:
- if version == 2:
- if admin2 == 0:
- conn.send_eol("2")
- else:
- conn.send_eol("3")
- else:
+ if switch == 0:
+ if version == 2:
+ if admin2 == 0:
conn.send_eol("2")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- if (None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE |
re.S).match(conn.before)):
- admin3 = 0
- else:
- admin3 = 1
- conn.send_eol("1")
+ else:
+ conn.send_eol("3")
else:
- conn.send_eol(options["-s"])
+ conn.send_eol("2")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ if (None == re.compile('.*2- Outlet Restriction.*', re.IGNORECASE |
re.S).match(conn.before)):
+ admin3 = 0
+ else:
+ admin3 = 1
+ conn.send_eol("1")
+ else:
+ conn.send_eol(options["-s"])
- while 1 == conn.log_expect(options, [ options["-c"], "Press
<ENTER>" ], int(options["-Y"])):
- conn.send_eol("")
+ while 1 == conn.log_expect(options, [ options["-c"], "Press
<ENTER>" ], int(options["-Y"])):
+ conn.send_eol("")
- conn.send_eol(options["-n"]+"")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send_eol(options["-n"]+"")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
- if switch == 0:
- if admin2 == 1:
- conn.send_eol("1")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- if admin3 == 1:
- conn.send_eol("1")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- else:
+ if switch == 0:
+ if admin2 == 1:
conn.send_eol("1")
conn.log_expect(options, options["-c"], int(options["-Y"]))
-
- conn.send_eol(action)
- conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to
cancel :", int(options["-Y"]))
- conn.send_eol("YES")
- conn.log_expect(options, "Press <ENTER> to continue...",
int(options["-Y"]))
- conn.send_eol("")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- conn.send(chr(03))
- conn.log_expect(options, "- Logout", int(options["-Y"]))
+ if admin3 == 1:
+ conn.send_eol("1")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ else:
+ conn.send_eol("1")
conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+
+ conn.send_eol(action)
+ conn.log_expect(options, "Enter 'YES' to continue or <ENTER> to
cancel :", int(options["-Y"]))
+ conn.send_eol("YES")
+ conn.log_expect(options, "Press <ENTER> to continue...",
int(options["-Y"]))
+ conn.send_eol("")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send(chr(03))
+ conn.log_expect(options, "- Logout", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script", "cmd_prompt",
diff --git a/fence/agents/bladecenter/fence_bladecenter.py
b/fence/agents/bladecenter/fence_bladecenter.py
index 2825dbe..726a15f 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -23,72 +23,57 @@ BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- node_cmd = "system:blade\[" + options["-n"] + "\]>"
-
- conn.send_eol("env -T system:blade[" + options["-n"] +
"]")
- i = conn.log_expect(options, [ node_cmd, "system>" ] ,
int(options["-Y"]))
- if i == 1:
- ## Given blade number does not exist
- if options.has_key("-M"):
- return "off"
- else:
- fail(EC_STATUS)
- conn.send_eol("power -state")
- conn.log_expect(options, node_cmd, int(options["-Y"]))
- status = conn.before.splitlines()[-1]
- conn.send_eol("env -T system")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ node_cmd = "system:blade\[" + options["-n"] + "\]>"
+
+ conn.send_eol("env -T system:blade[" + options["-n"] +
"]")
+ i = conn.log_expect(options, [ node_cmd, "system>" ] ,
int(options["-Y"]))
+ if i == 1:
+ ## Given blade number does not exist
+ if options.has_key("-M"):
+ return "off"
+ else:
+ fail(EC_STATUS)
+ conn.send_eol("power -state")
+ conn.log_expect(options, node_cmd, int(options["-Y"]))
+ status = conn.before.splitlines()[-1]
+ conn.send_eol("env -T system")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
return status.lower().strip()
def set_power_status(conn, options):
- try:
- node_cmd = "system:blade\[" + options["-n"] + "\]>"
-
- conn.send_eol("env -T system:blade[" + options["-n"] +
"]")
- i = conn.log_expect(options, [ node_cmd, "system>" ] ,
int(options["-Y"]))
- if i == 1:
- ## Given blade number does not exist
- if options.has_key("-M"):
- return
- else:
- fail(EC_GENERIC_ERROR)
-
- conn.send_eol("power -"+options["-o"])
- conn.log_expect(options, node_cmd, int(options["-Y"]))
- conn.send_eol("env -T system")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ node_cmd = "system:blade\[" + options["-n"] + "\]>"
+
+ conn.send_eol("env -T system:blade[" + options["-n"] +
"]")
+ i = conn.log_expect(options, [ node_cmd, "system>" ] ,
int(options["-Y"]))
+ if i == 1:
+ ## Given blade number does not exist
+ if options.has_key("-M"):
+ return
+ else:
+ fail(EC_GENERIC_ERROR)
+
+ conn.send_eol("power -"+options["-o"])
+ conn.log_expect(options, node_cmd, int(options["-Y"]))
+ conn.send_eol("env -T system")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
def get_blades_list(conn, options):
outlets = { }
- try:
- node_cmd = "system>"
-
- conn.send_eol("env -T system")
- conn.log_expect(options, node_cmd, int(options["-Y"]))
- conn.send_eol("list -l 2")
- conn.log_expect(options, node_cmd, int(options["-Y"]))
-
- lines = conn.before.split("\r\n")
- filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$")
- for blade_line in lines:
- res = filter_re.search(blade_line)
- if res != None:
- outlets[res.group(1)] = (res.group(2), "")
-
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+
+ node_cmd = "system>"
+
+ conn.send_eol("env -T system")
+ conn.log_expect(options, node_cmd, int(options["-Y"]))
+ conn.send_eol("list -l 2")
+ conn.log_expect(options, node_cmd, int(options["-Y"]))
+
+ lines = conn.before.split("\r\n")
+ filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$")
+ for blade_line in lines:
+ res = filter_re.search(blade_line)
+ if res != None:
+ outlets[res.group(1)] = (res.group(2), "")
return outlets
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py
b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index d1d5f2b..5ed2c35 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -17,14 +17,10 @@ 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" +
options["-s"] + \
- "/ls-" + options["-n"] + "/power\"/>", \
- int(options["-Y"]))
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
+ res = send_command(options, \
+ "<configResolveDn cookie=\"" + options["cookie"] +
"\" inHierarchical=\"false\" dn=\"org-root" +
options["-s"] + \
+ "/ls-" + options["-n"] + "/power\"/>", \
+ int(options["-Y"]))
result = RE_STATUS.search(res)
if (result == None):
@@ -43,16 +39,12 @@ def set_power_status(conn, options):
'off' : "down"
}[options["-o"]]
- try:
- res = send_command(options, \
+ res = send_command(options, \
"<configConfMos cookie=\"" + options["cookie"] +
"\" inHierarchical=\"no\">" + \
"<inConfigs><pair key=\"org-root" + options["-s"] +
"/ls-" + options["-n"] + "/power\">" + \
"<lsPower dn=\"org-root/ls-" + options["-n"] +
"/power\" state=\"" + action + "\"
status=\"modified\" />" + \
"</pair></inConfigs></configConfMos>", \
int(options["-Y"]))
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
return
@@ -60,13 +52,9 @@ def get_list(conn, options):
outlets = { }
try:
- try:
- res = send_command(options, \
- "<configResolveClass cookie=\"" + options["cookie"] +
"\" inHierarchical=\"false\"
classId=\"lsServer\"/>", \
- int(options["-Y"]))
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
+ res = send_command(options, \
+ "<configResolveClass cookie=\"" + options["cookie"] +
"\" inHierarchical=\"false\"
classId=\"lsServer\"/>", \
+ int(options["-Y"]))
lines = res.split("<lsServer ")
for i in range(1, len(lines)):
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index d8f4bb8..f8c129d 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -23,17 +23,12 @@ BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- if options["model"] == "DRAC CMC":
- conn.send_eol("racadm serveraction powerstatus -m " +
options["-m"])
- elif options["model"] == "DRAC 5":
- conn.send_eol("racadm serveraction powerstatus")
+ if options["model"] == "DRAC CMC":
+ conn.send_eol("racadm serveraction powerstatus -m " +
options["-m"])
+ elif options["model"] == "DRAC 5":
+ conn.send_eol("racadm serveraction powerstatus")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
status = re.compile("(^|: )(ON|OFF|Powering ON|Powering OFF)\s*$",
re.IGNORECASE | re.MULTILINE).search(conn.before).group(2)
if status.lower().strip() in ["on", "powering on", "powering
off"]:
@@ -47,39 +42,29 @@ def set_power_status(conn, options):
'off': "powerdown"
}[options["-o"]]
- try:
- if options["model"] == "DRAC CMC":
- conn.send_eol("racadm serveraction " + action + " -m " +
options["-m"])
- elif options["model"] == "DRAC 5":
- conn.send_eol("racadm serveraction " + action)
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if options["model"] == "DRAC CMC":
+ conn.send_eol("racadm serveraction " + action + " -m " +
options["-m"])
+ elif options["model"] == "DRAC 5":
+ conn.send_eol("racadm serveraction " + action)
+ conn.log_expect(options, options["-c"], int(options["-g"]))
def get_list_devices(conn, options):
outlets = { }
- try:
- if options["model"] == "DRAC CMC":
- conn.send_eol("getmodinfo")
-
- list_re = re.compile("^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- for line in conn.before.splitlines():
- if (list_re.search(line)):
- outlets[list_re.search(line).group(1)] = ("",
list_re.search(line).group(2))
- elif options["model"] == "DRAC 5":
- ## DRAC 5 can be used only for one computer
- ## standard fence library can't handle correctly situation
- ## when some fence devices supported by fence agent
- ## works with 'list' and other should returns 'N/A'
- print "N/A"
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if options["model"] == "DRAC CMC":
+ conn.send_eol("getmodinfo")
+
+ list_re = re.compile("^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
+ for line in conn.before.splitlines():
+ if (list_re.search(line)):
+ outlets[list_re.search(line).group(1)] = ("",
list_re.search(line).group(2))
+ elif options["model"] == "DRAC 5":
+ ## DRAC 5 can be used only for one computer
+ ## standard fence library can't handle correctly situation
+ ## when some fence devices supported by fence agent
+ ## works with 'list' and other should returns 'N/A'
+ print "N/A"
return outlets
diff --git a/fence/agents/hpblade/fence_hpblade.py
b/fence/agents/hpblade/fence_hpblade.py
index c7ceb19..c4f045e 100644
--- a/fence/agents/hpblade/fence_hpblade.py
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -17,56 +17,42 @@ BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- conn.send_eol("show server status " + options["-n"])
- conn.log_expect(options, options["-c"] , int(options["-Y"]))
+ conn.send_eol("show server status " + options["-n"])
+ conn.log_expect(options, options["-c"] , int(options["-Y"]))
- power_re = re.compile("^\s*Power: (.*?)\s*$")
- status = "unknown"
- for line in conn.before.splitlines():
- res = power_re.search(line)
- if res != None:
- status = res.group(1)
-
- if status == "unknown":
- if options.has_key("-M"):
- return "off"
- else:
- fail(EC_STATUS)
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ power_re = re.compile("^\s*Power: (.*?)\s*$")
+ status = "unknown"
+ for line in conn.before.splitlines():
+ res = power_re.search(line)
+ if res != None:
+ status = res.group(1)
+
+ if status == "unknown":
+ if options.has_key("-M"):
+ return "off"
+ else:
+ fail(EC_STATUS)
return status.lower().strip()
def set_power_status(conn, options):
- try:
- if options["-o"] == "on":
- conn.send_eol("poweron server " + options["-n"])
- elif options["-o"] == "off":
- conn.send_eol("poweroff server " + options["-n"] + "
force")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if options["-o"] == "on":
+ conn.send_eol("poweron server " + options["-n"])
+ elif options["-o"] == "off":
+ conn.send_eol("poweroff server " + options["-n"] + "
force")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
def get_blades_list(conn, options):
outlets = { }
- try:
- conn.send_eol("show server list" )
- conn.log_expect(options, options["-c"], int(options["-Y"]))
-
- list_re = re.compile("^\s*(.*?)\s+(.*?)\s+(.*?)\s+OK\s+(.*?)\s+(.*?)\s*$")
- 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())
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+
+ conn.send_eol("show server list" )
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+
+ list_re = re.compile("^\s*(.*?)\s+(.*?)\s+(.*?)\s+OK\s+(.*?)\s+(.*?)\s*$")
+ 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())
return outlets
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
index 715b163..66472aa 100644
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -26,12 +26,7 @@ def get_power_status(conn, options):
" PASSWORD = \"" + options["-p"] +
"\">\r\n")
conn.send("<SERVER_INFO MODE =
\"read\"><GET_HOST_POWER_STATUS/>\r\n")
conn.send("</SERVER_INFO></LOGIN>\r\n")
- try:
- conn.log_expect(options, "HOST_POWER=\"(.*?)\"",
int(options["-g"]))
- except pexpect.EOF, e:
- fail(EC_STATUS)
- except pexpect.TIMEOUT, e:
- fail(EC_TIMED_OUT)
+ conn.log_expect(options, "HOST_POWER=\"(.*?)\"",
int(options["-g"]))
status = conn.match.group(1)
return status.lower().strip()
diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py
index 9c18336..7cf068a 100644
--- a/fence/agents/ilo_mp/fence_ilo_mp.py
+++ b/fence/agents/ilo_mp/fence_ilo_mp.py
@@ -11,37 +11,27 @@ BUILD_DATE=""
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- conn.send_eol("show /system1")
+ conn.send_eol("show /system1")
- re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
- conn.log_expect(options, re_state, int(options["-Y"]))
+ re_state = re.compile('EnabledState=(.*)', re.IGNORECASE)
+ conn.log_expect(options, re_state, int(options["-Y"]))
- status = conn.match.group(1).lower()
+ status = conn.match.group(1).lower()
- if status.startswith("enabled"):
- return "on"
- else:
- return "off"
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if status.startswith("enabled"):
+ return "on"
+ else:
+ return "off"
def set_power_status(conn, options):
- try:
- if options["-o"] == "on":
- conn.send_eol("start /system1")
- else:
- conn.send_eol("stop -f /system1")
+ if options["-o"] == "on":
+ conn.send_eol("start /system1")
+ else:
+ conn.send_eol("stop -f /system1")
- conn.log_expect(options, options["-c"], int(options["-g"]))
+ conn.log_expect(options, options["-c"], int(options["-g"]))
- return
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ return
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script",
diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py
index edbb2bf..0d67e3f 100644
--- a/fence/agents/ldom/fence_ldom.py
+++ b/fence/agents/ldom/fence_ldom.py
@@ -31,31 +31,25 @@ def start_communication(conn, options):
def get_power_status(conn, options):
- try:
- start_communication(conn, options)
+ start_communication(conn, options)
- conn.send_eol("ldm ls")
+ conn.send_eol("ldm ls")
- conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"]))
+ conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"]))
- result = {}
+ result = {}
- #This is status of mini finite automata. 0 = we didn't found NAME and STATE, 1 = we
did
- fa_status = 0
+ #This is status of mini finite automata. 0 = we didn't found NAME and STATE, 1 = we
did
+ fa_status = 0
- for line in conn.before.splitlines():
- domain = re.search("^(\S+)\s+(\S+)\s+.*$", line)
-
- if (domain!=None):
- if ((fa_status==0) and (domain.group(1)=="NAME") and
(domain.group(2)=="STATE")):
- fa_status = 1
- elif (fa_status==1):
- result[domain.group(1)] = ("", (domain.group(2).lower()=="bound"
and "off" or "on"))
+ for line in conn.before.splitlines():
+ domain = re.search("^(\S+)\s+(\S+)\s+.*$", line)
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if (domain!=None):
+ if ((fa_status==0) and (domain.group(1)=="NAME") and
(domain.group(2)=="STATE")):
+ fa_status = 1
+ elif (fa_status==1):
+ result[domain.group(1)] = ("", (domain.group(2).lower()=="bound"
and "off" or "on"))
if (not (options["-o"] in ['monitor','list'])):
if (not (options["-n"] in result)):
@@ -66,19 +60,13 @@ def get_power_status(conn, options):
return result
def set_power_status(conn, options):
- try:
- start_communication(conn, options)
+ start_communication(conn, options)
- cmd_line = "ldm "+(options["-o"]=="on" and
"start" or "stop -f")+"
\""+options["-n"]+"\""
+ cmd_line = "ldm "+(options["-o"]=="on" and
"start" or "stop -f")+"
\""+options["-n"]+"\""
- conn.send_eol(cmd_line)
+ conn.send_eol(cmd_line)
- conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"]))
-
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script",
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index af21696..9612b40 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -774,89 +774,103 @@ def show_docs(options, docs = None):
def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None):
result = 0
-
- ## Process options that manipulate fencing device
- #####
- if (options["-o"] == "list") and \
- 0 == options["device_opt"].count("port") and 0 ==
options["device_opt"].count("partition") and \
- 0 == options["device_opt"].count("uuid") and 0 ==
options["device_opt"].count("module_name"):
- print "N/A"
- return
- elif (options["-o"] == "list" and get_outlet_list == None):
- ## @todo: exception?
- ## This is just temporal solution, we will remove default value
- ## None as soon as all existing agent will support this operation
- print "NOTICE: List option is not working on this device yet"
- return
- elif (options["-o"] == "list") or ((options["-o"] ==
"monitor") and 1 == options["device_opt"].count("port")):
- outlets = get_outlet_list(tn, options)
- ## keys can be numbers (port numbers) or strings (names of VM)
- for o in outlets.keys():
- (alias, status) = outlets[o]
- if options["-o"] != "monitor":
- print o + options["-C"] + alias
- return
-
- status = get_power_fn(tn, options)
-
- if status != "on" and status != "off":
- fail(EC_STATUS)
-
-
- if options["-o"] == "on":
- if status == "on":
- print "Success: Already ON"
- else:
- power_on = False
- for _ in range(1, 1 + int(options["-F"])):
- set_power_fn(tn, options)
- time.sleep(int(options["-G"]))
- if wait_power_status(tn, options, get_power_fn):
- power_on = True
- break
- if power_on:
- print "Success: Powered ON"
+ try:
+ ## Process options that manipulate fencing device
+ #####
+ if (options["-o"] == "list") and \
+ 0 == options["device_opt"].count("port") and 0 ==
options["device_opt"].count("partition") and \
+ 0 == options["device_opt"].count("uuid") and 0 ==
options["device_opt"].count("module_name"):
+ print "N/A"
+ return
+ elif (options["-o"] == "list" and get_outlet_list == None):
+ ## @todo: exception?
+ ## This is just temporal solution, we will remove default value
+ ## None as soon as all existing agent will support this operation
+ print "NOTICE: List option is not working on this device yet"
+ return
+ elif (options["-o"] == "list") or ((options["-o"] ==
"monitor") and 1 == options["device_opt"].count("port")):
+ outlets = get_outlet_list(tn, options)
+ ## keys can be numbers (port numbers) or strings (names of VM)
+ for o in outlets.keys():
+ (alias, status) = outlets[o]
+ if options["-o"] != "monitor":
+ print o + options["-C"] + alias
+ return
+
+ status = get_power_fn(tn, options)
+
+ if status != "on" and status != "off":
+ fail(EC_STATUS)
+
+
+ if options["-o"] == "on":
+ if status == "on":
+ print "Success: Already ON"
else:
- fail(EC_WAITING_ON)
- elif options["-o"] == "off":
- if status == "off":
- print "Success: Already OFF"
- else:
- set_power_fn(tn, options)
- time.sleep(int(options["-G"]))
- if wait_power_status(tn, options, get_power_fn):
- print "Success: Powered OFF"
+ power_on = False
+ for _ in range(1, 1 + int(options["-F"])):
+ set_power_fn(tn, options)
+ time.sleep(int(options["-G"]))
+ if wait_power_status(tn, options, get_power_fn):
+ power_on = True
+ break
+
+ if power_on:
+ print "Success: Powered ON"
+ else:
+ fail(EC_WAITING_ON)
+ elif options["-o"] == "off":
+ if status == "off":
+ print "Success: Already OFF"
else:
- fail(EC_WAITING_OFF)
- elif options["-o"] == "reboot":
- if status != "off":
- options["-o"] = "off"
- set_power_fn(tn, options)
- time.sleep(int(options["-G"]))
- if wait_power_status(tn, options, get_power_fn) == 0:
- fail(EC_WAITING_OFF)
- options["-o"] = "on"
+ set_power_fn(tn, options)
+ time.sleep(int(options["-G"]))
+ if wait_power_status(tn, options, get_power_fn):
+ print "Success: Powered OFF"
+ else:
+ fail(EC_WAITING_OFF)
+ elif options["-o"] == "reboot":
+ if status != "off":
+ options["-o"] = "off"
+ set_power_fn(tn, options)
+ time.sleep(int(options["-G"]))
+ if wait_power_status(tn, options, get_power_fn) == 0:
+ fail(EC_WAITING_OFF)
+ options["-o"] = "on"
- power_on = False
- for _ in range(1, 1 + int(options["-F"])):
- set_power_fn(tn, options)
- time.sleep(int(options["-G"]))
- if wait_power_status(tn, options, get_power_fn) == 1:
- power_on = True
- break
-
- if power_on == False:
- # this should not fail as node was fenced succesfully
- sys.stderr.write('Timed out waiting to power ON\n')
-
- print "Success: Rebooted"
- elif options["-o"] == "status":
- print "Status: " + status.upper()
- if status.upper() == "OFF":
- result = 2
- elif options["-o"] == "monitor":
- pass
+ power_on = False
+ try:
+ for _ in range(1, 1 + int(options["-F"])):
+ set_power_fn(tn, options)
+ time.sleep(int(options["-G"]))
+ if wait_power_status(tn, options, get_power_fn) == 1:
+ power_on = True
+ break
+ except Exception, ex:
+ # an error occured during power ON phase in reboot
+ # fence action was completed succesfully even in that case
+ sys.stderr.write(str(ex))
+ pass
+
+ if power_on == False:
+ # this should not fail as node was fenced succesfully
+ sys.stderr.write('Timed out waiting to power ON\n')
+
+ print "Success: Rebooted"
+ elif options["-o"] == "status":
+ print "Status: " + status.upper()
+ if status.upper() == "OFF":
+ result = 2
+ elif options["-o"] == "monitor":
+ pass
+ except pexpect.EOF:
+ fail(EC_CONNECTION_LOST)
+ except pexpect.TIMEOUT:
+ fail(EC_TIMED_OUT)
+ except pycurl.error, ex:
+ sys.stderr.write(ex[1] + "\n")
+ fail(EC_TIMED_OUT)
return result
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 5a14d56..4522dfd 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -22,26 +22,16 @@ BUILD_DATE=""
def get_power_status(conn, options):
if options["-H"] == "3":
- try:
- conn.send("lssyscfg -r lpar -m " + options["-s"] + " -n
" + options["-n"] + " -F name,state\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send("lssyscfg -r lpar -m " + options["-s"] + " -n "
+ options["-n"] + " -F name,state\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
try:
status = re.compile("^" + options["-n"] + ",(.*?),.*$",
re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
except AttributeError:
fail(EC_STATUS_HMC)
elif options["-H"] == "4":
- try:
- conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter
'lpar_names=" + options["-n"] + "'\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send("lssyscfg -r lpar -m "+ options["-s"] +" --filter
'lpar_names=" + options["-n"] + "'\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
try:
status = re.compile(",state=(.*?),",
re.IGNORECASE).search(conn.before).group(1)
@@ -59,73 +49,53 @@ def get_power_status(conn, options):
def set_power_status(conn, options):
if options["-H"] == "3":
- try:
- conn.send("chsysstate -o " + options["-o"] + " -r lpar -m
" + options["-s"]
- + " -n " + options["-n"] + "\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send("chsysstate -o " + options["-o"] + " -r lpar -m
" + options["-s"]
+ + " -n " + options["-n"] + "\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
elif options["-H"] == "4":
- try:
- if options["-o"] == "on":
- conn.send("chsysstate -o on -r lpar -m " + options["-s"] +
- " -n " + options["-n"] +
- " -f `lssyscfg -r lpar -F curr_profile " +
- " -m " + options["-s"] +
- " --filter \"lpar_names="+ options["-n"]
+"\"`\n" )
- else:
- conn.send("chsysstate -o shutdown -r lpar --immed" +
- " -m " + options["-s"] + " -n " +
options["-n"] + "\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ if options["-o"] == "on":
+ conn.send("chsysstate -o on -r lpar -m " + options["-s"] +
+ " -n " + options["-n"] +
+ " -f `lssyscfg -r lpar -F curr_profile " +
+ " -m " + options["-s"] +
+ " --filter \"lpar_names="+ options["-n"]
+"\"`\n" )
+ else:
+ conn.send("chsysstate -o shutdown -r lpar --immed" +
+ " -m " + options["-s"] + " -n " +
options["-n"] + "\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
def get_lpar_list(conn, options):
outlets = { }
if options["-H"] == "3":
- try:
- conn.send("query_partition_names -m " + options["-s"] +
"\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
+ conn.send("query_partition_names -m " + options["-s"] +
"\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
- ## We have to remove first 3 lines (command + header) and last line (part of new
prompt)
- ####
- res = re.search("^.+?\n(.+?\n){2}(.*)\n.*$", conn.before, re.S)
+ ## We have to remove first 3 lines (command + header) and last line (part of new
prompt)
+ ####
+ res = re.search("^.+?\n(.+?\n){2}(.*)\n.*$", conn.before, re.S)
- if res == None:
- fail_usage("Unable to parse output of list command")
+ if res == None:
+ fail_usage("Unable to parse output of list command")
- lines = res.group(2).split("\n")
- for outlet_line in lines:
- outlets[outlet_line.rstrip()] = ("", "")
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ lines = res.group(2).split("\n")
+ for outlet_line in lines:
+ outlets[outlet_line.rstrip()] = ("", "")
elif options["-H"] == "4":
- try:
- conn.send("lssyscfg -r lpar -m " + options["-s"] +
- " -F name:state\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
+ conn.send("lssyscfg -r lpar -m " + options["-s"] +
+ " -F name:state\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
- ## We have to remove first line (command) and last line (part of new prompt)
- ####
- res = re.search("^.+?\n(.*)\n.*$", conn.before, re.S)
+ ## We have to remove first line (command) and last line (part of new prompt)
+ ####
+ res = re.search("^.+?\n(.*)\n.*$", conn.before, re.S)
- if res == None:
- fail_usage("Unable to parse output of list command")
+ if res == None:
+ fail_usage("Unable to parse output of list command")
- lines = res.group(1).split("\n")
- for outlet_line in lines:
- (port, status) = outlet_line.split(":")
- outlets[port] = ("", status)
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ lines = res.group(1).split("\n")
+ for outlet_line in lines:
+ (port, status) = outlet_line.split(":")
+ outlets[port] = ("", status)
return outlets
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index e1de315..7f5abde 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -18,11 +18,7 @@ RE_GET_NAME = re.compile("<name>(.*?)</name>",
re.IGNORECASE)
def get_power_status(conn, options):
### Obtain real ID from name
- try:
- res = send_command(options, "vms/?search=name%3D" + options["-n"])
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
+ res = send_command(options, "vms/?search=name%3D" + options["-n"])
result = RE_GET_ID.search(res)
if (result == None):
@@ -52,23 +48,13 @@ def set_power_status(conn, options):
}[options["-o"]]
url = "vms/" + options["id"] + "/" + action
- try:
- res = send_command(options, url, "POST")
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
-
- return
+ res = send_command(options, url, "POST")
def get_list(conn, options):
outlets = { }
try:
- try:
- res = send_command(options, "vms")
- except pycurl.error, e:
- sys.stderr.write(e[1] + "\n")
- fail(EC_TIMED_OUT)
+ res = send_command(options, "vms")
lines = res.split("<vm ")
for i in range(1, len(lines)):
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index 44ad33f..75cf1f7 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -18,13 +18,8 @@ BUILD_DATE=""
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- conn.send_eol("power state")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send_eol("power state")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
match = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before)
if (match != None):
@@ -35,13 +30,8 @@ def get_power_status(conn, options):
return status.lower().strip()
def set_power_status(conn, options):
- try:
- conn.send_eol("power " + options["-o"])
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send_eol("power " + options["-o"])
+ conn.log_expect(options, options["-c"], int(options["-g"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script",
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index f8cd827..40c922e 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -11,18 +11,13 @@ BUILD_DATE=""
#END_VERSION_GENERATION
def get_power_status(conn, options):
- try:
- conn.send("2")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- status = re.compile("Power Status : (on|off)",
re.IGNORECASE).search(conn.before).group(1)
- conn.send("0")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send("2")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ status = re.compile("Power Status : (on|off)",
re.IGNORECASE).search(conn.before).group(1)
+ conn.send("0")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
- return (status.lower().strip())
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ return (status.lower().strip())
def set_power_status(conn, options):
action = {
@@ -30,21 +25,16 @@ def set_power_status(conn, options):
'off': "1"
}[options["-o"]]
- try:
- conn.send("2")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- conn.send_eol(action)
- conn.log_expect(options, ["want to power off", "'yes' or
'no'"], int(options["-Y"]))
- conn.send_eol("yes")
- conn.log_expect(options, "any key to continue",
int(options["-g"]))
- conn.send_eol("")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- conn.send_eol("0")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send("2")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send_eol(action)
+ conn.log_expect(options, ["want to power off", "'yes' or
'no'"], int(options["-Y"]))
+ conn.send_eol("yes")
+ conn.log_expect(options, "any key to continue", int(options["-g"]))
+ conn.send_eol("")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.send_eol("0")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script",
diff --git a/fence/agents/sanbox2/fence_sanbox2.py
b/fence/agents/sanbox2/fence_sanbox2.py
index 1ed71cf..173c819 100644
--- a/fence/agents/sanbox2/fence_sanbox2.py
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -26,8 +26,6 @@ def get_power_status(conn, options):
try:
conn.send_eol("show port " + options["-n"])
conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
try:
conn.send_eol("admin end")
@@ -53,8 +51,6 @@ def set_power_status(conn, options):
try:
conn.send_eol("set port " + options["-n"] + " state " +
action)
conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
try:
conn.send_eol("admin end")
@@ -67,8 +63,6 @@ def set_power_status(conn, options):
try:
conn.send_eol("set port " + options["-n"] + " state " +
action)
conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
try:
conn.send_eol("admin end")
@@ -94,8 +88,6 @@ def get_list_devices(conn, options):
}[list_re.search(line).group(2).lower()]
outlets[list_re.search(line).group(1)] = ("", status)
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
try:
conn.send_eol("admin end")
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index cb33a56..c8c49a4 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -21,14 +21,8 @@ def get_outlets_status(conn, options):
else:
prefix = ""
- try:
- conn.sendline(prefix + "virsh list --all")
- conn.interact()
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.sendline(prefix + "virsh list --all")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
result = {}
@@ -59,16 +53,10 @@ def set_power_status(conn, options):
else:
prefix = ""
- try:
- conn.sendline(prefix + "virsh %s "%(options["-o"] == "on"
and "start" or "destroy")+options["-n"])
-
- conn.log_expect(options, options["-c"], int(options["-g"]))
- time.sleep(1)
+ conn.sendline(prefix + "virsh %s "%(options["-o"] == "on"
and "start" or "destroy")+options["-n"])
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.log_expect(options, options["-c"], int(options["-g"]))
+ time.sleep(1)
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script", "cmd_prompt",
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index b1fdd05..2337e10 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -24,27 +24,21 @@ BUILD_DATE="March, 2008"
def get_power_status(conn, options):
listing = ""
- try:
- conn.send("/S"+"\r\n")
-
- if isinstance(options["-c"], list):
- re_all = list(options["-c"])
- else:
- re_all = [options["-c"]]
- re_next = re.compile("Enter: ", re.IGNORECASE)
- re_all.append(re_next)
-
- result = conn.log_expect(options, re_all, int(options["-Y"]))
- listing = conn.before
- if result == (len(re_all) - 1):
- conn.send("\r\n")
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- listing += conn.before
-
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send("/S"+"\r\n")
+
+ if isinstance(options["-c"], list):
+ re_all = list(options["-c"])
+ else:
+ re_all = [options["-c"]]
+ re_next = re.compile("Enter: ", re.IGNORECASE)
+ re_all.append(re_next)
+
+ result = conn.log_expect(options, re_all, int(options["-Y"]))
+ listing = conn.before
+ if result == (len(re_all) - 1):
+ conn.send("\r\n")
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
+ listing += conn.before
plug_section = 0
plug_index = -1
@@ -84,13 +78,8 @@ def set_power_status(conn, options):
'off': "/off"
}[options["-o"]]
- try:
- conn.send(action + " " + options["-n"] + ",y\r\n")
- conn.log_expect(options, options["-c"], int(options["-g"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.send(action + " " + options["-n"] + ",y\r\n")
+ conn.log_expect(options, options["-c"], int(options["-g"]))
def main():
device_opt = [ "ipaddr", "login", "passwd",
"passwd_script",