Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py
index e1632cc9..0ad5082c 100644
--- a/fence/agents/alom/fence_alom.py
+++ b/fence/agents/alom/fence_alom.py
@@ -1,71 +1,76 @@
#!/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
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.sendline("showplatform")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
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)
return result
def set_power_status(conn, options):
try:
cmd_line=(options["-o"]=="on" and "poweron" or "poweroff -f -y")
conn.sendline(cmd_line)
conn.log_expect(options, options["-c"],POWER_TIMEOUT)
#Get the machine some time between poweron and poweroff
time.sleep(POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "test", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
# Default command is sc>
if (not options.has_key("-c")):
options["-c"] = "sc\>\ "
# Default to ssh
options["-x"] = 1
options["telnet_over_ssh"] = 1
# Operate the fencing device
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status,None)
# Logout from system
- conn.sendline("logout")
- conn.close()
+ try:
+ conn.sendline("logout")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index f8882a0d..ae0f37a0 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -1,119 +1,124 @@
#!/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
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("env -T system:blade[" + options["-n"] + "]\r\n")
i = conn.log_expect(options, [ node_cmd, "system>" ] , SHELL_TIMEOUT)
if i == 1:
## Given blade number does not exist
fail(EC_STATUS)
conn.send("power -state\r\n")
conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
status = conn.before.splitlines()[-1]
conn.send("env -T system\r\n")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
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' : "powerup",
'off': "powerdown"
}[options["-o"]]
try:
node_cmd = "system:blade\[" + options["-n"] + "\]>"
conn.send("env -T system:blade[" + options["-n"] + "]\r\n")
conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
conn.send("power -"+options["-o"]+"\r\n")
conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
conn.send("env -T system\r\n")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def get_blades_list(conn, options):
outlets = { }
try:
node_cmd = "system>"
conn.send("env -T system\r\n")
conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
conn.send("list -l 2\r\n")
conn.log_expect(options, node_cmd, SHELL_TIMEOUT)
lines = conn.before.split("\r\n")
filter_re = re.compile("^\s*blade\[(\d+)\]\s+(.*?)\s*$")
for x in lines:
res = filter_re.search(x)
if res != None:
outlets[res.group(1)] = (res.group(2), "")
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
return outlets
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "port", "identity_file", "separator",
"inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if 0 == options.has_key("-c"):
options["-c"] = "system>"
##
## Operate the fencing device
######
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
##
## Logout from system
######
- conn.send("exit\r\n")
- conn.close()
+ try:
+ conn.send("exit\r\n")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/drac/fence_drac5.py b/fence/agents/drac/fence_drac5.py
index bffd4f2a..ef105d51 100755
--- a/fence/agents/drac/fence_drac5.py
+++ b/fence/agents/drac/fence_drac5.py
@@ -1,124 +1,129 @@
#!/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
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.sendline("racadm serveraction powerstatus -m " + options["-m"])
elif options["model"] == "DRAC 5":
conn.sendline("racadm serveraction powerstatus")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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.sendline("racadm serveraction " + action + " -m " + options["-m"])
elif options["model"] == "DRAC 5":
conn.sendline("racadm serveraction " + action)
conn.log_expect(options, options["-c"], POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def get_list_devices(conn, options):
outlets = { }
try:
if options["model"] == "DRAC CMC":
conn.sendline("getmodinfo")
list_re = re.compile("^([^\s]*?)\s+Present\s*(ON|OFF)\s*.*$")
for line in conn.before.splitlines():
if (list_re.search(line)):
outlets[list_re.search(line).group(1)] = ("", list_re.search(line).group(2))
conn.log_expect(options, options["-c"], POWER_TIMEOUT)
elif options["model"] == "DRAC 5":
## DRAC 5 can be used only for one computer
pass
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
return outlets
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "drac_version", "module_name",
"separator", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if 0 == options.has_key("-c"):
options["-c"] = "\$"
##
## 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(option["-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"
fence_action(conn, options, set_power_status, get_power_status, get_list_devices)
##
## Logout from system
######
- conn.sendline("exit")
- conn.close()
+ try:
+ conn.sendline("exit")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py
index 683e54fd..4839faa2 100644
--- a/fence/agents/ldom/fence_ldom.py
+++ b/fence/agents/ldom/fence_ldom.py
@@ -1,114 +1,119 @@
#!/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
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.sendline ("PS1='"+COMMAND_PROMPT_NEW+"'")
res=conn.expect([pexpect.TIMEOUT, COMMAND_PROMPT_REG],SHELL_TIMEOUT)
if res==0:
#CSH stuff
conn.sendline("set prompt='"+COMMAND_PROMPT_NEW+"'")
conn.log_expect(options, COMMAND_PROMPT_REG,SHELL_TIMEOUT)
def get_power_status(conn, options):
try:
start_communication(conn,options)
conn.sendline("ldm ls")
conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT)
result={}
#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"))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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)
cmd_line="ldm "+(options["-o"]=="on" and "start" or "stop -f")+" \""+options["-n"]+"\""
conn.sendline(cmd_line)
conn.log_expect(options,COMMAND_PROMPT_REG,POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "identity_file", "test" , "port", "cmd_prompt",
"separator", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if (not options.has_key("-c")):
options["-c"] = "\ $"
options["-x"] = 1
##
## Operate the fencing device
####
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status,get_power_status)
##
## Logout from system
######
- conn.sendline("logout")
- conn.close()
+ try:
+ conn.sendline("logout")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index c9c9fe7b..faba923f 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -1,172 +1,177 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
## Version
## +---------------------------------------------+
## Tested on HMC
##
#####
import sys, re, pexpect
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"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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"], POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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"], POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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"], POWER_TIMEOUT)
## 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")
lines = res.group(2).split("\n")
for x in lines:
outlets[x.rstrip()] = ("", "")
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
elif options["-H"] == "4":
try:
conn.send("lssyscfg -r lpar -m " + options["-s"] +
" -F name:state\n")
conn.log_expect(options, options["-c"], POWER_TIMEOUT)
## 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")
lines = res.group(1).split("\n")
for x in lines:
s = x.split(":")
outlets[s[0]] = ("", s[1])
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
return outlets
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "partition", "managed", "hmc_version", "cmd_prompt",
"separator", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if 0 == options.has_key("-c"):
options["-c"] = [ ":~>", "]\$", "\$ " ]
if 0 == options.has_key("-x"):
fail_usage("Failed: You have to use ssh connection (-x) to fence device")
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)
fence_action(conn, options, set_power_status, get_power_status, get_lpar_list)
##
## Logout from system
######
- conn.send("quit\r\n")
- conn.close()
+ try:
+ conn.send("quit\r\n")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index 8683e381..d6b3d384 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -1,71 +1,76 @@
#!/usr/bin/python
#####
##
## The Following Agent Has Been Tested On:
##
#####
import sys, re, pexpect
sys.path.append("@FENCEAGENTSLIBDIR@")
from fencing import *
#BEGIN_VERSION_GENERATION
RELEASE_VERSION="New RSA2 Agent - test release on steroids"
REDHAT_COPYRIGHT=""
BUILD_DATE="March, 2009"
#END_VERSION_GENERATION
def get_power_status(conn, options):
try:
conn.send("power state\r\n")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
status = re.compile("Power: (.*)", re.IGNORECASE).search(conn.before).group(1)
return status.lower().strip()
def set_power_status(conn, options):
try:
conn.send("power " + options["-o"] + "\r\n")
conn.log_expect(options, options["-c"], POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if 0 == options.has_key("-c"):
options["-c"] = ">"
# This device will not allow us to login even with LANG=C
options["ssh_options"] = "-F /dev/null"
##
## Operate the fencing device
######
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status, None)
##
## Logout from system
######
- conn.sendline("exit")
- conn.close()
+ try:
+ conn.sendline("exit")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index 3eeb4be2..bbb88ec0 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -1,89 +1,94 @@
#!/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
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):
try:
conn.sendline("virsh list --all")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
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"] 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):
try:
conn.sendline("virsh %s "%(options["-o"] == "on" and "start" or "destroy")+options["-n"])
conn.log_expect(options, options["-c"], POWER_TIMEOUT)
time.sleep(1)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"secure", "identity_file", "test", "port", "separator",
"inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
## Defaults for fence agent
if 0 == options.has_key("-c"):
options["-c"] = "\[EXPECT\]#\ "
options["-x"]=1
options["ssh_options"]="-t '/bin/bash -c \"PS1=\[EXPECT\]#\ /bin/bash --noprofile --norc\"'"
## Operate the fencing device
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status, get_outlets_status)
## Logout from system
- conn.sendline("quit")
- conn.close()
+ try:
+ conn.sendline("quit")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 7ef58685..98b1d496 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -1,126 +1,131 @@
#!/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
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):
try:
conn.send("/S"+"\r\n")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
plug_section = 0
outlets = {}
for line in conn.before.splitlines():
if (plug_section == 2) and line.find("|") >= 0:
plug_line = [x.strip().lower() for x in line.split("|")]
if len(plug_line) < len(plug_header):
plug_section = -1
pass
if ["list", "monitor"].count(options["-o"]) == 0 and options["-n"].lower() == plug_line[plug_index]:
return plug_line[status_index]
else:
## We already believe that first column contains plug number
outlets[plug_line[0]] = (plug_line[name_index], plug_line[status_index])
elif (plug_section == 1):
plug_section = 2
pass
elif (line.upper().startswith("PLUG")):
plug_section = 1
plug_header = [x.strip().lower() for x in line.split("|")]
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"], POWER_TIMEOUT)
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
def main():
device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
"action", "ipaddr", "login", "passwd", "passwd_script",
"cmd_prompt", "secure", "port", "no_login", "no_password",
"test", "separator", "inet4_only", "inet6_only" ]
atexit.register(atexit_handler)
options = check_input(device_opt, process_input(device_opt))
##
## Fence agent specific defaults
#####
if 0 == options.has_key("-c"):
options["-c"] = [ "RSM>", "MPC>", "IPS>", "TPS>", "NBB>", "NPS>" ]
##
## 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:
conn = fspawn ('telnet ' + options["-a"])
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 ], SHELL_TIMEOUT)
if result == 0:
conn.send(options["-l"]+"\r\n")
result = conn.log_expect(options, [ re_login, "Password: ", re_prompt ], SHELL_TIMEOUT)
if result == 1:
conn.send(options["-p"]+"\r\n")
conn.log_expect(options, options["-c"], SHELL_TIMEOUT)
except pexpect.EOF:
fail(EC_LOGIN_DENIED)
except pexpect.TIMEOUT:
fail(EC_LOGIN_DENIED)
else:
conn = fence_login(options)
fence_action(conn, options, set_power_status, get_power_status, get_power_status)
##
## Logout from system
######
- conn.send("/X"+"\r\n")
- conn.close()
+ try:
+ conn.send("/X"+"\r\n")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
if __name__ == "__main__":
main()

File Metadata

Mime Type
text/x-diff
Expires
Mon, Sep 1, 7:11 PM (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2280365
Default Alt Text
(26 KB)

Event Timeline