[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [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(-)

diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index aa432c2..2c067a7 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -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():
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index 0ef0934..a19ae20 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -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):
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 6d2c649..1d7e09c 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -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
 	####
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]