From: Matt Clark <[email protected]>

Added all_opt parameters to aid in the fencing of virtual machines. 
Specifically this is for the fencing of machines through the XenAPI (Citrix 
XenServer or Xen Cloud Platform). New parameters are session_url, vm_name and 
uuid.

Updated logic to now check if either an IP address (-a) or a session URL (-s) 
is set.

Added a section to ensure that either a vm_name or uuid is specified. Because 
you can specify either, the "required" field in all_opt array can't be used and 
a separate explicit check is required.
---
 fence/agents/lib/fencing.py.py |   31 ++++++++++++++++++++++++++++---
 1 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 4e5eb18..0ea2979 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -378,7 +378,28 @@ all_opt = {
                "default" : "1",
                "required" : "0",
                "shortdesc" : "Count of attempts to retry power on",
-               "order" : 201 }
+               "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},
+        "vm_name" : {
+                "getopt" : "n:",
+                "longopt" : "vm-name",
+                "help" : "-n, --vm-name                  Name of the VM to 
fence.",
+                "required" : "0",
+                "shortdesc" : "The name of the virual machine to fence.",
+                "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}
 }
 
 common_opt = [ "retry_on", "delay" ]
@@ -661,7 +682,7 @@ def check_input(device_opt, opt):
        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"):
+       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):
@@ -682,6 +703,10 @@ def check_input(device_opt, opt):
        if (0 == ["list", "monitor"].count(options["-o"].lower())) and (0 == 
options.has_key("-n")) and (device_opt.count("port")):
                fail_usage("Failed: You have to enter plug number")
 
+       if (0 == ["list", "monitor"].count(options["-o"].lower())) and 
device_opt.count("vm_name") and device_opt.count("uuid"):
+               if 0 == options.has_key("-n") and 0 == options.has_key("-U"):
+                       fail_usage("Failed: You must specify either UUID or VM 
name")
+
        if options.has_key("-S"):
                options["-p"] = os.popen(options["-S"]).read().rstrip()
 
@@ -745,7 +770,7 @@ def fence_action(tn, options, set_power_fn, get_power_fn, 
get_outlet_list = None
        
        ## Process options that manipulate fencing device
        #####
-       if (options["-o"] == "list") and (0 == 
options["device_opt"].count("port")) and (0 == 
options["device_opt"].count("partition")):
+       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")):
                print "N/A"
                return
        elif (options["-o"] == "list" and get_outlet_list == None):
-- 
1.7.0.4

Reply via email to