From 14d640ebddfd211c6512b5aa29df112a5fa867a4 Mon Sep 17 00:00:00 2001 From: Marek 'marx' Grac Date: Wed, 5 Aug 2015 09:57:30 +0200 Subject: [PATCH 1/4] fencing: Add suport for list-status --- fence/agents/lib/fencing.py.py | 55 +++++++++++++++++------------- fence/agents/ovh/fence_ovh.py | 3 ++ tests/data/metadata/fence_alom.xml | 1 + tests/data/metadata/fence_amt.xml | 1 + tests/data/metadata/fence_apc.xml | 1 + tests/data/metadata/fence_apc_snmp.xml | 1 + tests/data/metadata/fence_bladecenter.xml | 1 + tests/data/metadata/fence_brocade.xml | 1 + tests/data/metadata/fence_cisco_mds.xml | 1 + tests/data/metadata/fence_cisco_ucs.xml | 1 + tests/data/metadata/fence_compute.xml | 1 + tests/data/metadata/fence_docker.xml | 1 + tests/data/metadata/fence_drac.xml | 1 + tests/data/metadata/fence_drac5.xml | 1 + tests/data/metadata/fence_dummy.xml | 1 + tests/data/metadata/fence_eaton_snmp.xml | 1 + tests/data/metadata/fence_emerson.xml | 1 + tests/data/metadata/fence_eps.xml | 1 + tests/data/metadata/fence_hds_cb.xml | 1 + tests/data/metadata/fence_hpblade.xml | 1 + tests/data/metadata/fence_ibmblade.xml | 1 + tests/data/metadata/fence_idrac.xml | 1 + tests/data/metadata/fence_ifmib.xml | 1 + tests/data/metadata/fence_ilo.xml | 1 + tests/data/metadata/fence_ilo2.xml | 1 + tests/data/metadata/fence_ilo3.xml | 1 + tests/data/metadata/fence_ilo3_ssh.xml | 1 + tests/data/metadata/fence_ilo4.xml | 1 + tests/data/metadata/fence_ilo4_ssh.xml | 1 + tests/data/metadata/fence_ilo_moonshot.xml | 1 + tests/data/metadata/fence_ilo_mp.xml | 1 + tests/data/metadata/fence_ilo_ssh.xml | 1 + tests/data/metadata/fence_imm.xml | 1 + tests/data/metadata/fence_intelmodular.xml | 1 + tests/data/metadata/fence_ipdu.xml | 1 + tests/data/metadata/fence_ipmilan.xml | 1 + tests/data/metadata/fence_ldom.xml | 1 + tests/data/metadata/fence_lpar.xml | 1 + tests/data/metadata/fence_mpath.xml | 1 + tests/data/metadata/fence_netio.xml | 1 + tests/data/metadata/fence_ovh.xml | 1 + tests/data/metadata/fence_pve.xml | 1 + tests/data/metadata/fence_raritan.xml | 1 + tests/data/metadata/fence_rhevm.xml | 1 + tests/data/metadata/fence_rsa.xml | 1 + tests/data/metadata/fence_rsb.xml | 1 + tests/data/metadata/fence_sanbox2.xml | 1 + tests/data/metadata/fence_scsi.xml | 1 + tests/data/metadata/fence_virsh.xml | 1 + tests/data/metadata/fence_vmware_soap.xml | 1 + tests/data/metadata/fence_wti.xml | 1 + tests/data/metadata/fence_xenapi.xml | 1 + tests/data/metadata/fence_zvmip.xml | 1 + 53 files changed, 85 insertions(+), 24 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 377c63f..89c3379 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -584,6 +584,7 @@ def metadata(avail_opt, options, docs): if avail_opt.count("no_status") == 0: print "\t" print "\t" + print "\t" print "\t" print "\t" print "" @@ -758,7 +759,7 @@ def check_input(device_opt, opt): ## add loggint to stderr logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stderr)) - acceptable_actions = ["on", "off", "status", "list", "monitor"] + acceptable_actions = ["on", "off", "status", "list", "list-status", "monitor"] if 1 == device_opt.count("fabric_fencing"): ## Compatibility layer ##### @@ -807,7 +808,7 @@ def check_input(device_opt, opt): if not os.path.isfile(options["--identity-file"]): fail_usage("Failed: Identity file " + options["--identity-file"] + " does not exist") - if (0 == ["list", "monitor"].count(options["--action"])) and \ + if (0 == ["list", "list-status", "monitor"].count(options["--action"])) and \ not options.has_key("--plug") and device_opt.count("port") and \ device_opt.count("no_port") == 0 and not device_opt.count("port_as_ip"): fail_usage("Failed: You have to enter plug number or machine identification") @@ -923,28 +924,34 @@ def fence_action(tn, options, set_power_fn, get_power_fn, get_outlet_list=None, ## Process options that manipulate fencing device ##### - if options["--action"] == "list" and 0 == options["device_opt"].count("port"): - print "N/A" - return - elif options["--action"] == "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["--action"] == "list") or \ - ((options["--action"] == "monitor") and 1 == options["device_opt"].count("port")): - options["--original-action"] = options["--action"] - options["--action"] = "list" - outlets = get_outlet_list(tn, options) - options["--action"] = options["--original-action"] - del options["--original-action"] - - ## keys can be numbers (port numbers) or strings (names of VM) - for outlet_id in outlets.keys(): - (alias, status) = outlets[outlet_id] - if options["--action"] != "monitor": - print outlet_id + options["--separator"] + alias + if options["--action"] in ["list", "list-status"] or \ + ((options["--action"] == "monitor") and 1 == options["device_opt"].count("port")): + + if 0 == options["device_opt"].count("port"): + print "N/A" + elif 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" + else: + options["--original-action"] = options["--action"] + options["--action"] = "list" + outlets = get_outlet_list(tn, options) + options["--action"] = options["--original-action"] + del options["--original-action"] + + ## keys can be numbers (port numbers) or strings (names of VM) + for outlet_id in outlets.keys(): + (alias, status) = outlets[outlet_id] + status = status.upper() + if not status in ["ON", "OFF"]: + status = "UNKNOWN" + + if options["--action"] == "list": + print outlet_id + options["--separator"] + alias + elif options["--action"] == "list-status": + print outlet_id + options["--separator"] + alias + options["--separator"] + status return status = get_multi_power_fn(tn, options, get_power_fn) diff --git a/fence/agents/ovh/fence_ovh.py b/fence/agents/ovh/fence_ovh.py index 14a0706..1fef7e3 100644 --- a/fence/agents/ovh/fence_ovh.py +++ b/fence/agents/ovh/fence_ovh.py @@ -97,6 +97,9 @@ Poweroff is simulated with a reboot into rescue-pro mode." if options["--action"] == "list": fail_usage("Action 'list' is not supported in this fence agent") + if options["--action"] == "list-status": + fail_usage("Action 'list-status' is not supported in this fence agent") + if options["--action"] != "monitor" and not options["--plug"].endswith(".ovh.net"): options["--plug"] += ".ovh.net" diff --git a/tests/data/metadata/fence_alom.xml b/tests/data/metadata/fence_alom.xml index 32e6630..dfbe431 100644 --- a/tests/data/metadata/fence_alom.xml +++ b/tests/data/metadata/fence_alom.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_amt.xml b/tests/data/metadata/fence_amt.xml index 8524180..17e38fc 100644 --- a/tests/data/metadata/fence_amt.xml +++ b/tests/data/metadata/fence_amt.xml @@ -134,6 +134,7 @@ + diff --git a/tests/data/metadata/fence_apc.xml b/tests/data/metadata/fence_apc.xml index 441de61..8233101 100644 --- a/tests/data/metadata/fence_apc.xml +++ b/tests/data/metadata/fence_apc.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_apc_snmp.xml b/tests/data/metadata/fence_apc_snmp.xml index 886f1b0..d433735 100644 --- a/tests/data/metadata/fence_apc_snmp.xml +++ b/tests/data/metadata/fence_apc_snmp.xml @@ -159,6 +159,7 @@ + diff --git a/tests/data/metadata/fence_bladecenter.xml b/tests/data/metadata/fence_bladecenter.xml index ec1b011..7058c18 100644 --- a/tests/data/metadata/fence_bladecenter.xml +++ b/tests/data/metadata/fence_bladecenter.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_brocade.xml b/tests/data/metadata/fence_brocade.xml index 5373d0e..6f69230 100644 --- a/tests/data/metadata/fence_brocade.xml +++ b/tests/data/metadata/fence_brocade.xml @@ -129,6 +129,7 @@ + diff --git a/tests/data/metadata/fence_cisco_mds.xml b/tests/data/metadata/fence_cisco_mds.xml index add75f3..df4aa61 100644 --- a/tests/data/metadata/fence_cisco_mds.xml +++ b/tests/data/metadata/fence_cisco_mds.xml @@ -158,6 +158,7 @@ + diff --git a/tests/data/metadata/fence_cisco_ucs.xml b/tests/data/metadata/fence_cisco_ucs.xml index 66fc576..9834f5a 100644 --- a/tests/data/metadata/fence_cisco_ucs.xml +++ b/tests/data/metadata/fence_cisco_ucs.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_compute.xml b/tests/data/metadata/fence_compute.xml index 2c488c5..846a861 100644 --- a/tests/data/metadata/fence_compute.xml +++ b/tests/data/metadata/fence_compute.xml @@ -120,6 +120,7 @@ + diff --git a/tests/data/metadata/fence_docker.xml b/tests/data/metadata/fence_docker.xml index d100b8c..2c2261a 100644 --- a/tests/data/metadata/fence_docker.xml +++ b/tests/data/metadata/fence_docker.xml @@ -133,6 +133,7 @@ + diff --git a/tests/data/metadata/fence_drac.xml b/tests/data/metadata/fence_drac.xml index d480669..37697f7 100644 --- a/tests/data/metadata/fence_drac.xml +++ b/tests/data/metadata/fence_drac.xml @@ -115,6 +115,7 @@ + diff --git a/tests/data/metadata/fence_drac5.xml b/tests/data/metadata/fence_drac5.xml index d96484c..c1a78aa 100644 --- a/tests/data/metadata/fence_drac5.xml +++ b/tests/data/metadata/fence_drac5.xml @@ -139,6 +139,7 @@ + diff --git a/tests/data/metadata/fence_dummy.xml b/tests/data/metadata/fence_dummy.xml index 9295544..eb31244 100644 --- a/tests/data/metadata/fence_dummy.xml +++ b/tests/data/metadata/fence_dummy.xml @@ -90,6 +90,7 @@ + diff --git a/tests/data/metadata/fence_eaton_snmp.xml b/tests/data/metadata/fence_eaton_snmp.xml index 1cf0436..7bbe054 100644 --- a/tests/data/metadata/fence_eaton_snmp.xml +++ b/tests/data/metadata/fence_eaton_snmp.xml @@ -159,6 +159,7 @@ + diff --git a/tests/data/metadata/fence_emerson.xml b/tests/data/metadata/fence_emerson.xml index 553fc37..b79186c 100644 --- a/tests/data/metadata/fence_emerson.xml +++ b/tests/data/metadata/fence_emerson.xml @@ -159,6 +159,7 @@ + diff --git a/tests/data/metadata/fence_eps.xml b/tests/data/metadata/fence_eps.xml index a64ce8e..fcf72b8 100644 --- a/tests/data/metadata/fence_eps.xml +++ b/tests/data/metadata/fence_eps.xml @@ -117,6 +117,7 @@ Agent basically works by connecting to hidden page and pass appropriate argument + diff --git a/tests/data/metadata/fence_hds_cb.xml b/tests/data/metadata/fence_hds_cb.xml index 8f5279a..3230916 100644 --- a/tests/data/metadata/fence_hds_cb.xml +++ b/tests/data/metadata/fence_hds_cb.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_hpblade.xml b/tests/data/metadata/fence_hpblade.xml index a8a2b3a..a9948c7 100644 --- a/tests/data/metadata/fence_hpblade.xml +++ b/tests/data/metadata/fence_hpblade.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_ibmblade.xml b/tests/data/metadata/fence_ibmblade.xml index 4731e5e..175df9b 100644 --- a/tests/data/metadata/fence_ibmblade.xml +++ b/tests/data/metadata/fence_ibmblade.xml @@ -159,6 +159,7 @@ + diff --git a/tests/data/metadata/fence_idrac.xml b/tests/data/metadata/fence_idrac.xml index 41ab729..b742161 100644 --- a/tests/data/metadata/fence_idrac.xml +++ b/tests/data/metadata/fence_idrac.xml @@ -161,6 +161,7 @@ + diff --git a/tests/data/metadata/fence_ifmib.xml b/tests/data/metadata/fence_ifmib.xml index 7faf2ab..49de1b3 100644 --- a/tests/data/metadata/fence_ifmib.xml +++ b/tests/data/metadata/fence_ifmib.xml @@ -160,6 +160,7 @@ It was written with managed ethernet switches in mind, in order to fence iSCSI S + diff --git a/tests/data/metadata/fence_ilo.xml b/tests/data/metadata/fence_ilo.xml index bcb3d15..891b7f1 100644 --- a/tests/data/metadata/fence_ilo.xml +++ b/tests/data/metadata/fence_ilo.xml @@ -141,6 +141,7 @@ + diff --git a/tests/data/metadata/fence_ilo2.xml b/tests/data/metadata/fence_ilo2.xml index 95bf32a..7ff697f 100644 --- a/tests/data/metadata/fence_ilo2.xml +++ b/tests/data/metadata/fence_ilo2.xml @@ -141,6 +141,7 @@ + diff --git a/tests/data/metadata/fence_ilo3.xml b/tests/data/metadata/fence_ilo3.xml index e09e5e1..05fd01c 100644 --- a/tests/data/metadata/fence_ilo3.xml +++ b/tests/data/metadata/fence_ilo3.xml @@ -161,6 +161,7 @@ + diff --git a/tests/data/metadata/fence_ilo3_ssh.xml b/tests/data/metadata/fence_ilo3_ssh.xml index 1bf85e7..ebdae65 100644 --- a/tests/data/metadata/fence_ilo3_ssh.xml +++ b/tests/data/metadata/fence_ilo3_ssh.xml @@ -140,6 +140,7 @@ + diff --git a/tests/data/metadata/fence_ilo4.xml b/tests/data/metadata/fence_ilo4.xml index 9450e56..4f29073 100644 --- a/tests/data/metadata/fence_ilo4.xml +++ b/tests/data/metadata/fence_ilo4.xml @@ -161,6 +161,7 @@ + diff --git a/tests/data/metadata/fence_ilo4_ssh.xml b/tests/data/metadata/fence_ilo4_ssh.xml index 3779ce7..197d627 100644 --- a/tests/data/metadata/fence_ilo4_ssh.xml +++ b/tests/data/metadata/fence_ilo4_ssh.xml @@ -140,6 +140,7 @@ + diff --git a/tests/data/metadata/fence_ilo_moonshot.xml b/tests/data/metadata/fence_ilo_moonshot.xml index d7f2bc9..41303e2 100644 --- a/tests/data/metadata/fence_ilo_moonshot.xml +++ b/tests/data/metadata/fence_ilo_moonshot.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_ilo_mp.xml b/tests/data/metadata/fence_ilo_mp.xml index 145fb36..d2396e9 100644 --- a/tests/data/metadata/fence_ilo_mp.xml +++ b/tests/data/metadata/fence_ilo_mp.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_ilo_ssh.xml b/tests/data/metadata/fence_ilo_ssh.xml index 6eb4ae4..1d79308 100644 --- a/tests/data/metadata/fence_ilo_ssh.xml +++ b/tests/data/metadata/fence_ilo_ssh.xml @@ -140,6 +140,7 @@ + diff --git a/tests/data/metadata/fence_imm.xml b/tests/data/metadata/fence_imm.xml index 2e7d65c..0302f84 100644 --- a/tests/data/metadata/fence_imm.xml +++ b/tests/data/metadata/fence_imm.xml @@ -161,6 +161,7 @@ + diff --git a/tests/data/metadata/fence_intelmodular.xml b/tests/data/metadata/fence_intelmodular.xml index 707b37a..9d33115 100644 --- a/tests/data/metadata/fence_intelmodular.xml +++ b/tests/data/metadata/fence_intelmodular.xml @@ -161,6 +161,7 @@ Note: Since firmware update version 2.7, SNMP v2 write support is removed, and r + diff --git a/tests/data/metadata/fence_ipdu.xml b/tests/data/metadata/fence_ipdu.xml index 66fa768..f656c1c 100644 --- a/tests/data/metadata/fence_ipdu.xml +++ b/tests/data/metadata/fence_ipdu.xml @@ -159,6 +159,7 @@ + diff --git a/tests/data/metadata/fence_ipmilan.xml b/tests/data/metadata/fence_ipmilan.xml index ae528de..4ed67eb 100644 --- a/tests/data/metadata/fence_ipmilan.xml +++ b/tests/data/metadata/fence_ipmilan.xml @@ -161,6 +161,7 @@ + diff --git a/tests/data/metadata/fence_ldom.xml b/tests/data/metadata/fence_ldom.xml index 082fd82..bab164a 100644 --- a/tests/data/metadata/fence_ldom.xml +++ b/tests/data/metadata/fence_ldom.xml @@ -132,6 +132,7 @@ Very useful parameter is -c (or cmd_prompt in stdin mode). This must be set to s + diff --git a/tests/data/metadata/fence_lpar.xml b/tests/data/metadata/fence_lpar.xml index 9b6d62d..8c82925 100644 --- a/tests/data/metadata/fence_lpar.xml +++ b/tests/data/metadata/fence_lpar.xml @@ -143,6 +143,7 @@ + diff --git a/tests/data/metadata/fence_mpath.xml b/tests/data/metadata/fence_mpath.xml index ccd41ff..d3de9d5 100644 --- a/tests/data/metadata/fence_mpath.xml +++ b/tests/data/metadata/fence_mpath.xml @@ -100,6 +100,7 @@ The fence_mpath agent works by having an unique key for each pair of node and de + diff --git a/tests/data/metadata/fence_netio.xml b/tests/data/metadata/fence_netio.xml index f47238c..94db07e 100644 --- a/tests/data/metadata/fence_netio.xml +++ b/tests/data/metadata/fence_netio.xml @@ -110,6 +110,7 @@ + diff --git a/tests/data/metadata/fence_ovh.xml b/tests/data/metadata/fence_ovh.xml index 522da6c..bf7ebfe 100644 --- a/tests/data/metadata/fence_ovh.xml +++ b/tests/data/metadata/fence_ovh.xml @@ -94,6 +94,7 @@ + diff --git a/tests/data/metadata/fence_pve.xml b/tests/data/metadata/fence_pve.xml index 86c3cd7..99894e5 100644 --- a/tests/data/metadata/fence_pve.xml +++ b/tests/data/metadata/fence_pve.xml @@ -115,6 +115,7 @@ + diff --git a/tests/data/metadata/fence_raritan.xml b/tests/data/metadata/fence_raritan.xml index e970b99..d3a0d50 100644 --- a/tests/data/metadata/fence_raritan.xml +++ b/tests/data/metadata/fence_raritan.xml @@ -110,6 +110,7 @@ + diff --git a/tests/data/metadata/fence_rhevm.xml b/tests/data/metadata/fence_rhevm.xml index e0c9516..aa033eb 100644 --- a/tests/data/metadata/fence_rhevm.xml +++ b/tests/data/metadata/fence_rhevm.xml @@ -135,6 +135,7 @@ + diff --git a/tests/data/metadata/fence_rsa.xml b/tests/data/metadata/fence_rsa.xml index aa9caaa..3f3a336 100644 --- a/tests/data/metadata/fence_rsa.xml +++ b/tests/data/metadata/fence_rsa.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_rsb.xml b/tests/data/metadata/fence_rsb.xml index b400d7e..36b9cdb 100644 --- a/tests/data/metadata/fence_rsb.xml +++ b/tests/data/metadata/fence_rsb.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_sanbox2.xml b/tests/data/metadata/fence_sanbox2.xml index 06826b6..950c629 100644 --- a/tests/data/metadata/fence_sanbox2.xml +++ b/tests/data/metadata/fence_sanbox2.xml @@ -114,6 +114,7 @@ + diff --git a/tests/data/metadata/fence_scsi.xml b/tests/data/metadata/fence_scsi.xml index ba80e8c..d370e36 100644 --- a/tests/data/metadata/fence_scsi.xml +++ b/tests/data/metadata/fence_scsi.xml @@ -110,6 +110,7 @@ The fence_scsi agent works by having each node in the cluster register a unique + diff --git a/tests/data/metadata/fence_virsh.xml b/tests/data/metadata/fence_virsh.xml index 5febd77..3546a2c 100644 --- a/tests/data/metadata/fence_virsh.xml +++ b/tests/data/metadata/fence_virsh.xml @@ -137,6 +137,7 @@ By default, virsh needs root account to do properly work. So you must allow ssh + diff --git a/tests/data/metadata/fence_vmware_soap.xml b/tests/data/metadata/fence_vmware_soap.xml index 1308c85..fb54ef7 100644 --- a/tests/data/metadata/fence_vmware_soap.xml +++ b/tests/data/metadata/fence_vmware_soap.xml @@ -132,6 +132,7 @@ Name of virtual machine (-n / port) has to be used in inventory path format (e.g + diff --git a/tests/data/metadata/fence_wti.xml b/tests/data/metadata/fence_wti.xml index c7cb9d1..5f2566a 100644 --- a/tests/data/metadata/fence_wti.xml +++ b/tests/data/metadata/fence_wti.xml @@ -130,6 +130,7 @@ + diff --git a/tests/data/metadata/fence_xenapi.xml b/tests/data/metadata/fence_xenapi.xml index 0dd0a78..6040e85 100644 --- a/tests/data/metadata/fence_xenapi.xml +++ b/tests/data/metadata/fence_xenapi.xml @@ -95,6 +95,7 @@ + diff --git a/tests/data/metadata/fence_zvmip.xml b/tests/data/metadata/fence_zvmip.xml index 993dfb3..c688f42 100644 --- a/tests/data/metadata/fence_zvmip.xml +++ b/tests/data/metadata/fence_zvmip.xml @@ -137,6 +137,7 @@ Where XXXXXXX is the name of the virtual machine used in the authuser field of t + -- 1.9.3