Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py
index 8d5a4bdd..3f39b2d1 100644
--- a/fence/agents/alom/fence_alom.py
+++ b/fence/agents/alom/fence_alom.py
@@ -1,80 +1,68 @@
#!/usr/bin/python
# The Following Agent Has Been Tested On:
#
# Sun(tm) Advanced Lights Out Manager CMT v1.6.1
# as found on SUN T2000 Niagara
import sys, re, pexpect, time, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="Sun Advanced Lights Out Manager (ALOM)"
REDHAT_COPYRIGHT=""
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",
"identity_file", "test", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["secure"]["default"] = "1"
all_opt["cmd_prompt"]["default"] = [ "sc\>\ " ]
options = check_input(device_opt, process_input(device_opt))
options["telnet_over_ssh"] = 1
docs = { }
docs["shortdesc"] = "Fence agent for Sun ALOM"
docs["longdesc"] = "fence_alom is an I/O Fencing \
agent which can be used with ALOM connected machines."
docs["vendorurl"] = "http://www.sun.com"
show_docs(options, docs)
# Operate the fencing device
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, None)
# Logout from system
try:
conn.send_eol("logout")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index fa1c3a65..743627a9 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -1,237 +1,228 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Model Firmware
## +---------------------------------------------+
## AP7951 AOS v2.7.0, PDU APP v2.7.3
## AP7941 AOS v3.5.7, PDU APP v3.5.6
## AP9606 AOS v2.5.4, PDU APP v2.7.3
##
## @note: ssh is very slow on AP79XX devices protocol (1) and
## cipher (des/blowfish) have to be defined
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New APC Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
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
else:
try:
(_, status) = outlets[options["-n"]]
return status.lower().strip()
except KeyError:
fail(EC_STATUS)
def set_power_status(conn, options):
action = {
'on' : "1",
'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",
"secure", "port", "identity_file", "switch", "test", "separator",
"inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = "\n>"
options = check_input(device_opt, process_input(device_opt))
options["ssh_options"] = "-1 -c blowfish"
docs = { }
docs["shortdesc"] = "Fence agent for APC over telnet/ssh"
docs["longdesc"] = "fence_apc is an I/O Fencing agent \
which can be used with the APC network power switch. It logs into device \
via telnet/ssh and reboots a specified outlet. Lengthy telnet/ssh connections \
should be avoided while a GFS cluster is running because the connection \
will block any necessary fencing actions."
docs["vendorurl"] = "http://www.apc.com"
show_docs(options, docs)
## 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
##
## Operate the fencing device
####
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
##
## Logout from system
##
## In some special unspecified cases it is possible that
## connection will be closed before we run close(). This is not
## a problem because everything is checked before.
######
try:
conn.send_eol("4")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index 2825dbec..726a15f6 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -1,136 +1,121 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Model Firmware
## +--------------------+---------------------------+
## (1) Main application BRET85K, rev 16
## Boot ROM BRBR67D, rev 16
## Remote Control BRRG67D, rev 16
##
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New Bladecenter Agent - test release on steroids"
REDHAT_COPYRIGHT=""
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
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "port", "identity_file", "separator",
"inet4_only", "inet6_only", "ipport", "missing_as_off" ]
atexit.register(atexit_handler)
all_opt["power_wait"]["default"] = "10"
all_opt["cmd_prompt"]["default"] = "system>"
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for IBM BladeCenter"
docs["longdesc"] = "fence_bladecenter is an I/O Fencing agent \
which can be used with IBM Bladecenters with recent enough firmware that \
includes telnet support. It logs into a Brocade chasis via telnet or ssh \
and uses the command line interface to power on and off blades."
docs["vendorurl"] = "http://www.ibm.com"
show_docs(options, docs)
##
## Operate the fencing device
######
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
##
## Logout from system
######
try:
conn.send_eol("exit")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/cisco_ucs/fence_cisco_ucs.py b/fence/agents/cisco_ucs/fence_cisco_ucs.py
index d1d5f2bd..5ed2c350 100644
--- a/fence/agents/cisco_ucs/fence_cisco_ucs.py
+++ b/fence/agents/cisco_ucs/fence_cisco_ucs.py
@@ -1,155 +1,143 @@
#!/usr/bin/python
import sys, re
import pycurl, StringIO
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New Cisco UCS Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
RE_COOKIE = re.compile("<aaaLogin .* outCookie=\"(.*?)\"", re.IGNORECASE)
RE_STATUS = re.compile("<lsPower .*? state=\"(.*?)\"", re.IGNORECASE)
RE_GET_DN = re.compile(" dn=\"(.*?)\"", re.IGNORECASE)
RE_GET_DESC = re.compile(" descr=\"(.*?)\"", re.IGNORECASE)
def get_power_status(conn, options):
- try:
- res = send_command(options, \
- "<configResolveDn cookie=\"" + options["cookie"] + "\" inHierarchical=\"false\" dn=\"org-root" + 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):
fail(EC_STATUS)
else:
status = result.group(1)
if (status == "up"):
return "on"
else:
return "off"
def set_power_status(conn, options):
action = {
'on' : "up",
'off' : "down"
}[options["-o"]]
- try:
- res = send_command(options, \
+ 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
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)):
dn = RE_GET_DN.search(lines[i]).group(1)
desc = RE_GET_DESC.search(lines[i]).group(1)
outlets[dn] = (desc, None)
except AttributeError:
return { }
except IndexError:
return { }
return outlets
def send_command(opt, command, timeout):
## setup correct URL
if opt.has_key("-z"):
url = "https:"
else:
url = "http:"
url += "//" + opt["-a"] + ":" + str(opt["-u"]) + "/nuova"
## send command through pycurl
c = pycurl.Curl()
b = StringIO.StringIO()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HTTPHEADER, [ "Content-type: text/xml" ])
c.setopt(pycurl.POSTFIELDS, command)
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.TIMEOUT, timeout)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.perform()
result = b.getvalue()
if opt["log"] >= LOG_MODE_VERBOSE:
opt["debug_fh"].write(command + "\n")
opt["debug_fh"].write(result + "\n")
return result
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"ssl", "inet4_only", "inet6_only", "ipport", "port",
"web", "separator", "suborg" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for Cisco UCS"
docs["longdesc"] = "fence_cisco_ucs is an I/O Fencing agent which can be \
used with Cisco UCS to fence machines."
docs["vendorurl"] = "http://www.cisco.com"
show_docs(options, docs)
### Login
res = send_command(options, "<aaaLogin inName=\"" + options["-l"] + "\" inPassword=\"" + options["-p"] + "\" />", int(options["-y"]))
result = RE_COOKIE.search(res)
if (result == None):
## Cookie is absenting in response
fail(EC_LOGIN_DENIED)
options["cookie"] = result.group(1)
##
## Modify suborg to format /suborg
if options["-s"] != "":
if options["-s"].startswith("/") == False:
options["-s"] = "/" + options["-s"]
if options["-s"].endswith("/") == True:
options["-s"] = options["-s"][0:-1]
##
## Fence operations
####
result = fence_action(None, options, set_power_status, get_power_status, get_list)
### Logout; we do not care about result as we will end in any case
send_command(options, "<aaaLogout inCookie=\"" + options["cookie"] + "\" />", int(options["-Y"]))
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index d8f4bb86..f8c129d9 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -1,140 +1,125 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## DRAC Version Firmware
## +-----------------+---------------------------+
## DRAC 5 1.0 (Build 06.05.12)
## DRAC 5 1.21 (Build 07.05.04)
##
## @note: drac_version was removed
#####
import sys, re, pexpect, exceptions, time
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New Drac5 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
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"]:
return "on"
else:
return "off"
def set_power_status(conn, options):
action = {
'on' : "powerup",
'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
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "identity_file", "drac_version", "module_name",
"separator", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = [ "\$" ]
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for Dell DRAC CMC/5"
docs["longdesc"] = "fence_drac5 is an I/O Fencing agent \
which can be used with the Dell Remote Access Card v5 or CMC (DRAC). \
This device provides remote access to controlling power to a server. \
It logs into the DRAC through the telnet/ssh interface of the card. \
By default, the telnet interface is not enabled."
docs["vendorurl"] = "http://www.dell.com"
show_docs(options, docs)
##
## Operate the fencing device
######
conn = fence_login(options)
if conn.before.find("CMC") >= 0:
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"
elif conn.before.find("DRAC 5") >= 0:
options["model"] = "DRAC 5"
else:
## Assume this is DRAC 5 by default as we don't want to break anything
options["model"] = "DRAC 5"
result = fence_action(conn, options, set_power_status, get_power_status, get_list_devices)
##
## Logout from system
######
try:
conn.send_eol("exit")
time.sleep(1)
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
index c7ceb194..c4f045e2 100644
--- a/fence/agents/hpblade/fence_hpblade.py
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -1,113 +1,99 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
## * BladeSystem c7000 Enclosure
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New Bladecenter Agent - test release on steroids"
REDHAT_COPYRIGHT=""
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
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "port", "identity_file", "separator",
"inet4_only", "inet6_only", "ipport", "missing_as_off" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = "c7000oa>"
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for HP BladeSystem"
docs["longdesc"] = "fence_hpblade is an I/O Fencing agent \
which can be used with HP BladeSystem. It logs into an enclosure via telnet or ssh \
and uses the command line interface to power on and off blades."
docs["vendorurl"] = "http://www.hp.com"
show_docs(options, docs)
##
## Operate the fencing device
######
options["eol"] = "\n"
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
##
## Logout from system
######
try:
conn.send_eol("exit")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/ilo/fence_ilo.py b/fence/agents/ilo/fence_ilo.py
index 715b163b..66472aa9 100644
--- a/fence/agents/ilo/fence_ilo.py
+++ b/fence/agents/ilo/fence_ilo.py
@@ -1,122 +1,117 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## iLO Version
## +---------------------------------------------+
## iLO / firmware 1.91 / RIBCL 2.22
## iLO2 / firmware 1.22 / RIBCL 2.22
## iLO2 / firmware 1.50 / RIBCL 2.22
#####
import sys, re, pexpect
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New ILO Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
def get_power_status(conn, options):
conn.send("<LOGIN USER_LOGIN = \"" + options["-l"] + "\"" + \
" 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()
def set_power_status(conn, options):
conn.send("<LOGIN USER_LOGIN = \"" + options["-l"] + "\"" + \
" PASSWORD = \"" + options["-p"] + "\">\r\n")
conn.send("<SERVER_INFO MODE = \"write\">")
if options.has_key("fw_processor") and options["fw_processor"] == "iLO2":
if options["fw_version"] > 1.29:
conn.send("<HOLD_PWR_BTN TOGGLE=\"yes\" />\r\n")
else:
conn.send("<HOLD_PWR_BTN />\r\n")
elif options["-r"] < 2.21:
conn.send("<SET_HOST_POWER HOST_POWER = \"" + options["-o"] + "\" />\r\n")
else:
if options["-o"] == "off":
conn.send("<HOLD_PWR_BTN/>\r\n")
else:
conn.send("<PRESS_PWR_BTN/>\r\n")
conn.send("</SERVER_INFO></LOGIN>\r\n")
return
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script",
"ssl", "ribcl", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["login_timeout"]["default"] = "10"
all_opt["retry_on"]["default"] = "3"
all_opt["ssl"]["default"] = "1"
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for HP iLO"
docs["longdesc"] = "fence_ilo is an I/O Fencing agent \
used for HP servers with the Integrated Light Out (iLO) PCI card.\
The agent opens an SSL connection to the iLO card. Once the SSL \
connection is established, the agent is able to communicate with \
the iLO card through an XML stream."
docs["vendorurl"] = "http://www.hp.com"
docs["symlink"] = [("fence_ilo2", "Fence agent for HP iLO2")]
show_docs(options, docs)
##
## Login and get version number
####
conn = fence_login(options)
try:
conn.send("<?xml version=\"1.0\"?>\r\n")
conn.log_expect(options, [ "</RIBCL>", "<END_RIBCL/>" ], int(options["-y"]))
version = re.compile("<RIBCL VERSION=\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1)
if options.has_key("-r") == 0:
options["-r"] = float(version)
if options["-r"] >= 2:
conn.send("<RIBCL VERSION=\"2.0\">\r\n")
else:
conn.send("<RIBCL VERSION=\"1.2\">\r\n")
conn.send("<LOGIN USER_LOGIN = \"" + options["-l"] + "\"" + \
" PASSWORD = \"" + options["-p"] + "\">\r\n")
if options["-r"] >= 2:
conn.send("<RIB_INFO MODE=\"read\"><GET_FW_VERSION />\r\n")
conn.send("</RIB_INFO>\r\n")
conn.log_expect(options, "<GET_FW_VERSION\s*\n", int(options["-Y"]))
conn.log_expect(options, "/>", int(options["-Y"]))
options["fw_version"] = float(re.compile("FIRMWARE_VERSION\s*=\s*\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1))
options["fw_processor"] = re.compile("MANAGEMENT_PROCESSOR\s*=\s*\"(.*?)\"", re.IGNORECASE).search(conn.before).group(1)
conn.send("</LOGIN>\r\n")
except pexpect.TIMEOUT:
fail(EC_LOGIN_DENIED)
except pexpect.EOF:
fail(EC_LOGIN_DENIED)
##
## Fence operations
####
result = fence_action(conn, options, set_power_status, get_power_status, None)
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py
index 9c18336e..7cf068ac 100644
--- a/fence/agents/ilo_mp/fence_ilo_mp.py
+++ b/fence/agents/ilo_mp/fence_ilo_mp.py
@@ -1,82 +1,72 @@
#!/usr/bin/python
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION=""
REDHAT_COPYRIGHT=""
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",
"secure", "identity_file", "cmd_prompt", "ipport",
"separator", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = [ "MP>", "hpiLO->" ]
all_opt["power_wait"]["default"] = 5
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for HP iLO MP"
docs["longdesc"] = ""
docs["vendorurl"] = "http://www.hp.com"
show_docs(options, docs)
conn = fence_login(options)
conn.send_eol("SMCLP")
##
## Fence operations
####
result = fence_action(conn, options, set_power_status, get_power_status)
try:
conn.send_eol("exit")
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py
index edbb2bf7..0d67e3fd 100644
--- a/fence/agents/ldom/fence_ldom.py
+++ b/fence/agents/ldom/fence_ldom.py
@@ -1,132 +1,120 @@
#!/usr/bin/python
##
## The Following Agent Has Been Tested On - LDOM 1.0.3
## The interface is backward compatible so it will work
## with 1.0, 1.0.1 and .2 too.
##
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="Logical Domains (LDoms) fence Agent"
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
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:
#CSH stuff
conn.send_eol("set prompt='"+COMMAND_PROMPT_NEW+"'")
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.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)):
fail_usage("Failed: You have to enter existing logical domain!")
else:
return result[options["-n"]][1]
else:
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",
"secure", "identity_file", "test" , "port", "cmd_prompt",
"separator", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["secure"]["default"] = "1"
all_opt["cmd_prompt"]["default"] = [ "\ $" ]
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for Sun LDOM"
docs["longdesc"] = "fence_ldom is an I/O Fencing agent \
which can be used with LDoms virtual machines. This agent works \
so, that run ldm command on host machine. So ldm must be directly \
runnable.\
\n.P\n\
Very useful parameter is -c (or cmd_prompt in stdin mode). This \
must be set to something, what is displayed after successful login \
to host machine. Default string is space on end of string (default \
for root in bash). But (for example) csh use ], so in that case you \
must use parameter -c with argument ]. Very similar situation is, \
if you use bash and login to host machine with other user than \
root. Than prompt is $, so again, you must use parameter -c."
docs["vendorurl"] = "http://www.sun.com"
show_docs(options, docs)
##
## Operate the fencing device
####
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
##
## Logout from system
######
try:
conn.send_eol("logout")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index af216962..9612b40d 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -1,977 +1,991 @@
#!/usr/bin/python
import sys, getopt, time, os
import pexpect, re, atexit
import __main__
## do not add code here.
#BEGIN_VERSION_GENERATION
RELEASE_VERSION = "New fence lib agent - test release on steroids"
REDHAT_COPYRIGHT = ""
BUILD_DATE = "March, 2008"
#END_VERSION_GENERATION
LOG_MODE_VERBOSE = 100
LOG_MODE_QUIET = 0
EC_GENERIC_ERROR = 1
EC_BAD_ARGS = 2
EC_LOGIN_DENIED = 3
EC_CONNECTION_LOST = 4
EC_TIMED_OUT = 5
EC_WAITING_ON = 6
EC_WAITING_OFF = 7
EC_STATUS = 8
EC_STATUS_HMC = 9
EC_PASSWORD_MISSING = 10
TELNET_PATH = "/usr/bin/telnet"
SSH_PATH = "/usr/bin/ssh"
SSL_PATH = "@SBINDIR@/fence_nss_wrapper"
SUDO_PATH = "/usr/bin/sudo"
all_opt = {
"help" : {
"getopt" : "h",
"longopt" : "help",
"help" : "-h, --help Display this help and exit",
"required" : "0",
"shortdesc" : "Display help and exit",
"order" : 54 },
"version" : {
"getopt" : "V",
"longopt" : "version",
"help" : "-V, --version Output version information and exit",
"required" : "0",
"shortdesc" : "Display version information and exit",
"order" : 53 },
"quiet" : {
"getopt" : "q",
"help" : "",
"order" : 50 },
"verbose" : {
"getopt" : "v",
"longopt" : "verbose",
"help" : "-v, --verbose Verbose mode",
"required" : "0",
"shortdesc" : "Verbose mode",
"order" : 51 },
"debug" : {
"getopt" : "D:",
"longopt" : "debug-file",
"help" : "-D, --debug-file=<debugfile> Debugging to output file",
"required" : "0",
"shortdesc" : "Write debug information to given file",
"order" : 52 },
"delay" : {
"getopt" : "f:",
"longopt" : "delay",
"help" : "--delay <seconds> Wait X seconds before fencing is started",
"required" : "0",
"shortdesc" : "Wait X seconds before fencing is started",
"default" : "0",
"order" : 200 },
"agent" : {
"getopt" : "",
"help" : "",
"order" : 1 },
"web" : {
"getopt" : "",
"help" : "",
"order" : 1 },
"action" : {
"getopt" : "o:",
"longopt" : "action",
"help" : "-o, --action=<action> Action: status, reboot (default), off or on",
"required" : "1",
"shortdesc" : "Fencing Action",
"default" : "reboot",
"order" : 1 },
"fabric_fencing" : {
"getopt" : "",
"help" : "",
"order" : 1 },
"ipaddr" : {
"getopt" : "a:",
"longopt" : "ip",
"help" : "-a, --ip=<ip> IP address or hostname of fencing device",
"required" : "1",
"shortdesc" : "IP Address or Hostname",
"order" : 1 },
"ipport" : {
"getopt" : "u:",
"longopt" : "ipport",
"help" : "-u, --ipport=<port> TCP port to use",
"required" : "0",
"shortdesc" : "TCP port to use for connection with device",
"order" : 1 },
"login" : {
"getopt" : "l:",
"longopt" : "username",
"help" : "-l, --username=<name> Login name",
"required" : "?",
"shortdesc" : "Login Name",
"order" : 1 },
"no_login" : {
"getopt" : "",
"help" : "",
"order" : 1 },
"no_password" : {
"getopt" : "",
"help" : "",
"order" : 1 },
"passwd" : {
"getopt" : "p:",
"longopt" : "password",
"help" : "-p, --password=<password> Login password or passphrase",
"required" : "0",
"shortdesc" : "Login password or passphrase",
"order" : 1 },
"passwd_script" : {
"getopt" : "S:",
"longopt" : "password-script=",
"help" : "-S, --password-script=<script> Script to run to retrieve password",
"required" : "0",
"shortdesc" : "Script to retrieve password",
"order" : 1 },
"identity_file" : {
"getopt" : "k:",
"longopt" : "identity-file",
"help" : "-k, --identity-file=<filename> Identity file (private key) for ssh ",
"required" : "0",
"shortdesc" : "Identity file for ssh",
"order" : 1 },
"module_name" : {
"getopt" : "m:",
"longopt" : "module-name",
"help" : "-m, --module-name=<module> DRAC/MC module name",
"required" : "0",
"shortdesc" : "DRAC/MC module name",
"order" : 1 },
"drac_version" : {
"getopt" : "d:",
"longopt" : "drac-version",
"help" : "-d, --drac-version=<version> Force DRAC version to use",
"required" : "0",
"shortdesc" : "Force DRAC version to use",
"order" : 1 },
"hmc_version" : {
"getopt" : "H:",
"longopt" : "hmc-version",
"help" : "-H, --hmc-version=<version> Force HMC version to use: 3, 4 (default)",
"required" : "0",
"shortdesc" : "Force HMC version to use (3 or 4)",
"default" : "4",
"order" : 1 },
"ribcl" : {
"getopt" : "r:",
"longopt" : "ribcl-version",
"help" : "-r, --ribcl-version=<version> Force ribcl version to use",
"required" : "0",
"shortdesc" : "Force ribcl version to use",
"order" : 1 },
"cmd_prompt" : {
"getopt" : "c:",
"longopt" : "command-prompt",
"help" : "-c, --command-prompt=<prompt> Force command prompt",
"shortdesc" : "Force command prompt",
"required" : "0",
"order" : 1 },
"secure" : {
"getopt" : "x",
"longopt" : "ssh",
"help" : "-x, --ssh Use ssh connection",
"shortdesc" : "SSH connection",
"required" : "0",
"order" : 1 },
"ssl" : {
"getopt" : "z",
"longopt" : "ssl",
"help" : "-z, --ssl Use ssl connection",
"required" : "0",
"shortdesc" : "SSL connection",
"order" : 1 },
"port" : {
"getopt" : "n:",
"longopt" : "plug",
"help" : "-n, --plug=<id> Physical plug number on device or\n" +
" name of virtual machine",
"required" : "1",
"shortdesc" : "Physical plug number or name of virtual machine",
"order" : 1 },
"switch" : {
"getopt" : "s:",
"longopt" : "switch",
"help" : "-s, --switch=<id> Physical switch number on device",
"required" : "0",
"shortdesc" : "Physical switch number on device",
"order" : 1 },
"suborg" : {
"getopt" : "s:",
"longopt" : "suborg",
"help" : "--suborg=<path> Additional path needed to access suborganization",
"required" : "0",
"shortdesc" : "Additional path needed to access suborganization",
"default" : "",
"order" : 1 },
"partition" : {
"getopt" : "n:",
"help" : "-n <id> Name of the partition",
"required" : "0",
"shortdesc" : "Partition name",
"order" : 1 },
"managed" : {
"getopt" : "s:",
"help" : "-s <id> Name of the managed system",
"required" : "0",
"shortdesc" : "Managed system name",
"order" : 1 },
"test" : {
"getopt" : "T",
"help" : "",
"order" : 1,
"obsolete" : "use -o status instead" },
"exec" : {
"getopt" : "e:",
"longopt" : "exec",
"help" : "-e, --exec=<command> Command to execute",
"required" : "0",
"shortdesc" : "Command to execute",
"order" : 1 },
"vmware_type" : {
"getopt" : "d:",
"longopt" : "vmware_type",
"help" : "-d, --vmware_type=<type> Type of VMware to connect",
"required" : "0",
"shortdesc" : "Type of VMware to connect",
"order" : 1 },
"vmware_datacenter" : {
"getopt" : "s:",
"longopt" : "vmware-datacenter",
"help" : "-s, --vmware-datacenter=<dc> VMWare datacenter filter",
"required" : "0",
"shortdesc" : "Show only machines in specified datacenter",
"order" : 2 },
"snmp_version" : {
"getopt" : "d:",
"longopt" : "snmp-version",
"help" : "-d, --snmp-version=<ver> Specifies SNMP version to use",
"required" : "0",
"shortdesc" : "Specifies SNMP version to use (1,2c,3)",
"order" : 1 },
"community" : {
"getopt" : "c:",
"longopt" : "community",
"help" : "-c, --community=<community> Set the community string",
"required" : "0",
"shortdesc" : "Set the community string",
"order" : 1},
"snmp_auth_prot" : {
"getopt" : "b:",
"longopt" : "snmp-auth-prot",
"help" : "-b, --snmp-auth-prot=<prot> Set authentication protocol (MD5|SHA)",
"required" : "0",
"shortdesc" : "Set authentication protocol (MD5|SHA)",
"order" : 1},
"snmp_sec_level" : {
"getopt" : "E:",
"longopt" : "snmp-sec-level",
"help" : "-E, --snmp-sec-level=<level> Set security level\n"+
" (noAuthNoPriv|authNoPriv|authPriv)",
"required" : "0",
"shortdesc" : "Set security level (noAuthNoPriv|authNoPriv|authPriv)",
"order" : 1},
"snmp_priv_prot" : {
"getopt" : "B:",
"longopt" : "snmp-priv-prot",
"help" : "-B, --snmp-priv-prot=<prot> Set privacy protocol (DES|AES)",
"required" : "0",
"shortdesc" : "Set privacy protocol (DES|AES)",
"order" : 1},
"snmp_priv_passwd" : {
"getopt" : "P:",
"longopt" : "snmp-priv-passwd",
"help" : "-P, --snmp-priv-passwd=<pass> Set privacy protocol password",
"required" : "0",
"shortdesc" : "Set privacy protocol password",
"order" : 1},
"snmp_priv_passwd_script" : {
"getopt" : "R:",
"longopt" : "snmp-priv-passwd-script",
"help" : "-R, --snmp-priv-passwd-script Script to run to retrieve privacy password",
"required" : "0",
"shortdesc" : "Script to run to retrieve privacy password",
"order" : 1},
"inet4_only" : {
"getopt" : "4",
"longopt" : "inet4-only",
"help" : "-4, --inet4-only Forces agent to use IPv4 addresses only",
"required" : "0",
"shortdesc" : "Forces agent to use IPv4 addresses only",
"order" : 1 },
"inet6_only" : {
"getopt" : "6",
"longopt" : "inet6-only",
"help" : "-6, --inet6-only Forces agent to use IPv6 addresses only",
"required" : "0",
"shortdesc" : "Forces agent to use IPv6 addresses only",
"order" : 1 },
"udpport" : {
"getopt" : "u:",
"longopt" : "udpport",
"help" : "-u, --udpport UDP/TCP port to use",
"required" : "0",
"shortdesc" : "UDP/TCP port to use for connection with device",
"order" : 1},
"separator" : {
"getopt" : "C:",
"longopt" : "separator",
"help" : "-C, --separator=<char> Separator for CSV created by 'list' operation",
"default" : ",",
"required" : "0",
"shortdesc" : "Separator for CSV created by operation list",
"order" : 100 },
"login_timeout" : {
"getopt" : "y:",
"longopt" : "login-timeout",
"help" : "--login-timeout <seconds> Wait X seconds for cmd prompt after login",
"default" : "5",
"required" : "0",
"shortdesc" : "Wait X seconds for cmd prompt after login",
"order" : 200 },
"shell_timeout" : {
"getopt" : "Y:",
"longopt" : "shell-timeout",
"help" : "--shell-timeout <seconds> Wait X seconds for cmd prompt after issuing command",
"default" : "3",
"required" : "0",
"shortdesc" : "Wait X seconds for cmd prompt after issuing command",
"order" : 200 },
"power_timeout" : {
"getopt" : "g:",
"longopt" : "power-timeout",
"help" : "--power-timeout <seconds> Test X seconds for status change after ON/OFF",
"default" : "20",
"required" : "0",
"shortdesc" : "Test X seconds for status change after ON/OFF",
"order" : 200 },
"power_wait" : {
"getopt" : "G:",
"longopt" : "power-wait",
"help" : "--power-wait <seconds> Wait X seconds after issuing ON/OFF",
"default" : "0",
"required" : "0",
"shortdesc" : "Wait X seconds after issuing ON/OFF",
"order" : 200 },
"missing_as_off" : {
"getopt" : "M",
"longopt" : "missing-as-off",
"help" : "--missing-as-off Missing port returns OFF instead of failure",
"required" : "0",
"shortdesc" : "Missing port returns OFF instead of failure",
"order" : 200 },
"retry_on" : {
"getopt" : "F:",
"longopt" : "retry-on",
"help" : "--retry-on <attempts> Count of attempts to retry power on",
"default" : "1",
"required" : "0",
"shortdesc" : "Count of attempts to retry power on",
"order" : 201 },
"session_url" : {
"getopt" : "s:",
"longopt" : "session-url",
"help" : "-s, --session-url URL to connect to XenServer on",
"required" : "1",
"shortdesc" : "The URL of the XenServer host.",
"order" : 1},
"uuid" : {
"getopt" : "U:",
"longopt" : "uuid",
"help" : "-U, --uuid UUID of the VM to fence",
"required" : "0",
"shortdesc" : "The UUID of the virtual machine to fence.",
"order" : 1},
"sudo" : {
"getopt" : "d",
"longopt" : "use-sudo",
"help" : "--use-sudo Use sudo (without password) when calling 3rd party software",
"required" : "0",
"shortdesc" : "Use sudo (without password) when calling 3rd party sotfware.",
"order" : 205}
}
COMMON_OPT = [ "help", "debug", "verbose", "quiet", "version", "action", "agent",
"power_timeout", "shell_timeout", "login_timeout", "power_wait", "retry_on", "delay" ]
class fspawn(pexpect.spawn):
def __init__(self, options, command):
pexpect.spawn.__init__(self, command)
self.opt = options
def log_expect(self, options, pattern, timeout):
result = self.expect(pattern, timeout)
if options["log"] >= LOG_MODE_VERBOSE:
options["debug_fh"].write(self.before + self.after)
return result
# send EOL according to what was detected in login process (telnet)
def send_eol(self, message):
self.send(message + self.opt["eol"])
def atexit_handler():
try:
sys.stdout.close()
os.close(1)
except IOError:
sys.stderr.write("%s failed to close standard output\n"%(sys.argv[0]))
sys.exit(EC_GENERIC_ERROR)
def version(command, release, build_date, copyright_notice):
print command, " ", release, " ", build_date
if len(copyright_notice) > 0:
print copyright_notice
def fail_usage(message = ""):
if len(message) > 0:
sys.stderr.write(message+"\n")
sys.stderr.write("Please use '-h' for usage\n")
sys.exit(EC_GENERIC_ERROR)
def fail(error_code):
message = {
EC_LOGIN_DENIED : "Unable to connect/login to fencing device",
EC_CONNECTION_LOST : "Connection lost",
EC_TIMED_OUT : "Connection timed out",
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 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):
print "Usage:"
print "\t" + os.path.basename(sys.argv[0]) + " [options]"
print "Options:"
sorted_list = [ (key, all_opt[key]) for key in avail_opt ]
sorted_list.sort(lambda x, y: cmp(x[1]["order"], y[1]["order"]))
for key, value in sorted_list:
if len(value["help"]) != 0:
print " " + value["help"]
def metadata(avail_opt, options, docs):
sorted_list = [ (key, all_opt[key]) for key in avail_opt ]
sorted_list.sort(lambda x, y: cmp(x[1]["order"], y[1]["order"]))
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"]:
print "<symlink name=\"" + symlink + "\" shortdesc=\"" + desc + "\"/>"
print "<longdesc>" + docs["longdesc"] + "</longdesc>"
if docs.has_key("vendorurl"):
print "<vendor-url>" + docs["vendorurl"] + "</vendor-url>"
print "<parameters>"
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"] + "\">"
default = ""
if all_opt[option].has_key("default"):
default = "default=\""+str(all_opt[option]["default"])+"\""
elif options.has_key("-" + all_opt[option]["getopt"][:-1]):
if options["-" + all_opt[option]["getopt"][:-1]]:
try:
default = "default=\"" + options["-" + all_opt[option]["getopt"][:-1]] + "\""
except TypeError:
## @todo/@note: Currently there is no clean way how to handle lists
## we can create a string from it but we can't set it on command line
default = "default=\"" + str(options["-" + all_opt[option]["getopt"][:-1]]) +"\""
elif options.has_key("-" + all_opt[option]["getopt"]):
default = "default=\"true\" "
mixed = all_opt[option]["help"]
## split it between option and help text
res = re.compile("^(.*--\S+)\s+", re.IGNORECASE | re.S).search(mixed)
if (None != res):
mixed = res.group(1)
mixed = mixed.replace("<", "&lt;").replace(">", "&gt;")
print "\t\t<getopt mixed=\"" + mixed + "\" />"
if all_opt[option]["getopt"].count(":") > 0:
print "\t\t<content type=\"string\" "+default+" />"
else:
print "\t\t<content type=\"boolean\" "+default+" />"
print "\t\t<shortdesc lang=\"en\">" + all_opt[option]["shortdesc"] + "</shortdesc>"
print "\t</parameter>"
print "</parameters>"
print "<actions>"
print "\t<action name=\"on\" />"
print "\t<action name=\"off\" />"
if avail_opt.count("fabric_fencing") == 0:
print "\t<action name=\"reboot\" />"
print "\t<action name=\"status\" />"
print "\t<action name=\"list\" />"
print "\t<action name=\"monitor\" />"
print "\t<action name=\"metadata\" />"
print "</actions>"
print "</resource-agent>"
def process_input(avail_opt):
##
## Add options which are available for every fence agent
#####
avail_opt.extend(COMMON_OPT)
##
## Set standard environment
#####
os.putenv("LANG", "C")
os.putenv("LC_ALL", "C")
##
## Prepare list of options for getopt
#####
getopt_string = ""
longopt_list = [ ]
for k in avail_opt:
if all_opt.has_key(k):
getopt_string += all_opt[k]["getopt"]
else:
fail_usage("Parse error: unknown option '"+k+"'")
if all_opt.has_key(k) and all_opt[k].has_key("longopt"):
if all_opt[k]["getopt"].endswith(":"):
longopt_list.append(all_opt[k]["longopt"] + "=")
else:
longopt_list.append(all_opt[k]["longopt"])
## Compatibility layer
if avail_opt.count("module_name") == 1:
getopt_string += "n:"
longopt_list.append("plug=")
##
## Read options from command line or standard input
#####
if len(sys.argv) > 1:
try:
opt, _args = getopt.gnu_getopt(sys.argv[1:], getopt_string, longopt_list)
except getopt.GetoptError, error:
fail_usage("Parse error: " + error.msg)
## Transform longopt to short one which are used in fencing agents
#####
old_opt = opt
opt = { }
for o in dict(old_opt).keys():
if o.startswith("--"):
for x in all_opt.keys():
if all_opt[x].has_key("longopt") and "--" + all_opt[x]["longopt"] == o:
opt["-" + all_opt[x]["getopt"].rstrip(":")] = dict(old_opt)[o]
else:
opt[o] = dict(old_opt)[o]
## Compatibility Layer
#####
z = dict(opt)
if z.has_key("-T") == 1:
z["-o"] = "status"
if z.has_key("-n") == 1:
z["-m"] = z["-n"]
opt = z
##
#####
else:
opt = { }
name = ""
for line in sys.stdin.readlines():
line = line.strip()
if ((line.startswith("#")) or (len(line) == 0)):
continue
(name, value) = (line + "=").split("=", 1)
value = value[:-1]
## Compatibility Layer
######
if name == "blade":
name = "port"
elif name == "option":
name = "action"
elif name == "fm":
name = "port"
elif name == "hostname":
name = "ipaddr"
elif name == "modulename":
name = "module_name"
elif name == "port" and 1 == avail_opt.count("drac_version"):
name = "module_name"
##
######
if avail_opt.count(name) == 0:
sys.stderr.write("Parse error: Ignoring unknown option '"+line+"'\n")
continue
if all_opt[name]["getopt"].endswith(":"):
opt["-"+all_opt[name]["getopt"].rstrip(":")] = value
elif ((value == "1") or (value.lower() == "yes") or (value.lower() == "on") or (value.lower() == "true")):
opt["-"+all_opt[name]["getopt"]] = "1"
return opt
##
## This function checks input and answers if we want to have same answers
## in each of the fencing agents. It looks for possible errors and run
## password script to set a correct password
######
def check_input(device_opt, 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])
options = dict(opt)
options["device_opt"] = device_opt
## Set requirements that should be included in metadata
#####
if device_opt.count("login") and device_opt.count("no_login") == 0:
all_opt["login"]["required"] = "1"
else:
all_opt["login"]["required"] = "0"
## 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
## Set default values
#####
for opt in device_opt:
if all_opt[opt].has_key("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()
if options.has_key("-v"):
options["log"] = LOG_MODE_VERBOSE
else:
options["log"] = LOG_MODE_QUIET
acceptable_actions = [ "on", "off", "status", "list", "monitor" ]
if 0 == device_opt.count("fabric_fencing"):
## Compatibility layer
#####
acceptable_actions.extend(["enable", "disable"])
else:
acceptable_actions.extend(["reboot"])
if 0 == acceptable_actions.count(options["-o"]):
fail_usage("Failed: Unrecognised action '" + options["-o"] + "'")
## Compatibility layer
#####
if options["-o"] == "enable":
options["-o"] = "on"
if options["-o"] == "disable":
options["-o"] = "off"
if (0 == options.has_key("-l")) and device_opt.count("login") and (device_opt.count("no_login") == 0):
fail_usage("Failed: You have to set login name")
if 0 == options.has_key("-a") and 0 == options.has_key("-s"):
fail_usage("Failed: You have to enter fence address")
if (device_opt.count("no_password") == 0):
if 0 == device_opt.count("identity_file"):
if 0 == (options.has_key("-p") or options.has_key("-S")):
fail_usage("Failed: You have to enter password or password script")
else:
if 0 == (options.has_key("-p") or options.has_key("-S") or options.has_key("-k")):
fail_usage("Failed: You have to enter password, password script or identity file")
if 0 == options.has_key("-x") and 1 == options.has_key("-k"):
fail_usage("Failed: You have to use identity file together with ssh connection (-x)")
if 1 == options.has_key("-k"):
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")):
fail_usage("Failed: You have to enter plug number")
if options.has_key("-S"):
options["-p"] = os.popen(options["-S"]).read().rstrip()
if options.has_key("-D"):
try:
options["debug_fh"] = file (options["-D"], "w")
except IOError:
fail_usage("Failed: Unable to create file "+options["-D"])
if options.has_key("-v") and options.has_key("debug_fh") == 0:
options["debug_fh"] = sys.stderr
if options.has_key("-R"):
options["-P"] = os.popen(options["-R"]).read().rstrip()
if options.has_key("-u") == False:
if options.has_key("-x"):
options["-u"] = 22
elif options.has_key("-z"):
options["-u"] = 443
elif device_opt.count("web"):
options["-u"] = 80
else:
options["-u"] = 23
return options
def wait_power_status(tn, options, get_power_fn):
for dummy in xrange(int(options["-g"])):
if get_power_fn(tn, options) != options["-o"]:
time.sleep(1)
else:
return 1
return 0
def show_docs(options, docs = None):
device_opt = options["device_opt"]
if docs == None:
docs = { }
docs["shortdesc"] = "Fence agent"
docs["longdesc"] = ""
## Process special options (and exit)
#####
if options.has_key("-h"):
usage(device_opt)
sys.exit(0)
if options.has_key("-o") and options["-o"].lower() == "metadata":
metadata(device_opt, options, docs)
sys.exit(0)
if options.has_key("-V"):
print __main__.RELEASE_VERSION, __main__.BUILD_DATE
print __main__.REDHAT_COPYRIGHT
sys.exit(0)
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
def fence_login(options):
force_ipvx = ""
if (options.has_key("-6")):
force_ipvx = "-6 "
if (options.has_key("-4")):
force_ipvx = "-4 "
if (options.has_key("eol") == False):
options["eol"] = "\r\n"
## Do the delay of the fence device before logging in
## Delay is important for two-node clusters fencing but we do not need to delay 'status' operations
if options["-o"] in ["off", "reboot"]:
time.sleep(int(options["-f"]))
try:
re_login = re.compile("(login\s*: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE)
re_pass = re.compile("(password)|(pass phrase)", re.IGNORECASE)
if options.has_key("-z"):
command = '%s %s %s %s' % (SSL_PATH, force_ipvx, options["-a"], options["-u"])
try:
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)
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"):
command += ' ' + options["ssh_options"]
try:
conn = fspawn(options, command)
except pexpect.ExceptionPexpect, ex:
sys.stderr.write(str(ex) + "\n")
sys.stderr.write("Due to limitations, binary dependencies on fence agents "
"are not in the spec file and must be installed separately." + "\n")
sys.exit(EC_GENERIC_ERROR)
if options.has_key("telnet_over_ssh"):
#This is for stupid ssh servers (like ALOM) which behave more like telnet (ignore name and display login prompt)
result = conn.log_expect(options, [ re_login, "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"]))
if result == 1:
conn.sendline("yes") # Host identity confirm
conn.log_expect(options, re_login, int(options["-y"]))
conn.sendline(options["-l"])
conn.log_expect(options, re_pass, int(options["-y"]))
else:
result = conn.log_expect(options, [ "ssword:", "Are you sure you want to continue connecting (yes/no)?" ], int(options["-y"]))
if result == 1:
conn.sendline("yes")
conn.log_expect(options, "ssword:", int(options["-y"]))
conn.sendline(options["-p"])
conn.log_expect(options, options["-c"], int(options["-y"]))
elif options.has_key("-x") and 1 == options.has_key("-k"):
command = '%s %s %s@%s -i %s -p %s' % (SSH_PATH, force_ipvx, options["-l"], options["-a"], options["-k"], options["-u"])
if options.has_key("ssh_options"):
command += ' ' + options["ssh_options"]
try:
conn = fspawn(options, command)
except pexpect.ExceptionPexpect, ex:
sys.stderr.write(str(ex) + "\n")
sys.stderr.write("Due to limitations, binary dependencies on fence agents "
"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"]))
if result == 1:
conn.sendline("yes")
conn.log_expect(options, [ options["-c"], "Enter passphrase for key '"+options["-k"]+"':"] , int(options["-y"]))
if result != 0:
if options.has_key("-p"):
conn.sendline(options["-p"])
conn.log_expect(options, options["-c"], int(options["-y"]))
else:
fail_usage("Failed: You have to enter passphrase (-p) for identity file")
else:
try:
conn = fspawn(options, TELNET_PATH)
conn.send("set binary\n")
conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
except pexpect.ExceptionPexpect, ex:
sys.stderr.write(str(ex) + "\n")
sys.stderr.write("Due to limitations, binary dependencies on fence agents "
"are not in the spec file and must be installed separately." + "\n")
sys.exit(EC_GENERIC_ERROR)
result = conn.log_expect(options, re_login, int(options["-y"]))
conn.send_eol(options["-l"])
## automatically change end of line separator
screen = conn.read_nonblocking(size=100, timeout=int(options["-Y"]))
if (re_login.search(screen) != None):
options["eol"] = "\n"
conn.send_eol(options["-l"])
result = conn.log_expect(options, re_pass, int(options["-y"]))
elif (re_pass.search(screen) == None):
conn.log_expect(options, re_pass, int(options["-Y"]))
try:
conn.send_eol(options["-p"])
conn.log_expect(options, options["-c"], int(options["-Y"]))
except KeyError:
fail(EC_PASSWORD_MISSING)
except pexpect.EOF:
fail(EC_LOGIN_DENIED)
except pexpect.TIMEOUT:
fail(EC_LOGIN_DENIED)
return conn
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 5a14d56b..4522dfd6 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -1,178 +1,148 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Version
## +---------------------------------------------+
## Tested on HMC
##
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION=""
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
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)
except AttributeError:
fail(EC_STATUS_HMC)
##
## Transformation to standard ON/OFF status if possible
if status in ["Running", "Open Firmware", "Shutting Down", "Starting"]:
status = "on"
else:
status = "off"
return status
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
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "secure",
"identity_file", "partition", "managed", "hmc_version", "cmd_prompt",
"separator", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["login_timeout"]["default"] = "15"
all_opt["secure"]["default"] = "1"
all_opt["cmd_prompt"]["default"] = [ ":~>", "]\$", "\$ " ]
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for IBM LPAR"
docs["longdesc"] = ""
show_docs(options, docs)
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 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")
##
## Operate the fencing device
####
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_lpar_list)
##
## Logout from system
######
try:
conn.send("quit\r\n")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/rhevm/fence_rhevm.py b/fence/agents/rhevm/fence_rhevm.py
index e1de315f..7f5abdeb 100644
--- a/fence/agents/rhevm/fence_rhevm.py
+++ b/fence/agents/rhevm/fence_rhevm.py
@@ -1,142 +1,128 @@
#!/usr/bin/python
import sys, re
import pycurl, StringIO
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New RHEV-M Agent - test release on steroids"
REDHAT_COPYRIGHT=""
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)
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):
# Unable to obtain ID needed to access virtual machine
fail(EC_STATUS)
options["id"] = result.group(2)
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
# contain <status> line. We can assume machine is OFF then
return "off"
else:
status = result.group(1)
if (status.lower() == "down"):
return "off"
else:
return "on"
def set_power_status(conn, options):
action = {
'on' : "start",
'off' : "stop"
}[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)):
name = RE_GET_NAME.search(lines[i]).group(1)
outlets[name] = ("", None)
except AttributeError:
return { }
except IndexError:
return { }
return outlets
def send_command(opt, command, method = "GET"):
## setup correct URL
if opt.has_key("-z"):
url = "https:"
else:
url = "http:"
url += "//" + opt["-a"] + ":" + str(opt["-u"]) + "/api/" + command
## send command through pycurl
c = pycurl.Curl()
b = StringIO.StringIO()
c.setopt(pycurl.URL, url)
c.setopt(pycurl.HTTPHEADER, [ "Content-type: application/xml", "Accept: application/xml" ])
c.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
c.setopt(pycurl.USERPWD, opt["-l"] + ":" + opt["-p"])
c.setopt(pycurl.TIMEOUT, int(opt["-Y"]))
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
if (method == "POST"):
c.setopt(pycurl.POSTFIELDS, "<action />")
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
result = b.getvalue()
if opt["log"] >= LOG_MODE_VERBOSE:
opt["debug_fh"].write(command + "\n")
opt["debug_fh"].write(result + "\n")
return result
def main():
device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "ssl",
"inet4_only", "inet6_only", "ipport", "port", "web", "separator" ]
atexit.register(atexit_handler)
all_opt["power_wait"]["default"] = "1"
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for RHEV-M REST API"
docs["longdesc"] = "fence_rhevm is an I/O Fencing agent which can be \
used with RHEV-M REST API to fence virtual machines."
docs["vendorurl"] = "http://www.redhat.com"
show_docs(options, docs)
##
## Fence operations
####
result = fence_action(None, options, set_power_status, get_power_status, get_list)
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index 44ad33f6..75cf1f7d 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -1,91 +1,81 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
## Main GFEP25A & Boot GFBP25A
##
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New RSA2 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
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):
status = match.group(1)
else:
status = "undefined"
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",
"cmd_prompt", "secure", "identity_file", "ipport" ]
atexit.register(atexit_handler)
all_opt["login_timeout"]["default"] = 10
all_opt["cmd_prompt"]["default"] = [ ">" ]
options = check_input(device_opt, process_input(device_opt))
# This device will not allow us to login even with LANG=C
options["ssh_options"] = "-F /dev/null"
docs = { }
docs["shortdesc"] = "Fence agent for IBM RSA"
docs["longdesc"] = "fence_rsa is an I/O Fencing agent \
which can be used with the IBM RSA II management interface. It \
logs into an RSA II device via telnet and reboots the associated \
machine. Lengthy telnet connections to the RSA II device should \
be avoided while a GFS cluster is running because the connection \
will block any necessary fencing actions."
docs["vendorurl"] = "http://www.ibm.com"
show_docs(options, docs)
##
## Operate the fencing device
######
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, None)
##
## Logout from system
######
try:
conn.send_eol("exit")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index f8cd8271..40c922e4 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -1,109 +1,99 @@
#!/usr/bin/python
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION=""
REDHAT_COPYRIGHT=""
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 = {
'on' : "4",
'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",
"secure", "identity_file", "separator", "cmd_prompt",
"inet4_only", "inet6_only", "ipport", "telnet_port" ]
atexit.register(atexit_handler)
all_opt["telnet_port"] = {
"getopt" : "n:",
"longopt" : "telnet_port",
"help" : "-n TCP port to use (deprecated, use -u)",
"required" : "0",
"shortdesc" : "TCP port to use for connection with device (default is 3172 for telnet)",
"order" : 1
}
all_opt["cmd_prompt"]["default"] = "to quit:"
opt = process_input(device_opt)
# option -n for backward compatibility (-n is normally port no)
if 1 == opt.has_key("-n"):
opt["-u"] = opt["-n"]
# set default port for telnet only
if 0 == opt.has_key("-x") and 0 == opt.has_key("-u"):
opt["-u"] = 3172
options = check_input(device_opt, opt)
docs = { }
docs["shortdesc"] = "I/O Fencing agent for Fujitsu-Siemens RSB"
docs["longdesc"] = "fence_rsb is an I/O Fencing agent \
which can be used with the Fujitsu-Siemens RSB management interface. It logs \
into device via telnet/ssh and reboots a specified outlet. Lengthy telnet/ssh \
connections should be avoided while a GFS cluster is running because the connection \
will block any necessary fencing actions."
docs["vendorurl"] = "http://www.fujitsu.com"
show_docs(options, docs)
##
## Operate the fencing device
####
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, None)
##
## Logout from system
##
## In some special unspecified cases it is possible that
## connection will be closed before we run close(). This is not
## a problem because everything is checked before.
######
try:
conn.send_eol("0")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/sanbox2/fence_sanbox2.py b/fence/agents/sanbox2/fence_sanbox2.py
index 1ed71cf1..173c8194 100644
--- a/fence/agents/sanbox2/fence_sanbox2.py
+++ b/fence/agents/sanbox2/fence_sanbox2.py
@@ -1,161 +1,153 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Version Firmware
## +-----------------+---------------------------+
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New Sanbox2 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
def get_power_status(conn, options):
status_trans = {
'online' : "on",
'offline' : "off"
}
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")
conn.send_eol("exit")
conn.close()
except:
pass
fail(EC_TIMED_OUT)
status = re.compile(".*AdminState\s+(online|offline)\s+", re.IGNORECASE | re.MULTILINE).search(conn.before).group(1)
try:
return status_trans[status.lower().strip()]
except KeyError:
return "PROBLEM"
def set_power_status(conn, options):
action = {
'on' : "online",
'off' : "offline"
}[options["-o"]]
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")
conn.send_eol("exit")
conn.close()
except:
pass
fail(EC_TIMED_OUT)
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")
conn.send_eol("exit")
conn.close()
except:
pass
fail(EC_TIMED_OUT)
def get_list_devices(conn, options):
outlets = { }
try:
conn.send_eol("show port")
conn.log_expect(options, options["-c"], int(options["-Y"]))
list_re = re.compile("^\s+(\d+?)\s+(Online|Offline)\s+", re.IGNORECASE)
for line in conn.before.splitlines():
if (list_re.search(line)):
status = {
'online' : "ON",
'offline' : "OFF"
}[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")
conn.send_eol("exit")
conn.close()
except:
pass
fail(EC_TIMED_OUT)
return outlets
def main():
device_opt = [ "fabric_fencing", "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "port", "ipport", "separator" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = [ " #> " ]
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for QLogic SANBox2 FC switches"
docs["longdesc"] = "fence_sanbox2 is an I/O Fencing agent which can be used with \
QLogic SANBox2 FC switches. It logs into a SANBox2 switch via telnet and disables a specified \
port. Disabling the port which a machine is connected to effectively fences that machine. \
Lengthy telnet connections to the switch should be avoided while a GFS cluster is running \
because the connection will block any necessary fencing actions."
docs["vendorurl"] = "http://www.qlogic.com"
show_docs(options, docs)
##
## Operate the fencing device
##
conn = fence_login(options)
conn.send_eol("admin start")
conn.log_expect(options, options["-c"], int(options["-Y"]))
if (re.search("\(admin\)", conn.before, re.MULTILINE) == None):
## Someone else is in admin section, we can't enable/disable
## ports so we will rather exit
sys.stderr.write("Failed: Unable to switch to admin section\n")
sys.exit(EC_GENERIC_ERROR)
result = fence_action(conn, options, set_power_status, get_power_status, get_list_devices)
##
## Logout from system
######
try:
conn.send_eol("admin end")
conn.send_eol("exit\n")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index cb33a561..c8c49a43 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -1,113 +1,101 @@
#!/usr/bin/python
# The Following Agent Has Been Tested On:
#
# Virsh 0.3.3 on RHEL 5.2 with xen-3.0.3-51
#
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="Virsh fence agent"
REDHAT_COPYRIGHT=""
BUILD_DATE=""
#END_VERSION_GENERATION
def get_outlets_status(conn, options):
if options.has_key("-d"):
prefix = SUDO_PATH + " "
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 = {}
#This is status of mini finite automata. 0 = we didn't found Id and Name, 1 = we did
fa_status = 0
for line in conn.before.splitlines():
domain = re.search("^\s*(\S+)\s+(\S+)\s+(\S+).*$", line)
if (domain!=None):
if ((fa_status==0) and (domain.group(1).lower()=="id") and (domain.group(2).lower()=="name")):
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"))
return result
def get_power_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]
def set_power_status(conn, options):
if options.has_key("-d"):
prefix = SUDO_PATH + " "
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",
"secure", "identity_file", "test", "port", "separator",
"inet4_only", "inet6_only", "ipport", "sudo" ]
atexit.register(atexit_handler)
all_opt["secure"]["default"] = "1"
all_opt["cmd_prompt"]["default"] = [ "\[EXPECT\]#\ " ]
options = check_input(device_opt, process_input(device_opt))
options["ssh_options"] = "-t '/bin/bash -c \"PS1=\[EXPECT\]#\ /bin/bash --noprofile --norc\"'"
docs = { }
docs["shortdesc"] = "Fence agent for virsh"
docs["longdesc"] = "fence_virsh is an I/O Fencing agent \
which can be used with the virtual machines managed by libvirt. \
It logs via ssh to a dom0 and there run virsh command, which does \
all work. \
\n.P\n\
By default, virsh needs root account to do properly work. So you \
must allow ssh login in your sshd_config."
show_docs(options, docs)
## Operate the fencing device
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_outlets_status)
## Logout from system
try:
conn.sendline("quit")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index b1fdd051..2337e105 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -1,173 +1,162 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Version Firmware
## +-----------------+---------------------------+
## WTI RSM-8R4 ?? unable to find out ??
## WTI MPC-??? ?? unable to find out ??
## WTI IPS-800-CE v1.40h (no username) ('list' tested)
#####
import sys, re, pexpect, exceptions
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New WTI Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2008"
#END_VERSION_GENERATION
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
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("|")]
if len(plug_line) < len(plug_header):
plug_section = -1
if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]:
return plug_line[status_index]
else:
## We already believe that first column contains plug number
if len(plug_line[0]) != 0:
outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
elif (plug_section == 1):
plug_section = 2
elif (line.upper().startswith("PLUG")):
plug_section = 1
plug_header = [x.strip().lower() for x in line.split("|")]
plug_index = plug_header.index("plug")
name_index = plug_header.index("name")
status_index = plug_header.index("status")
if ["list", "monitor"].count(options["-o"]) == 1:
return outlets
else:
return "PROBLEM"
def set_power_status(conn, options):
action = {
'on' : "/on",
'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",
"cmd_prompt", "secure", "identity_file", "port", "no_login", "no_password",
"test", "separator", "inet4_only", "inet6_only", "ipport" ]
atexit.register(atexit_handler)
all_opt["cmd_prompt"]["default"] = [ "RSM>", "MPC>", "IPS>", "TPS>", "NBB>", "NPS>", "VMR>" ]
options = check_input(device_opt, process_input(device_opt))
docs = { }
docs["shortdesc"] = "Fence agent for WTI"
docs["longdesc"] = "fence_wti is an I/O Fencing agent \
which can be used with the WTI Network Power Switch (NPS). It logs \
into an NPS via telnet or ssh and boots a specified plug. \
Lengthy telnet connections to the NPS should be avoided while a GFS cluster \
is running because the connection will block any necessary fencing actions."
docs["vendorurl"] = "http://www.wti.com"
show_docs(options, docs)
##
## Operate the fencing device
##
## @note: if it possible that this device does not need either login, password or both of them
#####
if 0 == options.has_key("-x"):
try:
try:
conn = fspawn(options, TELNET_PATH)
conn.send("set binary\n")
conn.send("open %s -%s\n"%(options["-a"], options["-u"]))
except pexpect.ExceptionPexpect, ex:
sys.stderr.write(str(ex) + "\n")
sys.stderr.write("Due to limitations, binary dependencies on fence agents "
"are not in the spec file and must be installed separately." + "\n")
sys.exit(EC_GENERIC_ERROR)
re_login = re.compile("(login: )|(Login Name: )|(username: )|(User Name :)", re.IGNORECASE)
re_prompt = re.compile("|".join(map (lambda x: "(" + x + ")", options["-c"])), re.IGNORECASE)
result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"]))
if result == 0:
if options.has_key("-l"):
conn.send(options["-l"]+"\r\n")
result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], int(options["-Y"]))
else:
fail_usage("Failed: You have to set login name")
if result == 1:
if options.has_key("-p"):
conn.send(options["-p"]+"\r\n")
conn.log_expect(options, options["-c"], int(options["-Y"]))
else:
fail_usage("Failed: You have to enter password or password script")
except pexpect.EOF:
fail(EC_LOGIN_DENIED)
except pexpect.TIMEOUT:
fail(EC_LOGIN_DENIED)
else:
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
##
## Logout from system
######
try:
conn.send("/X"+"\r\n")
conn.close()
except exceptions.OSError:
pass
except pexpect.ExceptionPexpect:
pass
sys.exit(result)
if __name__ == "__main__":
main()

File Metadata

Mime Type
text/x-diff
Expires
Mon, Feb 24, 7:25 PM (5 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1464417
Default Alt Text
(111 KB)

Event Timeline