dlm: master - --foreground option added to dlm_controld
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=dlm.git;a=commitdiff;h=ea0b5a37ab1bbc0...
Commit: ea0b5a37ab1bbc0f34a8ba49629d7350cfd55cd4
Parent: 47115c611ff9861900d374879b50818831b6d663
Author: Jacek Konieczny <jajcus(a)jajcus.net>
AuthorDate: Sat Nov 3 16:27:55 2012 +0100
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Nov 5 13:34:31 2012 -0600
--foreground option added to dlm_controld
Foreground is the preferred way to run services from systemd
and it is easier to provide startup notification this way.
Signed-off-by: Jacek Konieczny <jajcus(a)jajcus.net>
---
dlm_controld/dlm_controld.8 | 3 +++
dlm_controld/dlm_daemon.h | 1 +
dlm_controld/main.c | 7 ++++++-
3 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/dlm_controld/dlm_controld.8 b/dlm_controld/dlm_controld.8
index 262ef8a..c9011fd 100644
--- a/dlm_controld/dlm_controld.8
+++ b/dlm_controld/dlm_controld.8
@@ -23,6 +23,9 @@ For default settings, see dlm_controld -h.
.B --daemon_debug | -D
enable debugging to stderr and don't fork
+.B --foreground
+ don't fork
+
.B --log_debug | -K
enable kernel dlm debugging messages
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
index 916ee58..377f28d 100644
--- a/dlm_controld/dlm_daemon.h
+++ b/dlm_controld/dlm_daemon.h
@@ -109,6 +109,7 @@ enum {
enable_quorum_lockspace_ind,
help_ind,
version_ind,
+ foreground_ind,
dlm_options_max,
};
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index fd469f9..deda60c 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -1245,6 +1245,11 @@ static void set_opt_defaults(void)
0, NULL,
"enable debugging to stderr and don't fork");
+ set_opt_default(foreground_ind,
+ "foreground", '\0', no_arg,
+ 0, NULL,
+ "don't fork");
+
set_opt_default(log_debug_ind,
"log_debug", 'K', no_arg,
0, NULL,
@@ -1562,7 +1567,7 @@ int main(int argc, char **argv)
INIT_LIST_HEAD(&fs_register_list);
init_daemon();
- if (!opt(daemon_debug_ind)) {
+ if (!opt(daemon_debug_ind) && !opt(foreground_ind)) {
if (daemon(0, 0) < 0) {
perror("daemon error");
exit(EXIT_FAILURE);
11 years, 6 months
fence-agents: master - fence agents: Exceptions (EOF/TIMEOUT) should be handled in fencing library, not in every fence agent
by Marek Grác
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",
11 years, 6 months
fence-agents: master - code cleanup: Fix warnings according to pylint and typos
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=614e01...
Commit: 614e01c03d5ff5356caf0652baf9898f3c882d6f
Parent: db1d7376180a0d4329a8ab5fe78690b0c77fa2c3
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 14:52:37 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Nov 5 14:53:23 2012 +0100
code cleanup: Fix warnings according to pylint and typos
* remove unused 'global'
* typos
* start with renaming global variables from foo to FOO (python convention)
---
fence/agents/apc/fence_apc.py | 1 +
fence/agents/apc_snmp/fence_apc_snmp.py | 8 +---
fence/agents/bladecenter/fence_bladecenter.py | 4 +-
fence/agents/cisco_mds/fence_cisco_mds.py | 14 ++----
fence/agents/cisco_ucs/fence_cisco_ucs.py | 32 ++++++++----
fence/agents/eaton_snmp/fence_eaton_snmp.py | 8 +--
fence/agents/hpblade/fence_hpblade.py | 8 ++--
fence/agents/ibmblade/fence_ibmblade.py | 12 ++--
fence/agents/ifmib/fence_ifmib.py | 2 -
fence/agents/intelmodular/fence_intelmodular.py | 2 -
fence/agents/ipdu/fence_ipdu.py | 10 +---
fence/agents/lib/fencing.py.py | 58 ++++++++++------------
fence/agents/lpar/fence_lpar.py | 10 ++--
fence/agents/rhevm/fence_rhevm.py | 13 ++---
fence/agents/vmware/fence_vmware.py | 2 +-
fence/agents/wti/fence_wti.py | 1 -
16 files changed, 83 insertions(+), 102 deletions(-)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index d0ed9b6..fa1c3a6 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -153,6 +153,7 @@ def set_power_status(conn, options):
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"]))
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index cc624a1..6f95f37 100644
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -88,7 +88,7 @@ def apc_set_device(conn, options):
conn.log_command("Trying %s"%(device.ident_str))
def apc_resolv_port_id(conn, options):
- global port_id, switch_id, device
+ global port_id, switch_id
if (device == None):
apc_set_device(conn, options)
@@ -115,8 +115,6 @@ def apc_resolv_port_id(conn, options):
fail_usage("Can't find port with name %s!"%(options["-n"]))
def get_power_status(conn, options):
- global port_id, switch_id, device
-
if (port_id == None):
apc_resolv_port_id(conn, options)
@@ -126,8 +124,6 @@ def get_power_status(conn, options):
return (status==str(device.state_on) and "on" or "off")
def set_power_status(conn, options):
- global port_id, switch_id, device
-
if (port_id == None):
apc_resolv_port_id(conn, options)
@@ -137,8 +133,6 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
- global device
-
result = {}
if (device == None):
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index 49a3b5b..2825dbe 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -80,8 +80,8 @@ def get_blades_list(conn, options):
lines = conn.before.split("\r\n")
filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$")
- for x in lines:
- res = filter_re.search(x)
+ for blade_line in lines:
+ res = filter_re.search(blade_line)
if res != None:
outlets[res.group(1)] = (res.group(2), "")
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index 8f3ef9d..8ebce8a 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -27,7 +27,7 @@ PORTS_OID = ".1.3.6.1.2.1.2.2.1.2"
### GLOBAL VARIABLES ###
# OID converted from fc port name (fc(x)/(y))
-port_oid = ""
+PORT_OID = ""
### FUNCTIONS ###
@@ -43,15 +43,11 @@ def cisco_port2oid(port):
fail_usage("Mangled port number: %s"%(port))
def get_power_status(conn, options):
- global port_oid
-
- (oid, status) = conn.get(port_oid)
+ (oid, status) = conn.get(PORT_OID)
return (status=="1" and "on" or "off")
def set_power_status(conn, options):
- global port_oid
-
- conn.set(port_oid,(options["-o"]=="on" and 1 or 2))
+ conn.set(PORT_OID, (options["-o"]=="on" and 1 or 2))
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
@@ -79,7 +75,7 @@ def get_outlets_status(conn, options):
# Main agent method
def main():
- global port_oid
+ global PORT_OID
device_opt = [ "fabric_fencing", "ipaddr", "login", "passwd", "passwd_script",
"test", "port", "separator", "no_login", "no_password",
@@ -101,7 +97,7 @@ which can be used with any Cisco MDS 9000 series with SNMP enabled device."
show_docs(options, docs)
if (not (options["-o"] in ["list","monitor"])):
- port_oid = cisco_port2oid(options["-n"])
+ PORT_OID = cisco_port2oid(options["-n"])
# Operate the fencing device
result = fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index a34a580..d1d5f2b 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -11,19 +11,22 @@ 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)
+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" + options["-s"] + "/ls-" + options["-n"] + "/power\"/>", int(options["-Y"]))
+ 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)
- result = re_status.search(res)
+ result = RE_STATUS.search(res)
if (result == None):
fail(EC_STATUS)
else:
@@ -41,7 +44,12 @@ def set_power_status(conn, options):
}[options["-o"]]
try:
- 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"]))
+ 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)
@@ -53,15 +61,17 @@ def get_list(conn, options):
try:
try:
- res = send_command(options, "<configResolveClass cookie=\"" + options["cookie"] + "\" inHierarchical=\"false\" classId=\"lsServer\"/>", int(options["-Y"]))
+ 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)
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)
+ 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 { }
@@ -116,7 +126,7 @@ used with Cisco UCS to fence machines."
### Login
res = send_command(options, "<aaaLogin inName=\"" + options["-l"] + "\" inPassword=\"" + options["-p"] + "\" />", int(options["-y"]))
- result = re_cookie.search(res)
+ result = RE_COOKIE.search(res)
if (result == None):
## Cookie is absenting in response
fail(EC_LOGIN_DENIED)
diff --git a/fence/agents/eaton_snmp/fence_eaton_snmp.py b/fence/agents/eaton_snmp/fence_eaton_snmp.py
index 24e29fe..2c5017b 100644
--- a/fence/agents/eaton_snmp/fence_eaton_snmp.py
+++ b/fence/agents/eaton_snmp/fence_eaton_snmp.py
@@ -82,7 +82,7 @@ def eaton_set_device(conn, options):
conn.log_command("Trying %s"%(device.ident_str))
def eaton_resolv_port_id(conn, options):
- global port_id, switch_id, device
+ global port_id, switch_id
if (device==None):
eaton_set_device(conn, options)
@@ -119,7 +119,7 @@ def eaton_resolv_port_id(conn, options):
fail_usage("Can't find port with name %s!"%(options["-n"]))
def get_power_status(conn, options):
- global port_id, switch_id, device, after_set
+ global port_id, after_set
if (port_id==None):
eaton_resolv_port_id(conn, options)
@@ -143,7 +143,7 @@ def get_power_status(conn, options):
return None
def set_power_status(conn, options):
- global port_id, switch_id, device, after_set
+ global port_id, after_set
after_set = True
@@ -160,8 +160,6 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
- global device
-
outletCount = 0
result = {}
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
index 2953ddc..c7ceb19 100644
--- a/fence/agents/hpblade/fence_hpblade.py
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -60,9 +60,9 @@ def get_blades_list(conn, options):
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())
+ 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:
@@ -81,7 +81,7 @@ def main():
options = check_input(device_opt, process_input(device_opt))
- docs = { }
+ 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 \
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
index f9ee955..ceb747d 100644
--- a/fence/agents/ibmblade/fence_ibmblade.py
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -27,22 +27,22 @@ STATUS_SET_ON = 1
### FUNCTIONS ###
def get_power_status(conn, options):
- (oid,status) = conn.get("%s.%s"%(STATUSES_OID, options["-n"]))
- return (status==str(STATUS_UP) and "on" or "off")
+ (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["-n"]))
+ return (status == str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
conn.set("%s.%s"%(CONTROL_OID, options["-n"]), (options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
-def get_outlets_status(conn, options):
+def get_outlets_status(conn, _):
result = {}
res_blades = conn.walk(STATUSES_OID, 30)
- for x in res_blades:
- port_num = x[0].split('.')[-1]
+ for blade_info in res_blades:
+ port_num = blade_info[0].split('.')[-1]
port_alias = ""
- port_status = (x[1]==str(STATUS_UP) and "on" or "off")
+ port_status = (blade_info[1]==str(STATUS_UP) and "on" or "off")
result[port_num] = (port_alias, port_status)
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index fc96fb3..170134e 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -95,8 +95,6 @@ def get_outlets_status(conn, options):
# Main agent method
def main():
- global port_oid
-
device_opt = [ "fabric_fencing", "ipaddr", "login", "passwd", "passwd_script",
"test", "port", "separator", "no_login", "no_password",
"snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py
index 32d8449..3fd9822 100644
--- a/fence/agents/intelmodular/fence_intelmodular.py
+++ b/fence/agents/intelmodular/fence_intelmodular.py
@@ -61,8 +61,6 @@ def get_outlets_status(conn, options):
# Main agent method
def main():
- global port_oid
-
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"test", "port", "separator", "no_login", "no_password",
"snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
diff --git a/fence/agents/ipdu/fence_ipdu.py b/fence/agents/ipdu/fence_ipdu.py
index 354a037..da7f192 100644
--- a/fence/agents/ipdu/fence_ipdu.py
+++ b/fence/agents/ipdu/fence_ipdu.py
@@ -60,7 +60,7 @@ def ipdu_set_device(conn, options):
conn.log_command("Trying %s"%(device.ident_str))
def ipdu_resolv_port_id(conn, options):
- global port_id, switch_id, device
+ global port_id, switch_id
if (device==None):
ipdu_set_device(conn, options)
@@ -87,8 +87,6 @@ def ipdu_resolv_port_id(conn, options):
fail_usage("Can't find port with name %s!"%(options["-n"]))
def get_power_status(conn, options):
- global port_id, switch_id, device
-
if (port_id==None):
ipdu_resolv_port_id(conn, options)
@@ -98,8 +96,6 @@ def get_power_status(conn, options):
return (status==str(device.state_on) and "on" or "off")
def set_power_status(conn, options):
- global port_id, switch_id, device
-
if (port_id==None):
ipdu_resolv_port_id(conn, options)
@@ -109,11 +105,9 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
- global device
-
result = {}
- if (device==None):
+ if (device == None):
ipdu_set_device(conn, options)
res_ports = conn.walk(device.outlet_table_oid, 30)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index ea0ca09..af21696 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -1,9 +1,7 @@
#!/usr/bin/python
import sys, getopt, time, os
-import pexpect, re
-import telnetlib
-import atexit
+import pexpect, re, atexit
import __main__
## do not add code here.
@@ -403,7 +401,7 @@ all_opt = {
"order" : 205}
}
-common_opt = [ "help", "debug", "verbose", "quiet", "version", "action", "agent",
+COMMON_OPT = [ "help", "debug", "verbose", "quiet", "version", "action", "agent",
"power_timeout", "shell_timeout", "login_timeout", "power_wait", "retry_on", "delay" ]
class fspawn(pexpect.spawn):
@@ -448,15 +446,14 @@ def fail(error_code):
EC_WAITING_ON : "Failed: Timed out waiting to power ON",
EC_WAITING_OFF : "Failed: Timed out waiting to power OFF",
EC_STATUS : "Failed: Unable to obtain correct plug status or plug is not available",
- EC_STATUS_HMC : "Failed: Either unable to obtaion correct plug status, partition is not available or incorrect HMC version used",
+ EC_STATUS_HMC :
+ "Failed: Either unable to obtain correct plug status, partition is not available or incorrect HMC version used",
EC_PASSWORD_MISSING : "Failed: You have to set login password"
}[error_code] + "\n"
sys.stderr.write(message)
sys.exit(EC_GENERIC_ERROR)
def usage(avail_opt):
- global all_opt
-
print "Usage:"
print "\t" + os.path.basename(sys.argv[0]) + " [options]"
print "Options:"
@@ -469,8 +466,6 @@ def usage(avail_opt):
print " " + value["help"]
def metadata(avail_opt, options, docs):
- global all_opt
-
sorted_list = [ (key, all_opt[key]) for key in avail_opt ]
sorted_list.sort(lambda x, y: cmp(x[1]["order"], y[1]["order"]))
@@ -483,7 +478,7 @@ def metadata(avail_opt, options, docs):
if docs.has_key("vendorurl"):
print "<vendor-url>" + docs["vendorurl"] + "</vendor-url>"
print "<parameters>"
- for option, value in sorted_list:
+ for option, _value in sorted_list:
if all_opt[option].has_key("shortdesc"):
print "\t<parameter name=\"" + option + "\" unique=\"0\" required=\"" + all_opt[option]["required"] + "\">"
@@ -532,13 +527,10 @@ def metadata(avail_opt, options, docs):
print "</resource-agent>"
def process_input(avail_opt):
- global all_opt
- global common_opt
-
##
## Add options which are available for every fence agent
#####
- avail_opt.extend(common_opt)
+ avail_opt.extend(COMMON_OPT)
##
## Set standard environment
@@ -573,7 +565,7 @@ def process_input(avail_opt):
#####
if len(sys.argv) > 1:
try:
- opt, args = getopt.gnu_getopt(sys.argv[1:], getopt_string, longopt_list)
+ opt, _args = getopt.gnu_getopt(sys.argv[1:], getopt_string, longopt_list)
except getopt.GetoptError, error:
fail_usage("Parse error: " + error.msg)
@@ -644,13 +636,10 @@ def process_input(avail_opt):
## password script to set a correct password
######
def check_input(device_opt, opt):
- global all_opt
- global common_opt
-
##
## Add options which are available for every fence agent
#####
- device_opt.extend([x for x in common_opt if device_opt.count(x) == 0])
+ device_opt.extend([x for x in COMMON_OPT if device_opt.count(x) == 0])
options = dict(opt)
options["device_opt"] = device_opt
@@ -665,15 +654,15 @@ def check_input(device_opt, opt):
## In special cases (show help, metadata or version) we don't need to check anything
#####
if options.has_key("-h") or options.has_key("-V") or (options.has_key("-o") and options["-o"].lower() == "metadata"):
- return options;
+ return options
## Set default values
#####
for opt in device_opt:
if all_opt[opt].has_key("default"):
- getopt = "-" + all_opt[opt]["getopt"].rstrip(":")
- if 0 == options.has_key(getopt):
- options[getopt] = all_opt[opt]["default"]
+ getopt_short = "-" + all_opt[opt]["getopt"].rstrip(":")
+ if 0 == options.has_key(getopt_short):
+ options[getopt_short] = all_opt[opt]["default"]
options["-o"] = options["-o"].lower()
@@ -721,7 +710,8 @@ def check_input(device_opt, opt):
if 0 == os.path.isfile(options["-k"]):
fail_usage("Failed: Identity file " + options["-k"] + " does not exist")
- if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == options.has_key("-n") and 0 == options.has_key("-U")) and (device_opt.count("port")):
+ if (0 == ["list", "monitor"].count(options["-o"].lower())) and \
+ (0 == options.has_key("-n") and 0 == options.has_key("-U")) and (device_opt.count("port")):
fail_usage("Failed: You have to enter plug number")
if options.has_key("-S"):
@@ -787,7 +777,9 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
## 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")):
+ 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):
@@ -816,7 +808,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
print "Success: Already ON"
else:
power_on = False
- for i in range(1, 1 + int(options["-F"])):
+ 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):
@@ -847,7 +839,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
options["-o"] = "on"
power_on = False
- for i in range(1, 1 + int(options["-F"])):
+ 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:
@@ -855,7 +847,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
break
if power_on == False:
- # this should not fail as not was fenced succesfully
+ # this should not fail as node was fenced succesfully
sys.stderr.write('Timed out waiting to power ON\n')
print "Success: Rebooted"
@@ -864,7 +856,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
if status.upper() == "OFF":
result = 2
elif options["-o"] == "monitor":
- 1
+ pass
return result
@@ -895,8 +887,8 @@ def fence_login(options):
conn = fspawn(options, command)
except pexpect.ExceptionPexpect, ex:
## SSL telnet is part of the fencing package
- sys.stderr.write(str(ex) + "\n")
- sys.exit(EC_GENERIC_ERROR)
+ sys.stderr.write(str(ex) + "\n")
+ sys.exit(EC_GENERIC_ERROR)
elif options.has_key("-x") and 0 == options.has_key("-k"):
command = '%s %s %s@%s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-u"])
if options.has_key("ssh_options"):
@@ -938,7 +930,9 @@ def fence_login(options):
"are not in the spec file and must be installed separately." + "\n")
sys.exit(EC_GENERIC_ERROR)
- result = conn.log_expect(options, [ options["-c"], "Are you sure you want to continue connecting (yes/no)?", "Enter passphrase for key '"+options["-k"]+"':" ], int(options["-y"]))
+ result = conn.log_expect(options, [ options["-c"], \
+ "Are you sure you want to continue connecting (yes/no)?", \
+ "Enter passphrase for key '" + options["-k"] + "':" ], int(options["-y"]))
if result == 1:
conn.sendline("yes")
conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , int(options["-y"]))
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index df4f1ef..5a14d56 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -99,8 +99,8 @@ def get_lpar_list(conn, options):
fail_usage("Unable to parse output of list command")
lines = res.group(2).split("\n")
- for x in lines:
- outlets[x.rstrip()] = ("", "")
+ for outlet_line in lines:
+ outlets[outlet_line.rstrip()] = ("", "")
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -119,9 +119,9 @@ def get_lpar_list(conn, options):
fail_usage("Unable to parse output of list command")
lines = res.group(1).split("\n")
- for x in lines:
- s = x.split(":")
- outlets[s[0]] = ("", s[1])
+ for outlet_line in lines:
+ (port, status) = outlet_line.split(":")
+ outlets[port] = ("", status)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index 78eb300..e1de315 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -12,9 +12,9 @@ BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
-re_get_id = re.compile("<vm( .*)? id=\"(.*?)\"", re.IGNORECASE)
-re_status = re.compile("<state>(.*?)</state>", re.IGNORECASE)
-re_get_name = re.compile("<name>(.*?)</name>", re.IGNORECASE)
+RE_GET_ID = re.compile("<vm( .*)? id=\"(.*?)\"", re.IGNORECASE)
+RE_STATUS = re.compile("<state>(.*?)</state>", re.IGNORECASE)
+RE_GET_NAME = re.compile("<name>(.*?)</name>", re.IGNORECASE)
def get_power_status(conn, options):
### Obtain real ID from name
@@ -24,15 +24,14 @@ def get_power_status(conn, options):
sys.stderr.write(e[1] + "\n")
fail(EC_TIMED_OUT)
- result = re_get_id.search(res)
+ result = RE_GET_ID.search(res)
if (result == None):
# Unable to obtain ID needed to access virtual machine
fail(EC_STATUS)
options["id"] = result.group(2)
- re_status.search(res)
- result = re_status.search(res)
+ result = RE_STATUS.search(res)
if (result == None):
# We were able to parse ID so output is correct
# in some cases it is possible that RHEV-M output does not
@@ -73,7 +72,7 @@ def get_list(conn, options):
lines = res.split("<vm ")
for i in range(1, len(lines)):
- name = re_get_name.search(lines[i]).group(1)
+ name = RE_GET_NAME.search(lines[i]).group(1)
outlets[name] = ("", None)
except AttributeError:
return { }
diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 2ec2c3c..6e3f394 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -244,7 +244,7 @@ def vmware_is_supported_vmrun_version(options):
vmware_help_str = vmware_run_command(options, False, "", 0)
version_re = re.search("vmrun version (\d\.(\d[\.]*)*)", vmware_help_str.lower())
if (version_re==None):
- return False # Looks like this "vmrun" is not real vmrun
+ return False # Looks like this "vmrun" is not real vmrun
version_array = version_re.group(1).split(".")
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 1f353be..b1fdd05 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -58,7 +58,6 @@ def get_power_status(conn, options):
plug_line = [x.strip().lower() for x in line.split("|")]
if len(plug_line) < len(plug_header):
plug_section = -1
- pass
if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]:
return plug_line[status_index]
else:
11 years, 6 months
fence-agents: master - code cleanup: Fix warnings according to pylint
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=db1d73...
Commit: db1d7376180a0d4329a8ab5fe78690b0c77fa2c3
Parent: 80bae803aad75516cfe77cc90a7a37749d9175b7
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Oct 29 12:58:03 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Nov 5 14:45:17 2012 +0100
code cleanup: Fix warnings according to pylint
* use of possibly unitialized values
* redefining built-in functions
* unused block of code
---
fence/agents/ibmblade/fence_ibmblade.py | 2 --
fence/agents/lib/fencing_snmp.py.py | 10 +++++-----
fence/agents/vmware_soap/fence_vmware_soap.py | 1 -
fence/agents/wti/fence_wti.py | 5 +++++
fence/agents/xenapi/fence_xenapi.py | 4 ----
5 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
index 16a18df..f9ee955 100644
--- a/fence/agents/ibmblade/fence_ibmblade.py
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -50,8 +50,6 @@ def get_outlets_status(conn, options):
# Main agent method
def main():
- global port_oid
-
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"test", "port", "separator", "no_login", "no_password",
"snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index f478c53..e4c4636 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -26,8 +26,8 @@ class FencingSnmp:
if self.options["log"] >= LOG_MODE_VERBOSE:
self.options["debug_fh"].write(message+"\n")
- def quote_for_run(self, str):
- return ''.join(map(lambda x:x==r"'" and "'\\''" or x, str))
+ def quote_for_run(self, string):
+ return ''.join(map(lambda x:x==r"'" and "'\\''" or x, string))
def complete_missed_params(self):
mapping = [
@@ -112,14 +112,14 @@ class FencingSnmp:
def set(self, oid, value, additional_timemout=0):
mapping = ((int, 'i'), (str, 's'))
- type = ''
+ type_of_value = ''
for item in mapping:
if (isinstance(value, item[0])):
- type = item[1]
+ type_of_value = item[1]
break
- cmd = "%s '%s' %s '%s'"% (self.prepare_cmd("snmpset"), self.quote_for_run(oid), type, self.quote_for_run(str(value)))
+ cmd = "%s '%s' %s '%s'"% (self.prepare_cmd("snmpset"), self.quote_for_run(oid), type_of_value, self.quote_for_run(str(value)))
self.run_command(cmd, additional_timemout)
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index 41da8c0..2710603 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -139,7 +139,6 @@ def get_power_status(conn, options):
return "on"
else:
return "off"
- return status
except KeyError, ex:
fail(EC_STATUS)
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 555fb98..1f353be 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -47,7 +47,12 @@ def get_power_status(conn, options):
fail(EC_TIMED_OUT)
plug_section = 0
+ plug_index = -1
+ name_index = -1
+ status_index = -1
+ plug_header = list()
outlets = {}
+
for line in listing.splitlines():
if (plug_section == 2) and line.find("|") >= 0 and line.startswith("PLUG") == False:
plug_line = [x.strip().lower() for x in line.split("|")]
diff --git a/fence/agents/xenapi/fence_xenapi.py b/fence/agents/xenapi/fence_xenapi.py
index f583ea5..599f7a5 100644
--- a/fence/agents/xenapi/fence_xenapi.py
+++ b/fence/agents/xenapi/fence_xenapi.py
@@ -78,10 +78,6 @@ def get_power_fn(session, options):
# Set the state of the port given in the -U flag of options.
def set_power_fn(session, options):
action = options["-o"].lower()
- if options.has_key("-v"):
- verbose = True
- else:
- verbose = False
try:
# Get a reference to the vm specified in the UUID or vm_name/port parameter
11 years, 6 months
fence-agents: master - code cleanup: Fix minor warning according to pylint
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=80bae8...
Commit: 80bae803aad75516cfe77cc90a7a37749d9175b7
Parent: 4727d7e280c53ea2c3fca502c945b70418a5a7d1
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Oct 29 12:46:23 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Nov 5 14:40:57 2012 +0100
code cleanup: Fix minor warning according to pylint
* space / tab issue
* missing space after operators
* additional semicolons
* unused import of modules
* unused variables
---
fence/agents/alom/fence_alom.py | 14 +-
fence/agents/apc/fence_apc.py | 12 +-
fence/agents/apc_snmp/fence_apc_snmp.py | 158 +++++++-------
fence/agents/bladecenter/fence_bladecenter.py | 5 -
fence/agents/cisco_mds/fence_cisco_mds.py | 42 ++--
fence/agents/cisco_ucs/fence_cisco_ucs.py | 8 +-
fence/agents/drac5/fence_drac5.py | 7 +-
fence/agents/eaton_snmp/fence_eaton_snmp.py | 140 ++++++------
fence/agents/eps/fence_eps.py | 44 ++--
fence/agents/hpblade/fence_hpblade.py | 16 +-
fence/agents/ibmblade/fence_ibmblade.py | 38 ++--
fence/agents/ifmib/fence_ifmib.py | 56 +++---
fence/agents/ilo/fence_ilo.py | 2 +-
fence/agents/ilo_mp/fence_ilo_mp.py | 2 +-
fence/agents/intelmodular/fence_intelmodular.py | 32 ++--
fence/agents/ipdu/fence_ipdu.py | 94 ++++----
fence/agents/ldom/fence_ldom.py | 34 ++--
fence/agents/lib/XenAPI.py.py | 272 +++++++++++-----------
fence/agents/lib/fencing.py.py | 12 +-
fence/agents/lib/fencing_snmp.py.py | 80 ++++----
fence/agents/lpar/fence_lpar.py | 4 +-
fence/agents/rhevm/fence_rhevm.py | 10 +-
fence/agents/sanbox2/fence_sanbox2.py | 6 +-
fence/agents/virsh/fence_virsh.py | 28 ++--
fence/agents/vmware/fence_vmware.py | 160 +++++++-------
fence/agents/vmware_soap/fence_vmware_soap.py | 3 +-
fence/agents/wti/fence_wti.py | 1 -
fence/agents/xenapi/fence_xenapi.py | 35 ++--
28 files changed, 656 insertions(+), 659 deletions(-)
diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py
index 0f68050..8d5a4bd 100644
--- a/fence/agents/alom/fence_alom.py
+++ b/fence/agents/alom/fence_alom.py
@@ -5,7 +5,7 @@
# Sun(tm) Advanced Lights Out Manager CMT v1.6.1
# as found on SUN T2000 Niagara
-import sys, re, pexpect, time
+import sys, re, pexpect, time, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -19,9 +19,9 @@ 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")
+ 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:
@@ -31,9 +31,9 @@ def get_power_status(conn, options):
def set_power_status(conn, options):
try:
- cmd_line=(options["-o"]=="on" and "poweron" or "poweroff -f -y")
+ 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"]))
+ conn.log_expect(options, options["-c"], int(options["-g"]))
#Get the machine some time between poweron and poweroff
time.sleep(int(options["-g"]))
@@ -63,7 +63,7 @@ agent which can be used with ALOM connected machines."
# Operate the fencing device
conn = fence_login(options)
- result = fence_action(conn, options, set_power_status, get_power_status,None)
+ result = fence_action(conn, options, set_power_status, get_power_status, None)
# Logout from system
try:
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index 0406955..d0ed9b6 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -33,10 +33,10 @@ def get_power_status(conn, options):
version = 0
admin = 0
- switch = 0;
+ switch = 0
if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)):
- switch = 1;
+ 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")
@@ -69,7 +69,7 @@ def get_power_status(conn, options):
while True:
exp_result = conn.log_expect(options, [ options["-c"], "Press <ENTER>" ], int(options["-Y"]))
- lines = conn.before.split("\n");
+ 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)
@@ -111,7 +111,7 @@ def set_power_status(conn, options):
switch = 0
if (None != re.compile('.* MasterSwitch plus.*', re.IGNORECASE | re.S).match(conn.before)):
- switch = 1;
+ switch = 1
## MasterSwitch has different schema for on/off actions
action = {
'on' : "1",
@@ -206,8 +206,8 @@ will block any necessary fencing actions."
## Support for -n [switch]:[plug] notation that was used before
if (options.has_key("-n") == 1) and (-1 != options["-n"].find(":")):
(switch, plug) = options["-n"].split(":", 1)
- options["-s"] = switch;
- options["-n"] = plug;
+ options["-s"] = switch
+ options["-n"] = plug
##
## Operate the fencing device
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index 660eaf7..cc624a1 100644
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -8,7 +8,7 @@
# - APC Switched Rack PDU (MB:v3.7.0 PF:v2.7.0 PN:apc_hw02_aos_270.bin AF1:v2.7.3 AN1:apc_hw02_rpdu_273.bin
# MN:AP7951 HR:B2) - SNMP v1
-import sys, re, pexpect
+import sys
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -21,146 +21,146 @@ BUILD_DATE=""
### CONSTANTS ###
# oid defining fence device
-OID_SYS_OBJECT_ID='.1.3.6.1.2.1.1.2.0'
+OID_SYS_OBJECT_ID = '.1.3.6.1.2.1.1.2.0'
### GLOBAL VARIABLES ###
# Device - see ApcRPDU, ApcMSP, ApcMS
-device=None
+device = None
# Port ID
-port_id=None
+port_id = None
# Switch ID
-switch_id=None
+switch_id = None
# Classes describing Device params
class ApcRPDU:
# Rack PDU
- status_oid= '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4.%d'
- control_oid= '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.%d'
- outlet_table_oid='.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2'
- ident_str="APC rPDU"
- state_on=1
- state_off=2
- turn_on=1
- turn_off=2
- has_switches=False
+ status_oid = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.4.%d'
+ control_oid = '.1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.%d'
+ outlet_table_oid = '.1.3.6.1.4.1.318.1.1.12.3.5.1.1.2'
+ ident_str = "APC rPDU"
+ state_on = 1
+ state_off = 2
+ turn_on = 1
+ turn_off = 2
+ has_switches = False
class ApcMSP:
# Master Switch+
- status_oid= '.1.3.6.1.4.1.318.1.1.6.7.1.1.5.%d.1.%d'
- control_oid= '.1.3.6.1.4.1.318.1.1.6.5.1.1.5.%d.1.%d'
- outlet_table_oid='.1.3.6.1.4.1.318.1.1.6.7.1.1.4'
- ident_str="APC Master Switch+"
- state_on=1
- state_off=2
- turn_on=1
- turn_off=3
- has_switches=True
+ status_oid = '.1.3.6.1.4.1.318.1.1.6.7.1.1.5.%d.1.%d'
+ control_oid = '.1.3.6.1.4.1.318.1.1.6.5.1.1.5.%d.1.%d'
+ outlet_table_oid = '.1.3.6.1.4.1.318.1.1.6.7.1.1.4'
+ ident_str = "APC Master Switch+"
+ state_on = 1
+ state_off = 2
+ turn_on = 1
+ turn_off = 3
+ has_switches = True
class ApcMS:
# Master Switch - seems oldest, but supported on every APC PDU
- status_oid= '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
- control_oid= '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
- outlet_table_oid='.1.3.6.1.4.1.318.1.1.4.4.2.1.4'
- ident_str="APC Master Switch (fallback)"
- state_on=1
- state_off=2
- turn_on=1
- turn_off=2
- has_switches=False
+ status_oid = '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
+ control_oid = '.1.3.6.1.4.1.318.1.1.4.4.2.1.3.%d'
+ outlet_table_oid = '.1.3.6.1.4.1.318.1.1.4.4.2.1.4'
+ ident_str = "APC Master Switch (fallback)"
+ state_on = 1
+ state_off = 2
+ turn_on = 1
+ turn_off = 2
+ has_switches = False
### FUNCTIONS ###
-def apc_set_device(conn,options):
+def apc_set_device(conn, options):
global device
- agents_dir={'.1.3.6.1.4.1.318.1.3.4.5':ApcRPDU,
- '.1.3.6.1.4.1.318.1.3.4.4':ApcMSP,
- None:ApcMS}
+ agents_dir = {'.1.3.6.1.4.1.318.1.3.4.5':ApcRPDU,
+ '.1.3.6.1.4.1.318.1.3.4.4':ApcMSP,
+ None:ApcMS}
# First resolve type of APC
- apc_type=conn.walk(OID_SYS_OBJECT_ID)
+ apc_type = conn.walk(OID_SYS_OBJECT_ID)
if (not ((len(apc_type)==1) and (agents_dir.has_key(apc_type[0][1])))):
- apc_type=[[None,None]]
+ apc_type = [[None, None]]
- device=agents_dir[apc_type[0][1]]
+ device = agents_dir[apc_type[0][1]]
conn.log_command("Trying %s"%(device.ident_str))
-def apc_resolv_port_id(conn,options):
- global port_id,switch_id,device
+def apc_resolv_port_id(conn, options):
+ global port_id, switch_id, device
- if (device==None):
- apc_set_device(conn,options)
+ if (device == None):
+ apc_set_device(conn, options)
# Now we resolv port_id/switch_id
if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
- port_id=int(options["-n"])
+ port_id = int(options["-n"])
if (device.has_switches):
- switch_id=int(options["-s"])
+ switch_id = int(options["-s"])
else:
- table=conn.walk(device.outlet_table_oid,30)
+ table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"')==options["-n"]):
- t=x[0].split('.')
+ if (x[1].strip('"') == options["-n"]):
+ t = x[0].split('.')
if (device.has_switches):
- port_id=int(t[len(t)-1])
- switch_id=int(t[len(t)-3])
+ port_id = int(t[len(t)-1])
+ switch_id = int(t[len(t)-3])
else:
- port_id=int(t[len(t)-1])
+ port_id = int(t[len(t)-1])
- if (port_id==None):
+ if (port_id == None):
fail_usage("Can't find port with name %s!"%(options["-n"]))
-def get_power_status(conn,options):
- global port_id,switch_id,device
+def get_power_status(conn, options):
+ global port_id, switch_id, device
- if (port_id==None):
- apc_resolv_port_id(conn,options)
+ if (port_id == None):
+ apc_resolv_port_id(conn, options)
- oid=((device.has_switches) and device.status_oid%(switch_id,port_id) or device.status_oid%(port_id))
+ oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
- (oid,status)=conn.get(oid)
+ (oid, status) = conn.get(oid)
return (status==str(device.state_on) and "on" or "off")
def set_power_status(conn, options):
- global port_id,switch_id,device
+ global port_id, switch_id, device
- if (port_id==None):
- apc_resolv_port_id(conn,options)
+ if (port_id == None):
+ apc_resolv_port_id(conn, options)
- oid=((device.has_switches) and device.control_oid%(switch_id,port_id) or device.control_oid%(port_id))
+ oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
- conn.set(oid,(options["-o"]=="on" and device.turn_on or device.turn_off))
+ conn.set(oid, (options["-o"]=="on" and device.turn_on or device.turn_off))
def get_outlets_status(conn, options):
global device
- result={}
+ result = {}
- if (device==None):
- apc_set_device(conn,options)
+ if (device == None):
+ apc_set_device(conn, options)
- res_ports=conn.walk(device.outlet_table_oid,30)
+ res_ports = conn.walk(device.outlet_table_oid, 30)
for x in res_ports:
- t=x[0].split('.')
+ t = x[0].split('.')
- port_num=((device.has_switches) and "%s:%s"%(t[len(t)-3],t[len(t)-1]) or "%s"%(t[len(t)-1]))
+ port_num = ((device.has_switches) and "%s:%s"%(t[len(t)-3], t[len(t)-1]) or "%s"%(t[len(t)-1]))
- port_name=x[1].strip('"')
- port_status=""
- result[port_num]=(port_name,port_status)
+ port_name = x[1].strip('"')
+ port_status = ""
+ result[port_num] = (port_name, port_status)
- return result
+ return result
# Define new options
def apc_snmp_define_defaults():
- all_opt["snmp_version"]["default"]="1"
- all_opt["community"]["default"]="private"
+ all_opt["snmp_version"]["default"] = "1"
+ all_opt["community"]["default"] = "private"
# Main agent method
def main():
@@ -168,24 +168,24 @@ def main():
"test", "port", "separator", "no_login", "no_password",
"snmp_version", "community", "snmp_auth_prot", "snmp_sec_level",
"snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script",
- "udpport","inet4_only","inet6_only" ]
+ "udpport", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
snmp_define_defaults ()
apc_snmp_define_defaults()
- options=check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
## Support for -n [switch]:[plug] notation that was used before
if ((options.has_key("-n")) and (-1 != options["-n"].find(":"))):
(switch, plug) = options["-n"].split(":", 1)
if ((switch.isdigit()) and (plug.isdigit())):
- options["-s"] = switch
+ options["-s"] = switch
options["-n"] = plug
if (not (options.has_key("-s"))):
- options["-s"]="1"
+ options["-s"] = "1"
docs = { }
docs["shortdesc"] = "Fence agent for APC over SNMP"
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index ab06b27..49a3b5b 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -47,11 +47,6 @@ def get_power_status(conn, options):
return status.lower().strip()
def set_power_status(conn, options):
- action = {
- 'on' : "powerup",
- 'off': "powerdown"
- }[options["-o"]]
-
try:
node_cmd = "system:blade\[" + options["-n"] + "\]>"
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index e2a1e91..8f3ef9d 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -6,7 +6,7 @@
# - Cisco MDS 9124 (1 Slot) Chassis ("1/2/4 Gbps FC/Supervisor-2") Motorola, e500
# with BIOS 1.0.16, kickstart 4.1(1c), system 4.1(1c)
-import sys, re, pexpect
+import sys, re
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -19,33 +19,33 @@ BUILD_DATE=""
### CONSTANTS ###
# Cisco admin status
-PORT_ADMIN_STATUS_OID=".1.3.6.1.2.1.75.1.2.2.1.1"
+PORT_ADMIN_STATUS_OID = ".1.3.6.1.2.1.75.1.2.2.1.1"
# IF-MIB trees for alias, status and port
-ALIASES_OID=".1.3.6.1.2.1.31.1.1.1.18"
-PORTS_OID=".1.3.6.1.2.1.2.2.1.2"
+ALIASES_OID = ".1.3.6.1.2.1.31.1.1.1.18"
+PORTS_OID = ".1.3.6.1.2.1.2.2.1.2"
### GLOBAL VARIABLES ###
# OID converted from fc port name (fc(x)/(y))
-port_oid=""
+port_oid = ""
### FUNCTIONS ###
# Convert cisco port name (fc(x)/(y)) to OID
def cisco_port2oid(port):
- port=port.lower()
+ port = port.lower()
- nums=re.match('^fc(\d+)/(\d+)$',port)
+ nums = re.match('^fc(\d+)/(\d+)$', port)
if ((nums) and (len(nums.groups()))==2):
- return "%s.%d.%d"%(PORT_ADMIN_STATUS_OID,int(nums.group(1))+21,int(nums.group(2))-1)
+ return "%s.%d.%d"% (PORT_ADMIN_STATUS_OID, int(nums.group(1))+21, int(nums.group(2))-1)
else:
fail_usage("Mangled port number: %s"%(port))
-def get_power_status(conn,options):
+def get_power_status(conn, options):
global port_oid
- (oid,status)=conn.get(port_oid)
+ (oid, status) = conn.get(port_oid)
return (status=="1" and "on" or "off")
def set_power_status(conn, options):
@@ -56,24 +56,24 @@ def set_power_status(conn, options):
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
def array_to_dict(ar):
- return dict(map(lambda y:[y[0].split('.')[-1],y[1]],ar))
+ return dict(map(lambda y:[y[0].split('.')[-1], y[1]], ar))
def get_outlets_status(conn, options):
- result={}
+ result = {}
- res_fc=conn.walk(PORTS_OID,30)
- res_aliases=array_to_dict(conn.walk(ALIASES_OID,30))
+ res_fc = conn.walk(PORTS_OID, 30)
+ res_aliases = array_to_dict(conn.walk(ALIASES_OID, 30))
- fc_re=re.compile('^"fc\d+/\d+"$')
+ fc_re = re.compile('^"fc\d+/\d+"$')
for x in res_fc:
if fc_re.match(x[1]):
- port_num=x[0].split('.')[-1]
+ port_num = x[0].split('.')[-1]
- port_name=x[1].strip('"')
- port_alias=(res_aliases.has_key(port_num) and res_aliases[port_num].strip('"') or "")
- port_status=""
- result[port_name]=(port_alias,port_status)
+ port_name = x[1].strip('"')
+ port_alias = (res_aliases.has_key(port_num) and res_aliases[port_num].strip('"') or "")
+ port_status = ""
+ result[port_name] = (port_alias, port_status)
return result
@@ -101,7 +101,7 @@ which can be used with any Cisco MDS 9000 series with SNMP enabled device."
show_docs(options, docs)
if (not (options["-o"] in ["list","monitor"])):
- port_oid=cisco_port2oid(options["-n"])
+ port_oid = cisco_port2oid(options["-n"])
# Operate the fencing device
result = fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status)
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index 84cb4fd..a34a580 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, re, pexpect, socket
+import sys, re
import pycurl, StringIO
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -11,8 +11,8 @@ 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_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)
@@ -121,7 +121,7 @@ used with Cisco UCS to fence machines."
## Cookie is absenting in response
fail(EC_LOGIN_DENIED)
- options["cookie"] = result.group(1);
+ options["cookie"] = result.group(1)
##
## Modify suborg to format /suborg
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index b261e50..d8f4bb8 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -76,7 +76,6 @@ def get_list_devices(conn, options):
## when some fence devices supported by fence agent
## works with 'list' and other should returns 'N/A'
print "N/A"
- pass
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -114,12 +113,12 @@ By default, the telnet interface is not enabled."
if 0 == options.has_key("-m") and 0 == ["monitor", "list"].count(options["-o"].lower()):
fail_usage("Failed: You have to enter module name (-m)")
- options["model"]="DRAC CMC"
+ options["model"] = "DRAC CMC"
elif conn.before.find("DRAC 5") >= 0:
- options["model"]="DRAC 5"
+ options["model"] = "DRAC 5"
else:
## Assume this is DRAC 5 by default as we don't want to break anything
- options["model"]="DRAC 5"
+ options["model"] = "DRAC 5"
result = fence_action(conn, options, set_power_status, get_power_status, get_list_devices)
diff --git a/fence/agents/eaton_snmp/fence_eaton_snmp.py b/fence/agents/eaton_snmp/fence_eaton_snmp.py
index e4c3ea3..24e29fe 100644
--- a/fence/agents/eaton_snmp/fence_eaton_snmp.py
+++ b/fence/agents/eaton_snmp/fence_eaton_snmp.py
@@ -6,7 +6,7 @@
# - Eaton ePDU Switched - SNMP v1
# EATON | Powerware ePDU model: Switched ePDU (IPV3600), firmware: 2.0.K
-import sys, re, pexpect
+import sys
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -19,73 +19,73 @@ BUILD_DATE=""
### CONSTANTS ###
# oid defining fence device
-OID_SYS_OBJECT_ID='.1.3.6.1.2.1.1.2.0'
+OID_SYS_OBJECT_ID = '.1.3.6.1.2.1.1.2.0'
### GLOBAL VARIABLES ###
# Device - see EatonManagedePDU, EatonSwitchedePDU
-device=None
+device = None
# Port ID
-port_id=None
+port_id = None
# Switch ID
-switch_id=None
+switch_id = None
# Did we issue a set before get (to adjust OID with Switched ePDU)
-after_set=False
+after_set = False
# Classes describing Device params
# Managed ePDU
class EatonManagedePDU:
- status_oid= '.1.3.6.1.4.1.534.6.6.6.1.2.2.1.3.%d'
- control_oid= '.1.3.6.1.4.1.534.6.6.6.1.2.2.1.3.%d'
- outlet_table_oid='.1.3.6.1.4.1.534.6.6.6.1.2.2.1.1'
- ident_str="Eaton Managed ePDU"
- state_off=0
- state_on=1
- state_cycling=2 # FIXME: not usable with fence-agents
- turn_off=0
- turn_on=1
- turn_cycle=2 # FIXME: not usable with fence-agents
- has_switches=False
+ status_oid = '.1.3.6.1.4.1.534.6.6.6.1.2.2.1.3.%d'
+ control_oid = '.1.3.6.1.4.1.534.6.6.6.1.2.2.1.3.%d'
+ outlet_table_oid = '.1.3.6.1.4.1.534.6.6.6.1.2.2.1.1'
+ ident_str = "Eaton Managed ePDU"
+ state_off = 0
+ state_on = 1
+ state_cycling = 2 # FIXME: not usable with fence-agents
+ turn_off = 0
+ turn_on = 1
+ turn_cycle = 2 # FIXME: not usable with fence-agents
+ has_switches = False
# Switched ePDU (Pulizzi 2)
# NOTE: sysOID reports "20677.1", while data are actually at "20677.2"
class EatonSwitchedePDU:
- status_oid= '.1.3.6.1.4.1.20677.2.6.3.%d.0'
- control_oid= '.1.3.6.1.4.1.20677.2.6.2.%d.0'
- outlet_table_oid='.1.3.6.1.4.1.20677.2.6.3'
- ident_str="Eaton Switched ePDU"
- state_off=2
- state_on=1
- state_cycling=0 # Note: this status doesn't exist on this device
- turn_off=2
- turn_on=1
- turn_cycle=3 # FIXME: not usable with fence-agents
- has_switches=False
+ status_oid = '.1.3.6.1.4.1.20677.2.6.3.%d.0'
+ control_oid = '.1.3.6.1.4.1.20677.2.6.2.%d.0'
+ outlet_table_oid = '.1.3.6.1.4.1.20677.2.6.3'
+ ident_str = "Eaton Switched ePDU"
+ state_off = 2
+ state_on = 1
+ state_cycling = 0 # Note: this status doesn't exist on this device
+ turn_off = 2
+ turn_on = 1
+ turn_cycle = 3 # FIXME: not usable with fence-agents
+ has_switches = False
### FUNCTIONS ###
-def eaton_set_device(conn,options):
+def eaton_set_device(conn, options):
global device
- agents_dir={'.1.3.6.1.4.1.534.6.6.6':EatonManagedePDU,
+ agents_dir = {'.1.3.6.1.4.1.534.6.6.6':EatonManagedePDU,
'.1.3.6.1.4.1.20677.1':EatonSwitchedePDU,
'.1.3.6.1.4.1.20677.2':EatonSwitchedePDU }
# First resolve type of Eaton
- eaton_type=conn.walk(OID_SYS_OBJECT_ID)
+ eaton_type = conn.walk(OID_SYS_OBJECT_ID)
if (not ((len(eaton_type)==1) and (agents_dir.has_key(eaton_type[0][1])))):
- eaton_type=[[None,None]]
+ eaton_type = [[None, None]]
- device=agents_dir[eaton_type[0][1]]
+ device = agents_dir[eaton_type[0][1]]
conn.log_command("Trying %s"%(device.ident_str))
-def eaton_resolv_port_id(conn,options):
- global port_id,switch_id,device
+def eaton_resolv_port_id(conn, options):
+ global port_id, switch_id, device
if (device==None):
- eaton_set_device(conn,options)
+ eaton_set_device(conn, options)
# Restore the increment, that was removed in main for ePDU Managed
if (device.ident_str == "Eaton Switched ePDU"):
@@ -93,24 +93,24 @@ def eaton_resolv_port_id(conn,options):
# Now we resolv port_id/switch_id
if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
- port_id=int(options["-n"])
+ port_id = int(options["-n"])
if (device.has_switches):
- switch_id=int(options["-s"])
+ switch_id = int(options["-s"])
else:
- table=conn.walk(device.outlet_table_oid,30)
+ table = conn.walk(device.outlet_table_oid, 30)
for x in table:
if (x[1].strip('"')==options["-n"]):
- t=x[0].split('.')
+ t = x[0].split('.')
if (device.has_switches):
- port_id=int(t[len(t)-1])
- switch_id=int(t[len(t)-3])
+ port_id = int(t[len(t)-1])
+ switch_id = int(t[len(t)-3])
else:
if (device.ident_str == "Eaton Switched ePDU"):
- port_id=int(t[len(t)-3])
+ port_id = int(t[len(t)-3])
else:
- port_id=int(t[len(t)-1])
+ port_id = int(t[len(t)-1])
if (port_id==None):
# Restore index offset, to provide a valid error output on Managed ePDU
@@ -118,21 +118,21 @@ def eaton_resolv_port_id(conn,options):
options["-n"] = str(int(options["-n"]) + 1)
fail_usage("Can't find port with name %s!"%(options["-n"]))
-def get_power_status(conn,options):
- global port_id,switch_id,device,after_set
+def get_power_status(conn, options):
+ global port_id, switch_id, device, after_set
if (port_id==None):
- eaton_resolv_port_id(conn,options)
+ eaton_resolv_port_id(conn, options)
# Ajust OID for Switched ePDU when the get is after a set
if ((after_set == True) and (device.ident_str == "Eaton Switched ePDU")):
- port_id-=1
- after_set=False
+ port_id -= 1
+ after_set = False
- oid=((device.has_switches) and device.status_oid%(switch_id,port_id) or device.status_oid%(port_id))
+ oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
try:
- (oid,status)=conn.get(oid)
+ (oid, status)=conn.get(oid)
if (status==str(device.state_on)):
return "on"
elif (status==str(device.state_off)):
@@ -143,18 +143,18 @@ def get_power_status(conn,options):
return None
def set_power_status(conn, options):
- global port_id,switch_id,device,after_set
+ global port_id, switch_id, device, after_set
after_set = True
if (port_id==None):
- eaton_resolv_port_id(conn,options)
+ eaton_resolv_port_id(conn, options)
# Controls start at #2 on Switched ePDU, since #1 is the global command
if (device.ident_str == "Eaton Switched ePDU"):
- port_id=int(port_id)+1
+ port_id = int(port_id)+1
- oid=((device.has_switches) and device.control_oid%(switch_id,port_id) or device.control_oid%(port_id))
+ oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
conn.set(oid,(options["-o"]=="on" and device.turn_on or device.turn_off))
@@ -163,37 +163,37 @@ def get_outlets_status(conn, options):
global device
outletCount = 0
- result={}
+ result = {}
if (device==None):
- eaton_set_device(conn,options)
+ eaton_set_device(conn, options)
- res_ports=conn.walk(device.outlet_table_oid,30)
+ res_ports = conn.walk(device.outlet_table_oid, 30)
for x in res_ports:
- outletCount+=1
- status=x[1]
- t=x[0].split('.')
+ outletCount += 1
+ status = x[1]
+ t = x[0].split('.')
# Plug indexing start from zero, so we substract '1' from the
# user's given plug number
if (device.ident_str == "Eaton Managed ePDU"):
- port_num=str(int(((device.has_switches) and "%s:%s"%(t[len(t)-3],t[len(t)-1]) or "%s"%(t[len(t)-1]))) + 1)
+ port_num = str(int(((device.has_switches) and "%s:%s"%(t[len(t)-3], t[len(t)-1]) or "%s"%(t[len(t)-1]))) + 1)
# Plug indexing start from zero, so we add '1'
# for the user's exposed plug number
- port_name=str(int(x[1].strip('"')) + 1)
- port_status=""
- result[port_num]=(port_name,port_status)
+ port_name = str(int(x[1].strip('"')) + 1)
+ port_status = ""
+ result[port_num] = (port_name, port_status)
else:
# Switched ePDU do not propose an outletCount OID!
# Invalid status (ie value == '0'), retrieved via the walk,
# means the outlet is absent
- port_num=str(outletCount)
- port_name=str(outletCount)
- port_status=""
+ port_num = str(outletCount)
+ port_name = str(outletCount)
+ port_status = ""
if (status != '0'):
- result[port_num]=(port_name,port_status)
+ result[port_num] = (port_name, port_status)
return result
@@ -213,7 +213,7 @@ def main():
all_opt["power_wait"]["default"] = 2
all_opt["snmp_version"]["default"] = "1"
all_opt["community"]["default"] = "private"
- options=check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
# Plug indexing start from zero on ePDU Managed, so we substract '1' from
# the user's given plug number.
diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py
index 106fd1c..e1b8696 100644
--- a/fence/agents/eps/fence_eps.py
+++ b/fence/agents/eps/fence_eps.py
@@ -3,8 +3,8 @@
# The Following Agent Has Been Tested On:
# ePowerSwitch 8M+ version 1.0.0.4
-import sys, re, time
-import httplib, base64, string,socket
+import sys, re
+import httplib, base64, string, socket
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -15,8 +15,8 @@ BUILD_DATE=""
#END_VERSION_GENERATION
# Log actions and results from EPS device
-def eps_log(options,str):
- if options["log"]>=LOG_MODE_VERBOSE:
+def eps_log(options, str):
+ if options["log"] >= LOG_MODE_VERBOSE:
options["debug_fh"].write(str)
# Run command on EPS device.
@@ -27,35 +27,35 @@ def eps_run_command(options, params):
# New http connection
conn = httplib.HTTPConnection(options["-a"])
- request_str="/"+options["-c"]
+ request_str = "/"+options["-c"]
if (params!=""):
- request_str+="?"+params
+ request_str += "?"+params
- eps_log(options,"GET "+request_str+"\n")
+ eps_log(options, "GET "+request_str+"\n")
conn.putrequest('GET', request_str)
if (options.has_key("-l")):
if (not options.has_key("-p")):
- options["-p"]="" # Default is empty password
+ options["-p"] = "" # Default is empty password
# String for Authorization header
auth_str = 'Basic ' + string.strip(base64.encodestring(options["-l"]+':'+options["-p"]))
- eps_log(options,"Authorization:"+auth_str+"\n")
- conn.putheader('Authorization',auth_str)
+ eps_log(options, "Authorization:"+auth_str+"\n")
+ conn.putheader('Authorization', auth_str)
conn.endheaders()
response = conn.getresponse()
- eps_log(options,"%d %s\n"%(response.status,response.reason))
+ eps_log(options, "%d %s\n"%(response.status, response.reason))
#Response != OK -> couldn't login
if (response.status!=200):
fail(EC_LOGIN_DENIED)
- result=response.read()
- eps_log(options,result+"\n")
+ result = response.read()
+ eps_log(options, result+"\n")
conn.close()
except socket.timeout:
@@ -66,12 +66,12 @@ def eps_run_command(options, params):
return result
def get_power_status(conn, options):
- ret_val=eps_run_command(options,"")
+ ret_val = eps_run_command(options,"")
- result={}
- status=re.findall("p(\d{2})=(0|1)\s*\<br\>",ret_val.lower())
- for out_num,out_stat in status:
- result[out_num]=("",(out_stat=="1" and "on" or "off"))
+ result = {}
+ status = re.findall("p(\d{2})=(0|1)\s*\<br\>", ret_val.lower())
+ for out_num, out_stat in status:
+ result[out_num] = ("",(out_stat=="1" and "on" or "off"))
if (not (options["-o"] in ['monitor','list'])):
if (not (options["-n"] in result)):
@@ -82,11 +82,11 @@ def get_power_status(conn, options):
return result
def set_power_status(conn, options):
- ret_val=eps_run_command(options,"P%s=%s"%(options["-n"],(options["-o"]=="on" and "1" or "0")))
+ ret_val = eps_run_command(options, "P%s=%s"%(options["-n"], (options["-o"]=="on" and "1" or "0")))
# Define new option
def eps_define_new_opts():
- all_opt["hidden_page"]={
+ all_opt["hidden_page"] = {
"getopt" : "c:",
"longopt" : "page",
"help":"-c, --page=<page> Name of hidden page (default hidden.htm)",
@@ -105,7 +105,7 @@ def main():
eps_define_new_opts()
- options = check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for ePowerSwitch"
@@ -121,7 +121,7 @@ page feature must be enabled and properly configured."
show_docs(options, docs)
#Run fence action. Conn is None, beacause we always need open new http connection
- result = fence_action(None, options, set_power_status, get_power_status,get_power_status)
+ result = fence_action(None, options, set_power_status, get_power_status, get_power_status)
sys.exit(result)
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
index 4e125c1..2953ddc 100644
--- a/fence/agents/hpblade/fence_hpblade.py
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -24,11 +24,11 @@ def get_power_status(conn, options):
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)
+ res = power_re.search(line)
+ if res != None:
+ status = res.group(1)
- if status == "unknown":
+ if status == "unknown":
if options.has_key("-M"):
return "off"
else:
@@ -42,10 +42,10 @@ def get_power_status(conn, options):
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")
+ 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)
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
index ec992f4..16a18df 100644
--- a/fence/agents/ibmblade/fence_ibmblade.py
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, re, pexpect
+import sys
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -13,38 +13,38 @@ BUILD_DATE=""
### CONSTANTS ###
# From fence_ibmblade.pl
-STATUSES_OID=".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1.4" # remoteControlBladePowerState
-CONTROL_OID=".1.3.6.1.4.1.2.3.51.2.22.1.6.1.1.7" # powerOnOffBlade
+STATUSES_OID = ".1.3.6.1.4.1.2.3.51.2.22.1.5.1.1.4" # remoteControlBladePowerState
+CONTROL_OID = ".1.3.6.1.4.1.2.3.51.2.22.1.6.1.1.7" # powerOnOffBlade
# Status constants returned as value from SNMP
-STATUS_DOWN=0
-STATUS_UP=1
+STATUS_DOWN = 0
+STATUS_UP = 1
# Status constants to set as value to SNMP
-STATUS_SET_OFF=0
-STATUS_SET_ON=1
+STATUS_SET_OFF = 0
+STATUS_SET_ON = 1
### FUNCTIONS ###
-def get_power_status(conn,options):
- (oid,status)=conn.get("%s.%s"%(STATUSES_OID,options["-n"]))
+def get_power_status(conn, options):
+ (oid,status) = conn.get("%s.%s"%(STATUSES_OID, options["-n"]))
return (status==str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
- conn.set("%s.%s"%(CONTROL_OID,options["-n"]),(options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
+ conn.set("%s.%s"%(CONTROL_OID, options["-n"]), (options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
def get_outlets_status(conn, options):
- result={}
+ result = {}
- res_blades=conn.walk(STATUSES_OID,30)
+ res_blades = conn.walk(STATUSES_OID, 30)
for x in res_blades:
- port_num=x[0].split('.')[-1]
+ port_num = x[0].split('.')[-1]
- port_alias=""
- port_status=(x[1]==str(STATUS_UP) and "on" or "off")
+ port_alias = ""
+ port_status = (x[1]==str(STATUS_UP) and "on" or "off")
- result[port_num]=(port_alias,port_status)
+ result[port_num] = (port_alias, port_status)
return result
@@ -60,10 +60,10 @@ def main():
atexit.register(atexit_handler)
- snmp_define_defaults ()
- all_opt["snmp_version"]["default"]="1"
+ snmp_define_defaults()
+ all_opt["snmp_version"]["default"] = "1"
- options=check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for IBM BladeCenter over SNMP"
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index 0b0a71d..fc96fb3 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -8,7 +8,7 @@
# - Partially with APC PDU (Network Management Card AOS v2.7.0, Rack PDU APP v2.7.3)
# Only lance if is visible
-import sys, re, pexpect
+import sys
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -21,33 +21,33 @@ BUILD_DATE=""
### CONSTANTS ###
# IF-MIB trees for alias, status and port
-ALIASES_OID=".1.3.6.1.2.1.31.1.1.1.18"
-PORTS_OID=".1.3.6.1.2.1.2.2.1.2"
-STATUSES_OID=".1.3.6.1.2.1.2.2.1.7"
+ALIASES_OID = ".1.3.6.1.2.1.31.1.1.1.18"
+PORTS_OID = ".1.3.6.1.2.1.2.2.1.2"
+STATUSES_OID = ".1.3.6.1.2.1.2.2.1.7"
# Status constants returned as value from SNMP
-STATUS_UP=1
-STATUS_DOWN=2
-STATUS_TESTING=3
+STATUS_UP = 1
+STATUS_DOWN = 2
+STATUS_TESTING = 3
### GLOBAL VARIABLES ###
# Port number converted from port name or index
-port_num=None
+port_num = None
### FUNCTIONS ###
# Convert port index or name to port index
-def port2index(conn,port):
- res=None
+def port2index(conn, port):
+ res = None
if (port.isdigit()):
- res=int(port)
+ res = int(port)
else:
- ports=conn.walk(PORTS_OID,30)
+ ports = conn.walk(PORTS_OID, 30)
for x in ports:
if (x[1].strip('"')==port):
- res=int(x[0].split('.')[-1])
+ res = int(x[0].split('.')[-1])
break
if (res==None):
@@ -55,41 +55,41 @@ def port2index(conn,port):
return res
-def get_power_status(conn,options):
+def get_power_status(conn, options):
global port_num
if (port_num==None):
- port_num=port2index(conn,options["-n"])
+ port_num = port2index(conn, options["-n"])
- (oid,status)=conn.get("%s.%d"%(STATUSES_OID,port_num))
+ (oid, status) = conn.get("%s.%d"%(STATUSES_OID, port_num))
return (status==str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
global port_num
if (port_num==None):
- port_num=port2index(conn,options["-n"])
+ port_num = port2index(conn, options["-n"])
- conn.set("%s.%d"%(STATUSES_OID,port_num),(options["-o"]=="on" and STATUS_UP or STATUS_DOWN))
+ conn.set("%s.%d"%(STATUSES_OID, port_num), (options["-o"]=="on" and STATUS_UP or STATUS_DOWN))
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
def array_to_dict(ar):
- return dict(map(lambda y:[y[0].split('.')[-1],y[1]],ar))
+ return dict(map(lambda y:[y[0].split('.')[-1], y[1]], ar))
def get_outlets_status(conn, options):
- result={}
+ result = {}
- res_fc=conn.walk(PORTS_OID,30)
- res_aliases=array_to_dict(conn.walk(ALIASES_OID,30))
+ res_fc = conn.walk(PORTS_OID, 30)
+ res_aliases = array_to_dict(conn.walk(ALIASES_OID, 30))
for x in res_fc:
- port_num=x[0].split('.')[-1]
+ port_num = x[0].split('.')[-1]
- port_name=x[1].strip('"')
- port_alias=(res_aliases.has_key(port_num) and res_aliases[port_num].strip('"') or "")
- port_status=""
- result[port_name]=(port_alias,port_status)
+ port_name = x[1].strip('"')
+ port_alias = (res_aliases.has_key(port_num) and res_aliases[port_num].strip('"') or "")
+ port_status = ""
+ result[port_name] = (port_alias, port_status)
return result
@@ -106,7 +106,7 @@ def main():
atexit.register(atexit_handler)
snmp_define_defaults ()
- all_opt["snmp_version"]["default"]="2c"
+ all_opt["snmp_version"]["default"] = "2c"
options = check_input(device_opt, process_input(device_opt))
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
index fca72a7..715b163 100644
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -11,7 +11,7 @@
## iLO2 / firmware 1.50 / RIBCL 2.22
#####
-import sys, re, pexpect, socket
+import sys, re, pexpect
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py
index 9ac8701..9c18336 100644
--- a/fence/agents/ilo_mp/fence_ilo_mp.py
+++ b/fence/agents/ilo_mp/fence_ilo_mp.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, re, pexpect, socket
+import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py
index 52dd27f..32d8449 100644
--- a/fence/agents/intelmodular/fence_intelmodular.py
+++ b/fence/agents/intelmodular/fence_intelmodular.py
@@ -11,7 +11,7 @@
#
# Thanks Matthew Kent for original agent and testing.
-import sys, re, pexpect
+import sys
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
from fencing_snmp import *
@@ -25,37 +25,37 @@ BUILD_DATE=""
### CONSTANTS ###
# From INTELCORPORATION-MULTI-FLEX-SERVER-BLADES-MIB.my that ships with
# firmware updates
-STATUSES_OID=".1.3.6.1.4.1.343.2.19.1.2.10.202.1.1.6"
+STATUSES_OID = ".1.3.6.1.4.1.343.2.19.1.2.10.202.1.1.6"
# Status constants returned as value from SNMP
-STATUS_UP=2
-STATUS_DOWN=0
+STATUS_UP = 2
+STATUS_DOWN = 0
# Status constants to set as value to SNMP
-STATUS_SET_ON=2
-STATUS_SET_OFF=3
+STATUS_SET_ON = 2
+STATUS_SET_OFF = 3
### FUNCTIONS ###
-def get_power_status(conn,options):
- (oid,status)=conn.get("%s.%s"%(STATUSES_OID,options["-n"]))
+def get_power_status(conn, options):
+ (oid, status) = conn.get("%s.%s"% (STATUSES_OID, options["-n"]))
return (status==str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
- conn.set("%s.%s"%(STATUSES_OID,options["-n"]),(options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
+ conn.set("%s.%s"%(STATUSES_OID, options["-n"]), (options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
def get_outlets_status(conn, options):
- result={}
+ result = {}
- res_blades=conn.walk(STATUSES_OID,30)
+ res_blades = conn.walk(STATUSES_OID, 30)
for x in res_blades:
- port_num=x[0].split('.')[-1]
+ port_num = x[0].split('.')[-1]
- port_alias=""
- port_status=(x[1]==str(STATUS_UP) and "on" or "off")
+ port_alias = ""
+ port_status = (x[1]==str(STATUS_UP) and "on" or "off")
- result[port_num]=(port_alias,port_status)
+ result[port_num] = (port_alias, port_status)
return result
@@ -73,7 +73,7 @@ def main():
snmp_define_defaults ()
- options=check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for Intel Modular"
diff --git a/fence/agents/ipdu/fence_ipdu.py b/fence/agents/ipdu/fence_ipdu.py
index 0243afd..354a037 100644
--- a/fence/agents/ipdu/fence_ipdu.py
+++ b/fence/agents/ipdu/fence_ipdu.py
@@ -5,7 +5,7 @@
# Firmware release OPDP_sIBM_v01.2_1
#
-import sys, re, pexpect
+import sys
sys.path.append("/usr/share/fence")
from fencing import *
from fencing_snmp import *
@@ -18,92 +18,92 @@ BUILD_DATE=""
### CONSTANTS ###
# oid defining fence device
-OID_SYS_OBJECT_ID='.1.3.6.1.2.1.1.2.0'
+OID_SYS_OBJECT_ID = '.1.3.6.1.2.1.1.2.0'
### GLOBAL VARIABLES ###
# Device - see IBM iPDU
-device=None
+device = None
# Port ID
-port_id=None
+port_id = None
# Switch ID
-switch_id=None
+switch_id = None
# Classes describing Device params
class IBMiPDU:
# iPDU
- status_oid= '.1.3.6.1.4.1.2.6.223.8.2.2.1.11.%d'
- control_oid= '.1.3.6.1.4.1.2.6.223.8.2.2.1.11.%d'
- outlet_table_oid='.1.3.6.1.4.1.2.6.223.8.2.2.1.2'
- ident_str="IBM iPDU"
- state_on=1
- state_off=0
- turn_on=1
- turn_off=0
- has_switches=False
+ status_oid = '.1.3.6.1.4.1.2.6.223.8.2.2.1.11.%d'
+ control_oid = '.1.3.6.1.4.1.2.6.223.8.2.2.1.11.%d'
+ outlet_table_oid = '.1.3.6.1.4.1.2.6.223.8.2.2.1.2'
+ ident_str = "IBM iPDU"
+ state_on = 1
+ state_off = 0
+ turn_on = 1
+ turn_off = 0
+ has_switches = False
### FUNCTIONS ###
-def ipdu_set_device(conn,options):
+def ipdu_set_device(conn, options):
global device
- agents_dir={'.1.3.6.1.4.1.2.6.223':IBMiPDU,
+ agents_dir = {'.1.3.6.1.4.1.2.6.223':IBMiPDU,
None:IBMiPDU}
# First resolve type of PDU device
- pdu_type=conn.walk(OID_SYS_OBJECT_ID)
+ pdu_type = conn.walk(OID_SYS_OBJECT_ID)
if (not ((len(pdu_type)==1) and (agents_dir.has_key(pdu_type[0][1])))):
- pdu_type=[[None,None]]
+ pdu_type = [[None, None]]
- device=agents_dir[pdu_type[0][1]]
+ device = agents_dir[pdu_type[0][1]]
conn.log_command("Trying %s"%(device.ident_str))
-def ipdu_resolv_port_id(conn,options):
- global port_id,switch_id,device
+def ipdu_resolv_port_id(conn, options):
+ global port_id, switch_id, device
if (device==None):
- ipdu_set_device(conn,options)
+ ipdu_set_device(conn, options)
# Now we resolv port_id/switch_id
if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
- port_id=int(options["-n"])
+ port_id = int(options["-n"])
if (device.has_switches):
- switch_id=int(options["-s"])
+ switch_id = int(options["-s"])
else:
- table=conn.walk(device.outlet_table_oid,30)
+ table = conn.walk(device.outlet_table_oid, 30)
for x in table:
if (x[1].strip('"')==options["-n"]):
- t=x[0].split('.')
+ t = x[0].split('.')
if (device.has_switches):
- port_id=int(t[len(t)-1])
- switch_id=int(t[len(t)-3])
+ port_id = int(t[len(t)-1])
+ switch_id = int(t[len(t)-3])
else:
- port_id=int(t[len(t)-1])
+ port_id = int(t[len(t)-1])
if (port_id==None):
fail_usage("Can't find port with name %s!"%(options["-n"]))
-def get_power_status(conn,options):
- global port_id,switch_id,device
+def get_power_status(conn, options):
+ global port_id, switch_id, device
if (port_id==None):
- ipdu_resolv_port_id(conn,options)
+ ipdu_resolv_port_id(conn, options)
- oid=((device.has_switches) and device.status_oid%(switch_id,port_id) or device.status_oid%(port_id))
+ oid = ((device.has_switches) and device.status_oid%(switch_id, port_id) or device.status_oid%(port_id))
- (oid,status)=conn.get(oid)
+ (oid, status) = conn.get(oid)
return (status==str(device.state_on) and "on" or "off")
def set_power_status(conn, options):
- global port_id,switch_id,device
+ global port_id, switch_id, device
if (port_id==None):
- ipdu_resolv_port_id(conn,options)
+ ipdu_resolv_port_id(conn, options)
- oid=((device.has_switches) and device.control_oid%(switch_id,port_id) or device.control_oid%(port_id))
+ oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
conn.set(oid,(options["-o"]=="on" and device.turn_on or device.turn_off))
@@ -111,23 +111,23 @@ def set_power_status(conn, options):
def get_outlets_status(conn, options):
global device
- result={}
+ result = {}
if (device==None):
- ipdu_set_device(conn,options)
+ ipdu_set_device(conn, options)
- res_ports=conn.walk(device.outlet_table_oid,30)
+ res_ports = conn.walk(device.outlet_table_oid, 30)
for x in res_ports:
- t=x[0].split('.')
+ t = x[0].split('.')
- port_num=((device.has_switches) and "%s:%s"%(t[len(t)-3],t[len(t)-1]) or "%s"%(t[len(t)-1]))
+ port_num = ((device.has_switches) and "%s:%s"%(t[len(t)-3], t[len(t)-1]) or "%s"%(t[len(t)-1]))
- port_name=x[1].strip('"')
- port_status=""
- result[port_num]=(port_name,port_status)
+ port_name = x[1].strip('"')
+ port_status = ""
+ result[port_num] = (port_name, port_status)
- return result
+ return result
# Main agent method
def main():
@@ -145,7 +145,7 @@ def main():
all_opt["switch"]["default"] = "1"
device = IBMiPDU
- options = check_input(device_opt,process_input(device_opt))
+ options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for iPDU over SNMP"
diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py
index 498d0d7..edbb2bf 100644
--- a/fence/agents/ldom/fence_ldom.py
+++ b/fence/agents/ldom/fence_ldom.py
@@ -7,7 +7,7 @@
##
#####
-import sys, re, pexpect
+import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -17,40 +17,40 @@ REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
-COMMAND_PROMPT_REG="\[PEXPECT\]$"
-COMMAND_PROMPT_NEW="[PEXPECT]"
+COMMAND_PROMPT_REG = "\[PEXPECT\]$"
+COMMAND_PROMPT_NEW = "[PEXPECT]"
# Start comunicating after login. Prepare good environment.
def start_communication(conn, options):
conn.send_eol ("PS1='"+COMMAND_PROMPT_NEW+"'")
- res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],int(options["-Y"]))
- if res==0:
+ res = conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG], int(options["-Y"]))
+ if res == 0:
#CSH stuff
conn.send_eol("set prompt='"+COMMAND_PROMPT_NEW+"'")
- conn.log_expect(options, COMMAND_PROMPT_REG,int(options["-Y"]))
+ conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-Y"]))
def get_power_status(conn, options):
try:
- start_communication(conn,options)
+ start_communication(conn, options)
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
+ fa_status = 0
for line in conn.before.splitlines():
- domain=re.search("^(\S+)\s+(\S+)\s+.*$",line)
+ 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
+ fa_status = 1
elif (fa_status==1):
- result[domain.group(1)]=("",(domain.group(2).lower()=="bound" and "off" or "on"))
+ result[domain.group(1)] = ("", (domain.group(2).lower()=="bound" and "off" or "on"))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
@@ -67,13 +67,13 @@ def get_power_status(conn, options):
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.log_expect(options,COMMAND_PROMPT_REG,int(options["-g"]))
+ conn.log_expect(options, COMMAND_PROMPT_REG, int(options["-g"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
@@ -113,7 +113,7 @@ root. Than prompt is $, so again, you must use parameter -c."
## Operate the fencing device
####
conn = fence_login(options)
- result = fence_action(conn, options, set_power_status, get_power_status,get_power_status)
+ result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
##
## Logout from system
diff --git a/fence/agents/lib/XenAPI.py.py b/fence/agents/lib/XenAPI.py.py
index 4f27ef5..ce905fd 100644
--- a/fence/agents/lib/XenAPI.py.py
+++ b/fence/agents/lib/XenAPI.py.py
@@ -52,158 +52,158 @@ import socket
translation = gettext.translation('xen-xm', fallback = True)
class Failure(Exception):
- def __init__(self, details):
- try:
- # If this failure is MESSAGE_PARAMETER_COUNT_MISMATCH, then we
- # correct the return values here, to account for the fact that we
- # transparently add the session handle as the first argument.
- if details[0] == 'MESSAGE_PARAMETER_COUNT_MISMATCH':
- details[2] = str(int(details[2]) - 1)
- details[3] = str(int(details[3]) - 1)
-
- self.details = details
- except Exception, exn:
- self.details = ['INTERNAL_ERROR', 'Client-side: ' + str(exn)]
-
- def __str__(self):
- try:
- return translation.ugettext(self.details[0]) % self._details_map()
- except TypeError, exn:
- return "Message database broken: %s.\nXen-API failure: %s" % \
- (exn, str(self.details))
- except Exception, exn:
- import sys
- print >>sys.stderr, exn
- return "Xen-API failure: %s" % str(self.details)
-
- def _details_map(self):
- return dict([(str(i), self.details[i])
- for i in range(len(self.details))])
+ def __init__(self, details):
+ try:
+ # If this failure is MESSAGE_PARAMETER_COUNT_MISMATCH, then we
+ # correct the return values here, to account for the fact that we
+ # transparently add the session handle as the first argument.
+ if details[0] == 'MESSAGE_PARAMETER_COUNT_MISMATCH':
+ details[2] = str(int(details[2]) - 1)
+ details[3] = str(int(details[3]) - 1)
+
+ self.details = details
+ except Exception, exn:
+ self.details = ['INTERNAL_ERROR', 'Client-side: ' + str(exn)]
+
+ def __str__(self):
+ try:
+ return translation.ugettext(self.details[0]) % self._details_map()
+ except TypeError, exn:
+ return "Message database broken: %s.\nXen-API failure: %s" % \
+ (exn, str(self.details))
+ except Exception, exn:
+ import sys
+ print >> sys.stderr, exn
+ return "Xen-API failure: %s" % str(self.details)
+
+ def _details_map(self):
+ return dict([(str(i), self.details[i])
+ for i in range(len(self.details))])
_RECONNECT_AND_RETRY = (lambda _ : ())
class UDSHTTPConnection(httplib.HTTPConnection):
- """ Stupid hacked up HTTPConnection subclass to allow HTTP over Unix domain
- sockets. """
- def connect(self):
- path = self.host.replace("_", "/")
- self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
- self.sock.connect(path)
+ """ Stupid hacked up HTTPConnection subclass to allow HTTP over Unix domain
+ sockets. """
+ def connect(self):
+ path = self.host.replace("_", "/")
+ self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ self.sock.connect(path)
class UDSHTTP(httplib.HTTP):
- _connection_class = UDSHTTPConnection
+ _connection_class = UDSHTTPConnection
class UDSTransport(xmlrpclib.Transport):
- def make_connection(self, host):
- return UDSHTTP(host)
+ def make_connection(self, host):
+ return UDSHTTP(host)
class Session(xmlrpclib.ServerProxy):
- """A server proxy and session manager for communicating with Xend using
- the Xen-API.
-
- Example:
-
- session = Session('http://localhost:9363/')
- session.login_with_password('me', 'mypassword')
- session.xenapi.VM.start(vm_uuid)
- session.xenapi.session.logout()
-
- For now, this class also supports the legacy XML-RPC API, using
- session.xend.domain('Domain-0') and similar. This support will disappear
- once there is a working Xen-API replacement for every call in the legacy
- API.
- """
-
- def __init__(self, uri, transport=None, encoding=None, verbose=0,
- allow_none=1):
- xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding,
- verbose, allow_none)
- self._session = None
- self.last_login_method = None
- self.last_login_params = None
-
-
- def xenapi_request(self, methodname, params):
- if methodname.startswith('login'):
- self._login(methodname, params)
- return None
- else:
- retry_count = 0
- while retry_count < 3:
- full_params = (self._session,) + params
- result = _parse_result(getattr(self, methodname)(*full_params))
- if result == _RECONNECT_AND_RETRY:
- retry_count += 1
- if self.last_login_method:
- self._login(self.last_login_method,
- self.last_login_params)
- else:
- raise xmlrpclib.Fault(401, 'You must log in')
- else:
- return result
- raise xmlrpclib.Fault(
- 500, 'Tried 3 times to get a valid session, but failed')
-
-
- def _login(self, method, params):
- result = _parse_result(getattr(self, 'session.%s' % method)(*params))
- if result == _RECONNECT_AND_RETRY:
- raise xmlrpclib.Fault(
- 500, 'Received SESSION_INVALID when logging in')
- self._session = result
- self.last_login_method = method
- self.last_login_params = params
-
-
- def __getattr__(self, name):
- if name == 'xenapi':
- return _Dispatcher(self.xenapi_request, None)
- elif name.startswith('login'):
- return lambda *params: self._login(name, params)
- else:
- return xmlrpclib.ServerProxy.__getattr__(self, name)
+ """A server proxy and session manager for communicating with Xend using
+ the Xen-API.
+
+ Example:
+
+ session = Session('http://localhost:9363/')
+ session.login_with_password('me', 'mypassword')
+ session.xenapi.VM.start(vm_uuid)
+ session.xenapi.session.logout()
+
+ For now, this class also supports the legacy XML-RPC API, using
+ session.xend.domain('Domain-0') and similar. This support will disappear
+ once there is a working Xen-API replacement for every call in the legacy
+ API.
+ """
+
+ def __init__(self, uri, transport=None, encoding=None, verbose=0,
+ allow_none=1):
+ xmlrpclib.ServerProxy.__init__(self, uri, transport, encoding,
+ verbose, allow_none)
+ self._session = None
+ self.last_login_method = None
+ self.last_login_params = None
+
+
+ def xenapi_request(self, methodname, params):
+ if methodname.startswith('login'):
+ self._login(methodname, params)
+ return None
+ else:
+ retry_count = 0
+ while retry_count < 3:
+ full_params = (self._session,) + params
+ result = _parse_result(getattr(self, methodname)(*full_params))
+ if result == _RECONNECT_AND_RETRY:
+ retry_count += 1
+ if self.last_login_method:
+ self._login(self.last_login_method,
+ self.last_login_params)
+ else:
+ raise xmlrpclib.Fault(401, 'You must log in')
+ else:
+ return result
+ raise xmlrpclib.Fault(
+ 500, 'Tried 3 times to get a valid session, but failed')
+
+
+ def _login(self, method, params):
+ result = _parse_result(getattr(self, 'session.%s' % method)(*params))
+ if result == _RECONNECT_AND_RETRY:
+ raise xmlrpclib.Fault(
+ 500, 'Received SESSION_INVALID when logging in')
+ self._session = result
+ self.last_login_method = method
+ self.last_login_params = params
+
+
+ def __getattr__(self, name):
+ if name == 'xenapi':
+ return _Dispatcher(self.xenapi_request, None)
+ elif name.startswith('login'):
+ return lambda *params: self._login(name, params)
+ else:
+ return xmlrpclib.ServerProxy.__getattr__(self, name)
def xapi_local():
- return Session("http://_var_xapi_xapi/", transport=UDSTransport())
+ return Session("http://_var_xapi_xapi/", transport=UDSTransport())
def _parse_result(result):
- if type(result) != dict or 'Status' not in result:
- raise xmlrpclib.Fault(500, 'Missing Status in response from server' + result)
- if result['Status'] == 'Success':
- if 'Value' in result:
- return result['Value']
- else:
- raise xmlrpclib.Fault(500,
- 'Missing Value in response from server')
- else:
- if 'ErrorDescription' in result:
- if result['ErrorDescription'][0] == 'SESSION_INVALID':
- return _RECONNECT_AND_RETRY
- else:
- raise Failure(result['ErrorDescription'])
- else:
- raise xmlrpclib.Fault(
- 500, 'Missing ErrorDescription in response from server')
+ if type(result) != dict or 'Status' not in result:
+ raise xmlrpclib.Fault(500, 'Missing Status in response from server' + result)
+ if result['Status'] == 'Success':
+ if 'Value' in result:
+ return result['Value']
+ else:
+ raise xmlrpclib.Fault(500,
+ 'Missing Value in response from server')
+ else:
+ if 'ErrorDescription' in result:
+ if result['ErrorDescription'][0] == 'SESSION_INVALID':
+ return _RECONNECT_AND_RETRY
+ else:
+ raise Failure(result['ErrorDescription'])
+ else:
+ raise xmlrpclib.Fault(
+ 500, 'Missing ErrorDescription in response from server')
# Based upon _Method from xmlrpclib.
class _Dispatcher:
- def __init__(self, send, name):
- self.__send = send
- self.__name = name
-
- def __repr__(self):
- if self.__name:
- return '<XenAPI._Dispatcher for %s>' % self.__name
- else:
- return '<XenAPI._Dispatcher>'
-
- def __getattr__(self, name):
- if self.__name is None:
- return _Dispatcher(self.__send, name)
- else:
- return _Dispatcher(self.__send, "%s.%s" % (self.__name, name))
-
- def __call__(self, *args):
- return self.__send(self.__name, args)
+ def __init__(self, send, name):
+ self.__send = send
+ self.__name = name
+
+ def __repr__(self):
+ if self.__name:
+ return '<XenAPI._Dispatcher for %s>' % self.__name
+ else:
+ return '<XenAPI._Dispatcher>'
+
+ def __getattr__(self, name):
+ if self.__name is None:
+ return _Dispatcher(self.__send, name)
+ else:
+ return _Dispatcher(self.__send, "%s.%s" % (self.__name, name))
+
+ def __call__(self, *args):
+ return self.__send(self.__name, args)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index c1851d1..ea0ca09 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -477,7 +477,7 @@ def metadata(avail_opt, options, docs):
print "<?xml version=\"1.0\" ?>"
print "<resource-agent name=\"" + os.path.basename(sys.argv[0]) + "\" shortdesc=\"" + docs["shortdesc"] + "\" >"
if "symlink" in docs:
- for (symlink,desc) in docs["symlink"]:
+ for (symlink, desc) in docs["symlink"]:
print "<symlink name=\"" + symlink + "\" shortdesc=\"" + desc + "\"/>"
print "<longdesc>" + docs["longdesc"] + "</longdesc>"
if docs.has_key("vendorurl"):
@@ -816,7 +816,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
print "Success: Already ON"
else:
power_on = False
- for i in range(1,1 + int(options["-F"])):
+ for i 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):
@@ -847,7 +847,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
options["-o"] = "on"
power_on = False
- for i in range(1,1 + int(options["-F"])):
+ for i 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:
@@ -869,13 +869,13 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list = None
return result
def fence_login(options):
- force_ipvx=""
+ force_ipvx = ""
if (options.has_key("-6")):
- force_ipvx="-6 "
+ force_ipvx = "-6 "
if (options.has_key("-4")):
- force_ipvx="-4 "
+ force_ipvx = "-4 "
if (options.has_key("eol") == False):
options["eol"] = "\r\n"
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index 4f55795..f478c53 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -2,7 +2,7 @@
# For example of use please see fence_cisco_mds
-import re,pexpect
+import re, pexpect
from fencing import *
## do not add code here.
@@ -14,81 +14,81 @@ BUILD_DATE = ""
# Fix for RHBZ#527844
def snmp_define_defaults ():
- all_opt["udpport"]["default"]="161"
- all_opt["ipport"]["default"]="161"
+ all_opt["udpport"]["default"] = "161"
+ all_opt["ipport"]["default"] = "161"
class FencingSnmp:
- def __init__(self,options):
- self.options=options
+ def __init__(self, options):
+ self.options = options
# Log message if user set verbose option
def log_command(self, message):
if self.options["log"] >= LOG_MODE_VERBOSE:
self.options["debug_fh"].write(message+"\n")
- def quote_for_run(self,str):
- return ''.join(map(lambda x:x==r"'" and "'\\''" or x,str))
+ def quote_for_run(self, str):
+ return ''.join(map(lambda x:x==r"'" and "'\\''" or x, str))
def complete_missed_params(self):
- mapping=[
+ mapping = [
[['P','p','!E'],'self.options["-E"]="authPriv"'],
[['!d','c','!l','!P','!p'],'self.options["-d"]="2c"']
]
for val in mapping:
- e=val[0]
+ e = val[0]
- res=True
+ res = True
for item in e:
if ((item[0]=='!') and (self.options.has_key("-"+item[1]))):
- res=False
+ res = False
break
if ((item[0]!='!') and (not self.options.has_key("-"+item[0]))):
- res=False
+ res = False
break
if res:
exec(val[1])
- def prepare_cmd(self,command):
- cmd="@SNMPBIN@/%s -m '' -Oeqn "%(command)
+ def prepare_cmd(self, command):
+ cmd = "@SNMPBIN@/%s -m '' -Oeqn "% (command)
self.complete_missed_params()
#mapping from our option to snmpcmd option
- mapping=(('d','v'),('c','c'))
+ mapping = (('d', 'v'),('c', 'c'))
for item in mapping:
if (self.options.has_key("-"+item[0])):
- cmd+=" -%s '%s'"%(item[1],self.quote_for_run(self.options["-"+item[0]]))
+ cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["-" + item[0]]))
# Some options make sense only for v3 (and for v1/2c can cause "problems")
if (self.options.has_key("-d")) and (self.options["-d"] == "3"):
# Mapping from our options to snmpcmd options for v3
- mapping_v3=(('b','a'),('E','l'),('B','x'),('P','X'),('p','A'),('l','u'))
+ mapping_v3 = (('b','a'),('E','l'),('B','x'),('P','X'),('p','A'),('l','u'))
for item in mapping_v3:
if (self.options.has_key("-"+item[0])):
- cmd+=" -%s '%s'"%(item[1],self.quote_for_run(self.options["-"+item[0]]))
+ cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["-" + item[0]]))
- force_ipvx=""
+ force_ipvx = ""
if (self.options.has_key("-6")):
- force_ipvx="udp6:"
+ force_ipvx = "udp6:"
if (self.options.has_key("-4")):
- force_ipvx="udp:"
+ force_ipvx = "udp:"
- cmd+=" '%s%s%s'"%(force_ipvx, self.quote_for_run(self.options["-a"]),
+ cmd += " '%s%s%s'"% (force_ipvx, self.quote_for_run(self.options["-a"]),
self.options.has_key("-u") and self.quote_for_run(":" + str (self.options["-u"])) or "")
return cmd
- def run_command(self,command,additional_timemout=0):
+ def run_command(self, command, additional_timemout=0):
try:
self.log_command(command)
- (res_output,res_code)=pexpect.run(command,int(self.options["-Y"])+int(self.options["-y"])+additional_timemout,True)
+ (res_output, res_code) = pexpect.run(command, int(self.options["-Y"]) + int(self.options["-y"]) + additional_timemout, True)
if (res_code==None):
fail(EC_TIMED_OUT)
@@ -96,36 +96,36 @@ class FencingSnmp:
self.log_command(res_output)
if (res_code!=0) or (re.search("^Error ", res_output, re.MULTILINE) != None):
- fail_usage("Returned %d: %s"%(res_code,res_output))
+ fail_usage("Returned %d: %s"% (res_code, res_output))
except pexpect.ExceptionPexpect:
fail_usage("Cannot run command %s"%(command))
return res_output
- def get(self,oid,additional_timemout=0):
- cmd="%s '%s'"%(self.prepare_cmd("snmpget"),self.quote_for_run(oid))
+ def get(self, oid, additional_timemout=0):
+ cmd = "%s '%s'"% (self.prepare_cmd("snmpget"), self.quote_for_run(oid))
- output=self.run_command(cmd,additional_timemout).splitlines()
+ output = self.run_command(cmd, additional_timemout).splitlines()
- return output[len(output)-1].split(None,1)
+ return output[len(output)-1].split(None, 1)
- def set(self,oid,value,additional_timemout=0):
- mapping=((int,'i'),(str,'s'))
+ def set(self, oid, value, additional_timemout=0):
+ mapping = ((int, 'i'), (str, 's'))
- type=''
+ type = ''
for item in mapping:
- if (isinstance(value,item[0])):
- type=item[1]
+ if (isinstance(value, item[0])):
+ type = item[1]
break
- cmd="%s '%s' %s '%s'"%(self.prepare_cmd("snmpset"),self.quote_for_run(oid),type,self.quote_for_run(str(value)))
+ cmd = "%s '%s' %s '%s'"% (self.prepare_cmd("snmpset"), self.quote_for_run(oid), type, self.quote_for_run(str(value)))
- self.run_command(cmd,additional_timemout)
+ self.run_command(cmd, additional_timemout)
- def walk(self,oid,additional_timemout=0):
- cmd="%s '%s'"%(self.prepare_cmd("snmpwalk"),self.quote_for_run(oid))
+ def walk(self, oid, additional_timemout=0):
+ cmd = "%s '%s'"% (self.prepare_cmd("snmpwalk"), self.quote_for_run(oid))
- output=self.run_command(cmd,additional_timemout).splitlines()
+ output = self.run_command(cmd, additional_timemout).splitlines()
- return map(lambda x:x.split(None,1),filter(lambda y:len(y)>0 and y[0]=='.',output))
+ return map(lambda x:x.split(None, 1), filter(lambda y:len(y)>0 and y[0]=='.', output))
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index a5d4195..df4f1ef 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -150,8 +150,8 @@ def main():
if 0 == options.has_key("-s"):
fail_usage("Failed: You have to enter name of managed system")
- if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == options.has_key("-n")):
- fail_usage("Failed: You have to enter name of the partition")
+ if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == options.has_key("-n")):
+ fail_usage("Failed: You have to enter name of the partition")
if 1 == options.has_key("-H") and (options["-H"] != "3" and options["-H"] != "4"):
fail_usage("Failed: You have to enter valid version number: 3 or 4")
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index 9bb9581..78eb300 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-import sys, re, pexpect, socket
+import sys, re
import pycurl, StringIO
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -12,9 +12,9 @@ BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
-re_get_id = re.compile("<vm( .*)? id=\"(.*?)\"", re.IGNORECASE);
-re_status = re.compile("<state>(.*?)</state>", re.IGNORECASE);
-re_get_name = re.compile("<name>(.*?)</name>", re.IGNORECASE);
+re_get_id = re.compile("<vm( .*)? id=\"(.*?)\"", re.IGNORECASE)
+re_status = re.compile("<state>(.*?)</state>", re.IGNORECASE)
+re_get_name = re.compile("<name>(.*?)</name>", re.IGNORECASE)
def get_power_status(conn, options):
### Obtain real ID from name
@@ -29,7 +29,7 @@ def get_power_status(conn, options):
# Unable to obtain ID needed to access virtual machine
fail(EC_STATUS)
- options["id"] = result.group(2);
+ options["id"] = result.group(2)
re_status.search(res)
result = re_status.search(res)
diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py
index 51781f9..1ed71cf 100644
--- a/fence/agents/sanbox2/fence_sanbox2.py
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -8,7 +8,7 @@
## +-----------------+---------------------------+
#####
-import sys, re, pexpect
+import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
@@ -50,8 +50,8 @@ def set_power_status(conn, options):
'off' : "offline"
}[options["-o"]]
- try:
- conn.send_eol("set port " + options["-n"] + " state " + action)
+ 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)
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index ebf6666..cb33a56 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -30,28 +30,28 @@ def get_outlets_status(conn, options):
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
- result={}
+ result = {}
#This is status of mini finite automata. 0 = we didn't found Id and Name, 1 = we did
- fa_status=0
+ fa_status = 0
- for line in conn.before.splitlines():
- domain=re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$",line)
+ for line in conn.before.splitlines():
+ domain = re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$", line)
- if (domain!=None):
+ if (domain!=None):
if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")):
- fa_status=1
+ fa_status = 1
elif (fa_status==1):
- result[domain.group(2)]=("",(domain.group(3).lower() in ["running","blocked","idle","no state","paused"] and "on" or "off"))
+ result[domain.group(2)] = ("", (domain.group(3).lower() in ["running", "blocked", "idle", "no state", "paused"] and "on" or "off"))
return result
def get_power_status(conn, options):
- outlets=get_outlets_status(conn,options)
+ outlets = get_outlets_status(conn, options)
- if (not (options["-n"] in outlets)):
- fail_usage("Failed: You have to enter existing name of virtual machine!")
- else:
- return outlets[options["-n"]][1]
+ if (not (options["-n"] in outlets)):
+ fail_usage("Failed: You have to enter existing name of virtual machine!")
+ else:
+ return outlets[options["-n"]][1]
def set_power_status(conn, options):
if options.has_key("-d"):
@@ -63,7 +63,7 @@ def set_power_status(conn, options):
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)
+ time.sleep(1)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
@@ -82,7 +82,7 @@ def main():
options = check_input(device_opt, process_input(device_opt))
- options["ssh_options"]="-t '/bin/bash -c \"PS1=\[EXPECT\]#\ /bin/bash --noprofile --norc\"'"
+ options["ssh_options"] = "-t '/bin/bash -c \"PS1=\[EXPECT\]#\ /bin/bash --noprofile --norc\"'"
docs = { }
docs["shortdesc"] = "Fence agent for virsh"
diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py
index 885a876..2ec2c3c 100644
--- a/fence/agents/vmware/fence_vmware.py
+++ b/fence/agents/vmware/fence_vmware.py
@@ -34,59 +34,59 @@ BUILD_DATE=""
### CONSTANTS ####
# VMware type is ESX/ESXi/VC
-VMWARE_TYPE_ESX=0
+VMWARE_TYPE_ESX = 0
# VMware type is Server 1.x
-VMWARE_TYPE_SERVER1=1
+VMWARE_TYPE_SERVER1 = 1
# VMware type is Server 2.x and/or ESX 3.5 up2, ESXi 3.5 up2, VC 2.5 up2
-VMWARE_TYPE_SERVER2=2
+VMWARE_TYPE_SERVER2 = 2
# Minimum required version of vmrun command
-VMRUN_MINIMUM_REQUIRED_VERSION=2
+VMRUN_MINIMUM_REQUIRED_VERSION = 2
# Default path to vmhelper command
-VMHELPER_COMMAND="fence_vmware_helper"
+VMHELPER_COMMAND = "fence_vmware_helper"
# Default path to vmrun command
-VMRUN_COMMAND="/usr/bin/vmrun"
+VMRUN_COMMAND = "/usr/bin/vmrun"
# Default type of vmware
-VMWARE_DEFAULT_TYPE="esx"
+VMWARE_DEFAULT_TYPE = "esx"
#### GLOBAL VARIABLES ####
# Internal type. One of VMWARE_TYPE_, set by #vmware_check_vmware_type
-vmware_internal_type=VMWARE_TYPE_ESX
+vmware_internal_type = VMWARE_TYPE_ESX
# If ESX is disconnected, say, that VM is off (don't return previous state)
-vmware_disconnected_hack=False
+vmware_disconnected_hack = False
### FUNCTIONS ####
#Split string in simplified DSV format to array of items
def dsv_split(dsv_str):
- delimiter_c=':'
- escape_c='\\'
+ delimiter_c = ':'
+ escape_c = '\\'
- res=[]
- status=0
- tmp_str=""
+ res = []
+ status = 0
+ tmp_str = ""
for x in dsv_str:
if (status==0):
if (x==delimiter_c):
res.append(tmp_str)
- tmp_str=""
+ tmp_str = ""
elif (x==escape_c):
- status=1
+ status = 1
else:
- tmp_str+=x
+ tmp_str += x
elif (status==1):
if (x==delimiter_c):
- tmp_str+=delimiter_c
+ tmp_str += delimiter_c
elif (x==escape_c):
- tmp_str+=escape_c
+ tmp_str += escape_c
else:
- tmp_str+=escape_c+x
- status=0
+ tmp_str += escape_c+x
+ status = 0
- if (tmp_str!=""):
+ if (tmp_str != ""):
res.append(tmp_str)
return res
@@ -94,43 +94,43 @@ def dsv_split(dsv_str):
# Quote string for proper existence in quoted string used for pexpect.run function
# Ex. test'this will return test'\''this. So pexpect run will really pass ' to argument
def quote_for_run(str):
- dstr=''
+ dstr = ''
for c in str:
- if c==r"'":
- dstr+="'\\''"
+ if c == r"'":
+ dstr += "'\\''"
else:
- dstr+=c
+ dstr += c
return dstr
# Return string with command and additional parameters (something like vmrun -h 'host'
-def vmware_prepare_command(options,add_login_params,additional_params):
- res=options["-e"]
+def vmware_prepare_command(options, add_login_params, additional_params):
+ res = options["-e"]
if (add_login_params):
if (vmware_internal_type==VMWARE_TYPE_ESX):
- res+=" --server '%s' --username '%s' --password '%s' "%(quote_for_run(options["-a"]),
+ res += " --server '%s' --username '%s' --password '%s' "% (quote_for_run(options["-a"]),
quote_for_run(options["-l"]),
quote_for_run(options["-p"]))
elif (vmware_internal_type==VMWARE_TYPE_SERVER2):
- res+=" -h 'https://%s/sdk' -u '%s' -p '%s' -T server "%(quote_for_run(options["-a"]),
+ res += " -h 'https://%s/sdk' -u '%s' -p '%s' -T server "% (quote_for_run(options["-a"]),
quote_for_run(options["-l"]),
quote_for_run(options["-p"]))
elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
- host_name_array=options["-a"].split(':')
+ host_name_array = options["-a"].split(':')
- res+=" -h '%s' -u '%s' -p '%s' -T server1 "%(quote_for_run(host_name_array[0]),
+ res += " -h '%s' -u '%s' -p '%s' -T server1 "% (quote_for_run(host_name_array[0]),
quote_for_run(options["-l"]),
quote_for_run(options["-p"]))
if (len(host_name_array)>1):
- res+="-P '%s' "%(quote_for_run(host_name_array[1]))
+ res += "-P '%s' "% (quote_for_run(host_name_array[1]))
if ((options.has_key("-s")) and (vmware_internal_type==VMWARE_TYPE_ESX)):
- res+="--datacenter '%s' "%(quote_for_run(options["-s"]))
+ res += "--datacenter '%s' "% (quote_for_run(options["-s"]))
- if (additional_params!=""):
- res+=additional_params
+ if (additional_params != ""):
+ res += additional_params
return res
@@ -142,84 +142,84 @@ def vmware_log(options, message):
# Run command with timeout and parameters. Internaly uses vmware_prepare_command. Returns string
# with output from vmrun command. If something fails (command not found, exit code is not 0), fail_usage
# function is called (and never return).
-def vmware_run_command(options,add_login_params,additional_params,additional_timeout):
- command=vmware_prepare_command(options,add_login_params,additional_params)
+def vmware_run_command(options, add_login_params, additional_params, additional_timeout):
+ command = vmware_prepare_command(options, add_login_params, additional_params)
try:
- vmware_log(options,command)
+ vmware_log(options, command)
- (res_output,res_code)=pexpect.run(command,int(options["-Y"])+int(options["-y"])+additional_timeout,True)
+ (res_output, res_code) = pexpect.run(command, int(options["-Y"])+int(options["-y"])+additional_timeout, True)
if (res_code==None):
fail(EC_TIMED_OUT)
if ((res_code!=0) and (add_login_params)):
- vmware_log(options,res_output)
- fail_usage("%s returned %s"%(options["-e"],res_output))
+ vmware_log(options, res_output)
+ fail_usage("%s returned %s"% (options["-e"], res_output))
else:
- vmware_log(options,res_output)
+ vmware_log(options, res_output)
except pexpect.ExceptionPexpect:
- fail_usage("Cannot run command %s"%(options["-e"]))
+ fail_usage("Cannot run command %s"% (options["-e"]))
return res_output
# Get outlet list with status as hash table. If you will use add_vm_name, only VM with vmname is
# returned. This is used in get_status function
def vmware_get_outlets_vi(conn, options, add_vm_name):
- outlets={}
+ outlets = {}
if (add_vm_name):
- all_machines=vmware_run_command(options,True,("--operation status --vmname '%s'"%(quote_for_run(options["-n"]))),0)
+ all_machines = vmware_run_command(options, True, ("--operation status --vmname '%s'"% (quote_for_run(options["-n"]))), 0)
else:
- all_machines=vmware_run_command(options,True,"--operation list",int(options["-g"]))
+ all_machines = vmware_run_command(options, True, "--operation list", int(options["-g"]))
- all_machines_array=all_machines.splitlines()
+ all_machines_array = all_machines.splitlines()
for machine in all_machines_array:
- machine_array=dsv_split(machine)
- if (len(machine_array)==4):
+ machine_array = dsv_split(machine)
+ if (len(machine_array) == 4):
if (machine_array[0] in outlets):
fail_usage("Failed. More machines with same name %s found!"%(machine_array[0]))
if (vmware_disconnected_hack):
- outlets[machine_array[0]]=("",(
+ outlets[machine_array[0]] = ("", (
((machine_array[2].lower() in ["poweredon"]) and
(machine_array[3].lower()=="connected"))
and "on" or "off"))
else:
- outlets[machine_array[0]]=("",((machine_array[2].lower() in ["poweredon"]) and "on" or "off"))
+ outlets[machine_array[0]] = ("", ((machine_array[2].lower() in ["poweredon"]) and "on" or "off"))
return outlets
# Get outlet list with status as hash table.
-def vmware_get_outlets_vix(conn,options):
- outlets={}
+def vmware_get_outlets_vix(conn, options):
+ outlets = {}
- running_machines=vmware_run_command(options,True,"list",0)
- running_machines_array=running_machines.splitlines()[1:]
+ running_machines = vmware_run_command(options, True, "list", 0)
+ running_machines_array = running_machines.splitlines()[1:]
if (vmware_internal_type==VMWARE_TYPE_SERVER2):
- all_machines=vmware_run_command(options,True,"listRegisteredVM",0)
- all_machines_array=all_machines.splitlines()[1:]
+ all_machines = vmware_run_command(options, True, "listRegisteredVM", 0)
+ all_machines_array = all_machines.splitlines()[1:]
elif (vmware_internal_type==VMWARE_TYPE_SERVER1):
- all_machines_array=running_machines_array
+ all_machines_array = running_machines_array
for machine in all_machines_array:
if (machine!=""):
- outlets[machine]=("",((machine in running_machines_array) and "on" or "off"))
+ outlets[machine] = ("", ((machine in running_machines_array) and "on" or "off"))
return outlets
def get_outlets_status(conn, options):
if (vmware_internal_type==VMWARE_TYPE_ESX):
- return vmware_get_outlets_vi(conn,options,False)
+ return vmware_get_outlets_vi(conn, options, False)
if ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
- return vmware_get_outlets_vix(conn,options)
+ return vmware_get_outlets_vix(conn, options)
-def get_power_status(conn,options):
+def get_power_status(conn, options):
if (vmware_internal_type==VMWARE_TYPE_ESX):
- outlets=vmware_get_outlets_vi(conn,options,True)
+ outlets = vmware_get_outlets_vi(conn, options, True)
else:
- outlets=get_outlets_status(conn,options)
+ outlets = get_outlets_status(conn, options)
if ((vmware_internal_type==VMWARE_TYPE_SERVER2) or (vmware_internal_type==VMWARE_TYPE_ESX)):
if (not (options["-n"] in outlets)):
@@ -231,25 +231,25 @@ def get_power_status(conn,options):
def set_power_status(conn, options):
if (vmware_internal_type==VMWARE_TYPE_ESX):
- additional_params="--operation %s --vmname '%s'"%((options["-o"]=="on" and "on" or "off"),quote_for_run(options["-n"]))
+ additional_params = "--operation %s --vmname '%s'"% ((options["-o"]=="on" and "on" or "off"), quote_for_run(options["-n"]))
elif ((vmware_internal_type==VMWARE_TYPE_SERVER1) or (vmware_internal_type==VMWARE_TYPE_SERVER2)):
- additional_params="%s '%s'"%((options["-o"]=="on" and "start" or "stop"),quote_for_run(options["-n"]))
+ additional_params = "%s '%s'"% ((options["-o"]=="on" and "start" or "stop"), quote_for_run(options["-n"]))
if (options["-o"]=="off"):
- additional_params+=" hard"
+ additional_params += " hard"
- vmware_run_command(options,True,additional_params,int(options["-g"]))
+ vmware_run_command(options, True, additional_params, int(options["-g"]))
# Returns True, if user uses supported vmrun version (currently >=2.0.0) otherwise False.
def vmware_is_supported_vmrun_version(options):
- vmware_help_str=vmware_run_command(options,False,"",0)
- version_re=re.search("vmrun version (\d\.(\d[\.]*)*)",vmware_help_str.lower())
+ vmware_help_str = vmware_run_command(options, False, "", 0)
+ version_re = re.search("vmrun version (\d\.(\d[\.]*)*)", vmware_help_str.lower())
if (version_re==None):
return False # Looks like this "vmrun" is not real vmrun
- version_array=version_re.group(1).split(".")
+ version_array = version_re.group(1).split(".")
try:
- if (int(version_array[0])<VMRUN_MINIMUM_REQUIRED_VERSION):
+ if (int(version_array[0]) < VMRUN_MINIMUM_REQUIRED_VERSION):
return False
except Exception:
return False
@@ -261,20 +261,20 @@ def vmware_is_supported_vmrun_version(options):
def vmware_check_vmware_type(options):
global vmware_internal_type
- options["-d"]=options["-d"].lower()
+ options["-d"] = options["-d"].lower()
if (options["-d"]=="esx"):
- vmware_internal_type=VMWARE_TYPE_ESX
+ vmware_internal_type = VMWARE_TYPE_ESX
if (not options.has_key("-e")):
- options["-e"]=VMHELPER_COMMAND
+ options["-e"] = VMHELPER_COMMAND
elif (options["-d"]=="server2"):
- vmware_internal_type=VMWARE_TYPE_SERVER2
+ vmware_internal_type = VMWARE_TYPE_SERVER2
if (not options.has_key("-e")):
- options["-e"]=VMRUN_COMMAND
+ options["-e"] = VMRUN_COMMAND
elif (options["-d"]=="server1"):
- vmware_internal_type=VMWARE_TYPE_SERVER1
+ vmware_internal_type = VMWARE_TYPE_SERVER1
if (not options.has_key("-e")):
- options["-e"]=VMRUN_COMMAND
+ options["-e"] = VMRUN_COMMAND
else:
fail_usage("vmware_type can be esx,server2 or server1!")
diff --git a/fence/agents/vmware_soap/fence_vmware_soap.py b/fence/agents/vmware_soap/fence_vmware_soap.py
index 21dad66..41da8c0 100644
--- a/fence/agents/vmware_soap/fence_vmware_soap.py
+++ b/fence/agents/vmware_soap/fence_vmware_soap.py
@@ -1,10 +1,9 @@
#!/usr/bin/python
-import sys, re, pexpect, exceptions
+import sys, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from suds.client import Client
-from suds import WebFault
from suds.sudsobject import Property
from fencing import *
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 9aa9959..555fb98 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -62,7 +62,6 @@ def get_power_status(conn, options):
outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
elif (plug_section == 1):
plug_section = 2
- pass
elif (line.upper().startswith("PLUG")):
plug_section = 1
plug_header = [x.strip().lower() for x in line.split("|")]
diff --git a/fence/agents/xenapi/fence_xenapi.py b/fence/agents/xenapi/fence_xenapi.py
index 017908f..f583ea5 100644
--- a/fence/agents/xenapi/fence_xenapi.py
+++ b/fence/agents/xenapi/fence_xenapi.py
@@ -54,12 +54,13 @@ def get_power_fn(session, options):
# Get a reference to the vm specified in the UUID or vm_name/port parameter
vm = return_vm_reference(session, options)
# Query the VM for its' associated parameters
- record = session.xenapi.VM.get_record(vm);
+ record = session.xenapi.VM.get_record(vm)
# Check that we are not trying to manipulate a template or a control
# domain as they show up as VM's with specific properties.
if not(record["is_a_template"]) and not(record["is_control_domain"]):
status = record["power_state"]
- if verbose: print "UUID:", record["uuid"], "NAME:", record["name_label"], "POWER STATUS:", record["power_state"]
+ if verbose:
+ print "UUID:", record["uuid"], "NAME:", record["name_label"], "POWER STATUS:", record["power_state"]
# Note that the VM can be in the following states (from the XenAPI document)
# Halted: VM is offline and not using any resources.
# Paused: All resources have been allocated but the VM itself is paused and its vCPUs are not running
@@ -100,7 +101,7 @@ def set_power_fn(session, options):
# Force reboot the VM
session.xenapi.VM.hard_reboot(vm)
except Exception, exn:
- print str(exn);
+ print str(exn)
# Function to populate an array of virtual machines and their status
def get_outlet_list(session, options):
@@ -115,7 +116,7 @@ def get_outlet_list(session, options):
vms = session.xenapi.VM.get_all()
for vm in vms:
# Query the VM for its' associated parameters
- record = session.xenapi.VM.get_record(vm);
+ record = session.xenapi.VM.get_record(vm)
# Check that we are not trying to manipulate a template or a control
# domain as they show up as VM's with specific properties.
if not(record["is_a_template"]) and not(record["is_control_domain"]):
@@ -123,9 +124,10 @@ def get_outlet_list(session, options):
uuid = record["uuid"]
status = record["power_state"]
result[uuid] = (name, status)
- if verbose: print "UUID:", record["uuid"], "NAME:", name, "POWER STATUS:", record["power_state"]
+ if verbose:
+ print "UUID:", record["uuid"], "NAME:", name, "POWER STATUS:", record["power_state"]
except Exception, exn:
- print str(exn);
+ print str(exn)
return result
@@ -137,18 +139,18 @@ def connect_and_login(options):
try:
# Create the XML RPC session to the specified URL.
- session = XenAPI.Session(url);
+ session = XenAPI.Session(url)
# Login using the supplied credentials.
- session.xenapi.login_with_password(username, password);
+ session.xenapi.login_with_password(username, password)
except Exception, exn:
- print str(exn);
+ print str(exn)
# http://sources.redhat.com/cluster/wiki/FenceAgentAPI says that for no connectivity
# the exit value should be 1. It doesn't say anything about failed logins, so
# until I hear otherwise it is best to keep this exit the same to make sure that
# anything calling this script (that uses the same information in the web page
# above) knows that this is an error condition, not a msg signifying a down port.
- sys.exit(EC_BAD_SESSION);
- return session;
+ sys.exit(EC_BAD_SESSION)
+ return session
# return a reference to the VM by either using the UUID or the vm_name/port. If the UUID is set then
# this is tried first as this is the only properly unique identifier.
@@ -167,8 +169,9 @@ def return_vm_reference(session, options):
# need to catch and re-raise the exception produced by get_by_uuid.
try:
return session.xenapi.VM.get_by_uuid(uuid)
- except Exception,exn:
- if verbose: print "No VM's found with a UUID of \"%s\"" %uuid
+ except Exception, exn:
+ if verbose:
+ print "No VM's found with a UUID of \"%s\"" % uuid
raise
@@ -182,13 +185,15 @@ def return_vm_reference(session, options):
return vm_arr[0]
else:
if len(vm_arr) == 0:
- if verbose: print "No VM's found with a name of \"%s\"" %vm_name
+ if verbose:
+ print "No VM's found with a name of \"%s\"" % vm_name
# NAME_INVALID used as the XenAPI throws a UUID_INVALID if it can't find
# a VM with the specified UUID. This should make the output look fairly
# consistent.
raise Exception("NAME_INVALID")
else:
- if verbose: print "Multiple VM's have the name \"%s\", use UUID instead" %vm_name
+ if verbose:
+ print "Multiple VM's have the name \"%s\", use UUID instead" % vm_name
raise Exception("MULTIPLE_VMS_FOUND")
# We should never get to this case as the input processing checks that either the UUID or
11 years, 6 months
fence-agents: the annotated tag v3.1.11 has been created
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=1a3f07...
Commit: 1a3f07b257b69f4d19006bf72f713a7266cb0767
Parent: 0000000000000000000000000000000000000000
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: 2012-11-05 10:47 +0000
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: 2012-11-05 10:47 +0000
annotated tag: v3.1.11 has been created
at 1a3f07b257b69f4d19006bf72f713a7266cb0767 (tag)
tagging 4727d7e280c53ea2c3fca502c945b70418a5a7d1 (commit)
replaces v3.1.10
v3.1.11 release
Marek 'marx' Grac (8):
fence_rhevm: Support new API used in RHEV-M 3.1
fence_rhevm: fix typo in RE
fence_na: Add support for XML metadata output
fence-agents: Extend set of default device options
fence_cisco_ucs: Incorrect timeout was used during login
fence-agents: Use default values for device options instead of per-agent solutions
fabric fence agents: Fix dealing with enable/disable and support on/off options for fabric fence agents
fence_ipmilan: Fix manual page for HP iLO3, HP iLO4
11 years, 6 months
fence-agents: master - fence_ipmilan: Fix manual page for HP iLO3, HP iLO4
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=4727d7...
Commit: 4727d7e280c53ea2c3fca502c945b70418a5a7d1
Parent: c7ba00daf03a19d7557e825e637a220b5cc4deae
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 11:39:15 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Mon Nov 5 11:39:15 2012 +0100
fence_ipmilan: Fix manual page for HP iLO3, HP iLO4
---
fence/agents/ipmilan/ipmilan.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index d1a0530..1eb733e 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -903,14 +903,14 @@ static void print_xml_metadata(char *pname) {
printf("%s\n","<?xml version=\"1.0\" ?>");
printf("%s%s%s\n","<resource-agent name=\"",pname,"\" shortdesc=\"Fence agent for IPMI over LAN\">");
- printf("<symlink name=\"fence_ilo3\" shortdesc=\"Fence agent for HP iLO2\"/>\n");
+ printf("<symlink name=\"fence_ilo3\" shortdesc=\"Fence agent for HP iLO3\"/>\n");
printf("<symlink name=\"fence_idrac\" shortdesc=\"Fence agent for Dell iDRAC\"/>\n");
printf("<symlink name=\"fence_imm\" shortdesc=\"Fence agent for IBM Integrated Management Module\"/>\n");
printf("<longdesc>\n");
printf("fence_ipmilan is an I/O Fencing agent which can be used with "
"machines controlled by IPMI. This agent calls support software "
"using ipmitool (http://ipmitool.sf.net/).\n\n"
- "To use fence_ipmilan with HP iLO 3 you have to enable lanplus "
+ "To use fence_ipmilan with HP iLO 3 or HP iLO 4 you have to enable lanplus "
"option (lanplus / -P) and increase wait after operation to "
"4 seconds (power_wait=4 / -T 4)");
printf("</longdesc>\n");
11 years, 6 months
dlm: master - dlm_controld: new var dirs
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=dlm.git;a=commitdiff;h=47115c611ff9861...
Commit: 47115c611ff9861900d374879b50818831b6d663
Parent: 20eba93563bab4521c63618a797e662c3bfca3d8
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Nov 2 16:24:05 2012 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Nov 2 16:24:05 2012 -0500
dlm_controld: new var dirs
/var/run/dlm_controld
/var/log/dlm_controld
instead of
/var/run/dlm
/var/log/dlm
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
dlm_controld/dlm_daemon.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
index ffd501c..916ee58 100644
--- a/dlm_controld/dlm_daemon.h
+++ b/dlm_controld/dlm_daemon.h
@@ -62,8 +62,8 @@
/* TODO: get CONFDIR, LOGDIR, RUNDIR from build */
-#define RUNDIR "/var/run/dlm"
-#define LOGDIR "/var/log/dlm"
+#define RUNDIR "/var/run/dlm_controld"
+#define LOGDIR "/var/log/dlm_controld"
#define CONFDIR "/etc/dlm"
#define RUN_FILE_NAME "dlm_controld.pid"
11 years, 6 months
dlm: master - Do not crash uncleanly on SIGINT and SIGHUP
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=dlm.git;a=commitdiff;h=20eba93563bab45...
Commit: 20eba93563bab4521c63618a797e662c3bfca3d8
Parent: f0e026c225dda5090ebb5da5622223a4b786e4ed
Author: Jacek Konieczny <jajcus(a)jajcus.net>
AuthorDate: Fri Nov 2 16:39:50 2012 +0100
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Nov 2 10:59:49 2012 -0500
Do not crash uncleanly on SIGINT and SIGHUP
Unclean shut-down of dlm_controld may trigger a node fencing,
this should not be triggered by mistake.
SIGINT is the natural way to stop dlm_controld started on a terminal
with '-D' for debugging – let this work like SIGTERM.
SIGHUP is often used for config reload. dlm_controld doesn't support
that, but when someone tries this by mistake, this is not a reason to
crash.
Signed-off-by: Jacek Konieczny <jajcus(a)jajcus.net>
---
dlm_controld/main.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
index 6eafa49..fd469f9 100644
--- a/dlm_controld/main.c
+++ b/dlm_controld/main.c
@@ -1582,6 +1582,15 @@ int main(int argc, char **argv)
rv = sigaction(SIGTERM, &act, NULL);
if (rv < 0)
return -rv;
+ rv = sigaction(SIGINT, &act, NULL);
+ if (rv < 0)
+ return -rv;
+
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = SIG_IGN;
+ rv = sigaction(SIGHUP, &act, NULL);
+ if (rv < 0)
+ return -rv;
memset(&act, 0, sizeof(act));
act.sa_handler = sigchld_handler;
11 years, 6 months
dlm: master - Run dlm.service after sys-kernel-config.mount
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=dlm.git;a=commitdiff;h=f0e026c225dda50...
Commit: f0e026c225dda5090ebb5da5622223a4b786e4ed
Parent: 8b74fc075d10b3a6602c140b6a2bd62bbded9506
Author: Jacek Konieczny <jajcus(a)jajcus.net>
AuthorDate: Fri Nov 2 16:39:49 2012 +0100
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Nov 2 10:59:49 2012 -0500
Run dlm.service after sys-kernel-config.mount
dlm_controld requires configfs mounted. systemd can take care for that,
but it does it better if the order is set in the unit file.
Signed-off-by: Jacek Konieczny <jajcus(a)jajcus.net>
---
init/dlm.service | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/init/dlm.service b/init/dlm.service
index d7cf9c7..3c4e53e 100644
--- a/init/dlm.service
+++ b/init/dlm.service
@@ -1,6 +1,6 @@
[Unit]
Description=dlm control daemon
-After=syslog.target network.target corosync.service
+After=syslog.target network.target corosync.service sys-kernel-config.mount
[Service]
Type=forking
11 years, 6 months