fencing: Add support for options which should be selected from a list of values
PATCH 1/2 fencing: Add support for options which should be selected from a list of values
Previously, we have supported only strings and booleans; this is first patch that adds support for entering constrains like select a proper SNMP version from [1, 2c, 3].
--- fence/agents/drac5/fence_drac5.py | 1 + fence/agents/lib/fencing.py.py | 20 +++++++++++++------- fence/agents/lpar/fence_lpar.py | 4 +--- 3 files changed, 15 insertions(+), 10 deletions(-)
fence/agents/drac5/fence_drac5.py +1 -0
@@ -96,6 +96,7 @@ def define_new_opts(): "help" : "-d, --drac-version=[version] Force DRAC version to use (DRAC 5, DRAC CMC, DRAC MC)", "required" : "0", "shortdesc" : "Force DRAC version to use (DRAC 5, DRAC CMC, DRAC MC)", + "choices" : [ "DRAC CMC", "DRAC MC", "DRAC 5" ], "order" : 1 } def main():
fence/agents/lib/fencing.py.py +13 -7
@@ -142,13 +142,6 @@ all_opt = { "required" : "0", "shortdesc" : "Identity file for ssh", "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 }, "cmd_prompt" : { "getopt" : "c:", "longopt" : "command-prompt",
@@ -219,6 +212,7 @@ all_opt = { "help" : "-d, --snmp-version=[version] Specifies SNMP version to use", "required" : "0", "shortdesc" : "Specifies SNMP version to use (1,2c,3)", + "choices" : [ "1", "2c", "3" ], "order" : 1 }, "community" : { "getopt" : "c:",
@@ -233,6 +227,7 @@ all_opt = { "help" : "-b, --snmp-auth-prot=[prot] Set authentication protocol (MD5|SHA)", "required" : "0", "shortdesc" : "Set authentication protocol (MD5|SHA)", + "choices" : [ "MD5" , "SHA" ], "order" : 1}, "snmp_sec_level" : { "getopt" : "E:",
@@ -241,6 +236,7 @@ all_opt = { " (noAuthNoPriv|authNoPriv|authPriv)", "required" : "0", "shortdesc" : "Set security level (noAuthNoPriv|authNoPriv|authPriv)", + "choices" : [ "noAuthNoPriv", "authNoPriv", "authPriv" ], "order" : 1}, "snmp_priv_prot" : { "getopt" : "B:",
@@ -248,6 +244,7 @@ all_opt = { "help" : "-B, --snmp-priv-prot=[prot] Set privacy protocol (DES|AES)", "required" : "0", "shortdesc" : "Set privacy protocol (DES|AES)", + "choices" : [ "DES", "AES" ], "order" : 1}, "snmp_priv_passwd" : { "getopt" : "P:",
@@ -721,6 +718,15 @@ def check_input(device_opt, opt): else: options["--ipport"] = 23 + for opt in device_opt: + if all_opt[opt].has_key("choices"): + long = "--" + all_opt[opt]["longopt"] + possible_values_upper = map (lambda y : y.upper(), all_opt[opt]["choices"]) + if options.has_key(long): + options[long] = options[long].upper() + if not options["--" + all_opt[opt]["longopt"]] in possible_values_upper: + fail_usage("Failed: You have to enter a valid choice for %s from the valid values: %s" % ("--" + all_opt[opt]["longopt"] , str(all_opt[opt]["choices"]))) + return options def wait_power_status(tn, options, get_power_fn):
fence/agents/lpar/fence_lpar.py +1 -3
@@ -114,6 +114,7 @@ def define_new_opts(): "required" : "0", "shortdesc" : "Force HMC version to use (3 or 4)", "default" : "4", + "choices" : [ "3", "4" ], "order" : 1 } def main():
@@ -139,9 +140,6 @@ def main(): if 0 == options.has_key("--managed"): fail_usage("Failed: You have to enter name of managed system") - if 1 == options.has_key("--hmc-version") and (options["--hmc-version"] != "3" and options["--hmc-version"] != "4"): - fail_usage("Failed: You have to enter valid version number: 3 or 4") - ## ## Operate the fencing device ####
Signature · 1 line
1.7.7.6
PATCH 2/2 fencing: Add information about option that have to be selected from list to XML metadata
--- fence/agents/lib/fencing.py.py | 7 ++++++- fence/agents/lib/metadata.rng | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-)
fence/agents/lib/fencing.py.py +6 -1
@@ -477,7 +477,12 @@ def metadata(avail_opt, options, docs): mixed = mixed.replace("<", "<").replace(">", ">") print "\t\t<getopt mixed=\"" + mixed + "\" />" - if all_opt[option]["getopt"].count(":") > 0: + if all_opt[option].has_key("choices"): + print "\t\t<content type=\"select\" "+default+" >" + for choice in all_opt[option]["choices"]: + print "\t\t\t<option value=\"%s\" />" % (choice) + print "\t\t</content>" + elif all_opt[option]["getopt"].count(":") > 0: print "\t\t<content type=\"string\" "+default+" />" else: print "\t\t<content type=\"boolean\" "+default+" />"
fence/agents/lib/metadata.rng +18 -6
@@ -24,12 +24,24 @@ <attribute name="mixed" /> </element> <element name="content"> - <attribute name="type"> - <choice> - <value>boolean</value> - <value>string</value> - </choice> - </attribute> + <choice> + <attribute name="type"> + <choice> + <value>boolean</value> + <value>string</value> + </choice> + </attribute> + <group> + <attribute name="type"> + <value>select</value> + </attribute> + <zeroOrMore> + <element name="option"> + <attribute name="value" /> + </element> + </zeroOrMore> + </group> + </choice> <optional> <attribute name="default"> <text /> </attribute> </optional>
Signature · 1 line
1.7.7.6