public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: Jan Friesse <honzaf@fedoraproject.org> To: cluster-cvs-relay@redhat.com Subject: master - fence: Operation 'list' and 'monitor' for Alom, LDOM, VMware and ePowerSwitch Date: Mon, 27 Oct 2008 17:35:00 -0000 [thread overview] Message-ID: <20081027171632.C7D1E120214@lists.fedorahosted.org> (raw) Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=2d12836022d1a1de4889c842757af8e483a4bf96 Commit: 2d12836022d1a1de4889c842757af8e483a4bf96 Parent: 5ba707202381b5e2deb243bdbac39a0549e2ab86 Author: Jan Friesse <jfriesse@redhat.com> AuthorDate: Mon Oct 27 18:15:45 2008 +0100 Committer: Jan Friesse <jfriesse@redhat.com> CommitterDate: Mon Oct 27 18:15:45 2008 +0100 fence: Operation 'list' and 'monitor' for Alom, LDOM, VMware and ePowerSwitch None of this devices returns alias with list operation, because it doesn't make any sense (LDOM, VMware) or it isn't possible to get that information (ePowerSwitch). --- fence/agents/alom/fence_alom.py | 2 +- fence/agents/eps/fence_eps.py | 26 ++++++++------ fence/agents/ldom/fence_ldom.py | 34 +++++++++++++------ fence/agents/lib/fencing.py.py | 6 ++-- fence/agents/vmware/fence_vmware.py | 63 ++++++++++++++++++++++++++-------- 5 files changed, 90 insertions(+), 41 deletions(-) diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py index b1d8dcc..9f10650 100644 --- a/fence/agents/alom/fence_alom.py +++ b/fence/agents/alom/fence_alom.py @@ -59,7 +59,7 @@ def main(): # Operate the fencing device conn = fence_login(options) - fence_action(conn, options, set_power_status, get_power_status) + fence_action(conn, options, set_power_status, get_power_status,None) # Logout from system conn.sendline("logout") diff --git a/fence/agents/eps/fence_eps.py b/fence/agents/eps/fence_eps.py index f3b7f15..c56ffb8 100644 --- a/fence/agents/eps/fence_eps.py +++ b/fence/agents/eps/fence_eps.py @@ -66,17 +66,20 @@ def eps_run_command(options, params): return result def get_power_status(conn, options): - result = "" - ret_val=eps_run_command(options,"") - status=re.search("p"+options["-n"].lower()+"=(0|1)\s*\<br\>",ret_val.lower()) - if status==None: - fail_usage("Failed: You have to enter existing physical plug!") - - result=(status.group(1)=="1" and "on" or "off") + result={} + status=re.findall("p(\d{2})=(0|1)\s*\<br\>",ret_val.lower()) + for out_num,out_stat in status: + result[out_num]=("",(out_stat=="1" and "on" or "off")) - return result + if (options["-o"] == "status"): + if (not (options["-n"] in result)): + fail_usage("Failed: You have to enter existing physical plug!") + else: + return result[options["-n"]][1] + else: + return result def set_power_status(conn, options): ret_val=eps_run_command(options,"P%s=%s"%(options["-n"],(options["-o"]=="on" and "1" or "0"))) @@ -92,7 +95,8 @@ def eps_define_new_opts(): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "test", "port", "hidden_page", "no_login", "no_password" ] + "test", "port", "hidden_page", "no_login", "no_password", + "separator" ] eps_define_new_opts() @@ -101,8 +105,8 @@ def main(): if (not options.has_key("-c")): options["-c"]="hidden.htm" - #Run fence action. Conn is None, beacause we always need run new curl command - fence_action(None, options, set_power_status, get_power_status) + #Run fence action. Conn is None, beacause we always need open new http connection + fence_action(None, options, set_power_status, get_power_status,get_power_status) if __name__ == "__main__": main() diff --git a/fence/agents/ldom/fence_ldom.py b/fence/agents/ldom/fence_ldom.py index 8b2c210..78771c6 100644 --- a/fence/agents/ldom/fence_ldom.py +++ b/fence/agents/ldom/fence_ldom.py @@ -31,28 +31,39 @@ def start_communication(conn, options): def get_power_status(conn, options): - result = "" try: start_communication(conn,options) conn.sendline("ldm ls") conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) - #Status of logical domain. This can be None => LM not found or something else - ldom_exists = re.search(re.escape(options["-n"])+"\s+(\w+)",conn.before) - if (ldom_exists==None): - fail_usage("Failed: You have to enter existing logical domain!") - #Test status - status=re.search(".*bound",ldom_exists.group(1).lower()) - result=(status!=None and "off" or "on") + 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) - return result + if (options["-o"] == "status"): + 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: @@ -72,7 +83,8 @@ def set_power_status(conn, options): def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", - "secure", "identity_file", "test" , "port", "cmd_prompt" ] + "secure", "identity_file", "test" , "port", "cmd_prompt", + "separator" ] options = check_input(device_opt, process_input(device_opt)) @@ -89,7 +101,7 @@ def main(): ## Operate the fencing device #### conn = fence_login(options) - fence_action(conn, options, set_power_status, get_power_status) + fence_action(conn, options, set_power_status, get_power_status,get_power_status) ## ## Logout from system diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index c529b78..5743f50 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -345,12 +345,12 @@ def check_input(device_opt, opt): if (device_opt.count("vmlogin") and (not options.has_key("-L"))): fail_usage("Failed: You have to set login name for VMware ESX management console") - if (options.has_key("-L") and (not (options.has_key("-P") or options.has_key("-C")))): + if (options.has_key("-L") and (not (options.has_key("-P") or options.has_key("-B")))): fail_usage("Failed: You have to enter password or password script for VMware ESX management console") - if (options.has_key("-L") and (not (options.has_key("-n")))): + if (["list", "monitor"].count(options["-o"])==0 and (options.has_key("-L") and (not (options.has_key("-n"))))): fail_usage("Failed: You have to enter virtual machine name") - + return options def wait_power_status(tn, options, get_power_fn): diff --git a/fence/agents/vmware/fence_vmware.py b/fence/agents/vmware/fence_vmware.py index 887b3bb..fc5618f 100644 --- a/fence/agents/vmware/fence_vmware.py +++ b/fence/agents/vmware/fence_vmware.py @@ -26,23 +26,27 @@ def start_communication(conn, options): conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) # Prepare command line for vmware-cmd with parameters. -def prepare_cmdline(conn,options): - cmd_line=VMWARE_COMMAND+" -H "+options["-A"]+" -U "+options["-L"]+" -P "+options["-P"]+" '"+options["-n"]+"'" - if options.has_key("-A"): +def prepare_cmdline(conn,options,add_vm_name): + cmd_line=VMWARE_COMMAND+" -H '"+options["-A"]+"' -U '"+options["-L"]+"' -P '"+options["-P"]+"'" + if (add_vm_name): + cmd_line+=" '"+options["-n"]+"'" + + if options.has_key("-v"): cmd_line+=" -v" + return cmd_line def get_power_status(conn, options): result = "" try: start_communication(conn,options) - - cmd_line=prepare_cmdline(conn,options) - + + cmd_line=prepare_cmdline(conn,options,True) + cmd_line+=" getstate" - + conn.sendline(cmd_line) - + conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) status_err = re.search("vmcontrol\ error\ ([-+]?\d+)\:(.*)",conn.before.lower()) if (status_err!=None): @@ -59,18 +63,47 @@ def get_power_status(conn, options): return result +def get_outlet_list(conn,options): + result={} + + try: + start_communication(conn,options) + + cmd_line=prepare_cmdline(conn,options,False) + cmd_line+=" -l" + + conn.sendline(cmd_line) + + conn.log_expect(options,COMMAND_PROMPT_REG,SHELL_TIMEOUT) + status_err = re.search("vmcontrol\ error\ ([-+]?\d+)\:(.*)",conn.before.lower()) + if (status_err!=None): + fail_usage("VMware error "+status_err.group(1)+": "+status_err.group(2)) + + lines=conn.before.splitlines() + + for line in lines[(options.has_key("-v") and 3 or 1):-1]: + if (line!=""): + result[line]=("","") + + except pexpect.EOF: + fail(EC_CONNECTION_LOST) + except pexpect.TIMEOUT: + fail(EC_TIMED_OUT) + + return result + def set_power_status(conn, options): try: start_communication(conn,options) - cmd_line=prepare_cmdline(conn,options) - + cmd_line=prepare_cmdline(conn,options,True) + cmd_line+=" "+(options["-o"]=="on" and "start" or "stop hard") - + conn.sendline(cmd_line) - + conn.log_expect(options,COMMAND_PROMPT_REG,POWER_TIMEOUT) - + except pexpect.EOF: fail(EC_CONNECTION_LOST) except pexpect.TIMEOUT: @@ -80,7 +113,7 @@ def main(): device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug", "action", "ipaddr", "login", "passwd", "passwd_script", "secure", "identity_file", "test" , "vmipaddr", "vmlogin", - "vmpasswd", "port", "vmpasswd_script" ] + "vmpasswd", "port", "vmpasswd_script", "separator" ] options = check_input(device_opt, process_input(device_opt)) @@ -98,7 +131,7 @@ def main(): ## Operate the fencing device #### conn = fence_login(options) - fence_action(conn, options, set_power_status, get_power_status) + fence_action(conn, options, set_power_status, get_power_status, get_outlet_list) ## ## Logout from system
reply other threads:[~2008-10-27 17:35 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20081027171632.C7D1E120214@lists.fedorahosted.org \ --to=honzaf@fedoraproject.org \ --cc=cluster-cvs-relay@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).