Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > d236c5da97a239a1b6991cfba2865b66 > files > 43

cman-2.0.115-68.el5_6.1.src.rpm

commit 417822ca757ede38d6a7ce98029c4ec30fef9d46
Author: Marek 'marx' Grac <mgrac@redhat.com>
Date:   Fri Oct 9 14:19:16 2009 +0200

    fencing: Support for 'metadata' option for fencing agents / default values
    
    We need default values to work with timeout in systematic way
    
    Part of solution for bz#507514
    
    Fencing library now understand new 'metadata' action which shows
    available commands (for use on stdin). Output should be compatibile
    with stonith agents. Currently it is just partial (parameters only).
    We will extend it according to what we really needs. It should be
    possible to use these metadata for building UI. Device options now
    contains 'short description' and earlier option 'order' was added so we
    can set the correct orded (it will be same as in --help).
    
    Default values are now stored in fencing library as they are used for
    metadata generating. Fence agent can set their default settings to all_opt.
    
    There is a bit of redundancy ('required') because we will check it later.
    But I was not able to describe requirements without using not-naive schema.
    
    Taken from STABLE3 [77d987aa09c9e05905cb151540e32aee04b233b3]

diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py
index b870e4b..3cd1818 100644
--- a/fence/agents/lib/fencing.py.py
+++ b/fence/agents/lib/fencing.py.py
@@ -51,6 +51,8 @@ all_opt = {
 		"getopt" : "v",
 		"longopt" : "verbose",
 		"help" : "-v, --verbose                  Verbose mode",
+		"required" : "0",
+		"shortdesc" : "Verbose mode",
 		"order" : 51 },
 	"debug" : {
 		"getopt" : "D:",
@@ -65,6 +67,9 @@ all_opt = {
 		"getopt" : "o:",
 		"longopt" : "action",
 		"help" : "-o, --action=<action>          Action: status, reboot (default), off or on",
+		"required" : "1",
+		"shortdesc" : "Fencing Action",
+		"default" : "reboot",
 		"order" : 1 },
 	"io_fencing" : {
 		"getopt" : "o:",
@@ -78,6 +83,8 @@ all_opt = {
 		"getopt" : "a:",
 		"longopt" : "ip",
 		"help" : "-a, --ip=<ip>                  IP address or hostname of fencing device",
+		"required" : "1",
+		"shortdesc" : "IP Address or Hostname",
 		"order" : 1 },
 	"ipport" : {
 		"getopt" : "u:",
@@ -90,6 +97,8 @@ all_opt = {
 		"getopt" : "l:",
 		"longopt" : "username",
 		"help" : "-l, --username=<name>          Login name",
+		"required" : "?",
+		"shortdesc" : "Login Name",
 		"order" : 1 },
 	"no_login" : {
 		"getopt" : "",
@@ -103,16 +112,22 @@ all_opt = {
 		"getopt" : "p:",
 		"longopt" : "password",
 		"help" : "-p, --password=<password>      Login password or passphrase",
+		"required" : "0",
+		"shortdesc" : "Login password or passphrase",
 		"order" : 1 },
 	"passwd_script" : {
 		"getopt" : "S:",
 		"longopt" : "password-script=",
 		"help" : "-S, --password-script=<script> Script to run to retrieve password",
+		"required" : "0",
+		"shortdesc" : "Script to retrieve password",
 		"order" : 1 },
 	"identity_file" : {
 		"getopt" : "k:",
 		"longopt" : "identity-file",
 		"help" : "-k, --identity-file=<filename> Identity file (private key) for ssh ",
+		"required" : "0",
+		"shortdesc" : "Identity file for ssh",
 		"order" : 1 },
 	"module_name" : {
 		"getopt" : "m:",
@@ -148,30 +163,42 @@ all_opt = {
 		"getopt" : "x",
 		"longopt" : "ssh",
 		"help" : "-x, --ssh                      Use ssh connection",
+		"required" : "0",
+		"shortdesc" : "SSH connection",
 		"order" : 1 },
 	"ssl" : {
 		"getopt" : "z",
 		"longopt" : "ssl",
 		"help" : "-z, --ssl                      Use ssl connection",
+		"required" : "0",
+		"shortdesc" : "SSL connection",
 		"order" : 1 },
 	"port" : {
 		"getopt" : "n:",
 		"longopt" : "plug",
 		"help" : "-n, --plug=<id>                Physical plug number on device or\n" + 
         "                                        name of virtual machine",
+		"required" : "1",
+		"shortdesc" : "Physical plug number or name of virtual machine",
 		"order" : 1 },
 	"switch" : {
 		"getopt" : "s:",
 		"longopt" : "switch",
 		"help" : "-s, --switch=<id>              Physical switch number on device",
+		"required" : "0",
+		"shortdesc" : "Physical switch number on device",
 		"order" : 1 },
 	"partition" : {
 		"getopt" : "n:",
 		"help" : "-n <id>                        Name of the partition",
+		"required" : "0",
+		"shortdesc" : "Partition name",
 		"order" : 1 },
 	"managed" : {
 		"getopt" : "s:",
 		"help" : "-s <id>                        Name of the managed system",
+		"required" : "0",
+		"shortdesc" : "Managed system name",
 		"order" : 1 },
 	"test" : {
 		"getopt" : "T",
@@ -327,6 +354,29 @@ def usage(avail_opt):
 		if len(value["help"]) != 0:
 			print "   " + value["help"]
 
+def metadata(avail_opt):
+	global all_opt
+
+	sorted_list = [ (key, all_opt[key]) for key in avail_opt ]
+	sorted_list.sort(lambda x, y: cmp(x[1]["order"], y[1]["order"]))
+
+	print "<parameters>"
+	for option, value in sorted_list:
+		if all_opt[option].has_key("shortdesc"):
+			print "\t<parameter name=\"" + option + "\" unique=\"1\" required=\"" + all_opt[option]["required"] + "\">"
+
+			default = ""
+			if all_opt[option].has_key("default"):
+				default = "default=\""+all_opt[option]["default"]+"\""
+
+			if all_opt[option]["getopt"].count(":") > 0:
+				print "\t\t<content type=\"string\" "+default+" />"
+			else:
+				print "\t\t<content type=\"boolean\" "+default+" />"
+			print "\t\t<shortdesc lang=\"en\">" + all_opt[option]["shortdesc"] + "</shortdesc>"
+			print "\t</parameter>"
+	print "</parameters>"
+
 def process_input(avail_opt):
 	global all_opt
 
@@ -426,18 +476,43 @@ def process_input(avail_opt):
 ## password script to set a correct password
 ######
 def check_input(device_opt, opt):
+	global all_opt
+
 	options = dict(opt)
 	options["device_opt"] = device_opt
 
+	## Set requirements that should be included in metadata
+	#####
+	if device_opt.count("login") and device_opt.count("no_login") == 0:
+		all_opt["login"]["required"] = "1"
+	else:
+		all_opt["login"]["required"] = "0"
+
+	## Process special options (and exit)
+	#####
 	if options.has_key("-h"): 
 		usage(device_opt)
 		sys.exit(0)
 
+	if options.has_key("-o") and options["-o"].lower() == "metadata":
+		metadata(device_opt)
+		sys.exit(0)
+
 	if options.has_key("-V"):
 		print FENCE_RELEASE_NAME, BUILD_DATE
 		print REDHAT_COPYRIGHT
 		sys.exit(0)
 
+	## Set default values
+	#####
+	for opt in device_opt:
+		if all_opt[opt].has_key("default"):
+			getopt = "-" + all_opt[opt]["getopt"].rstrip(":")
+			if 0 == options.has_key(getopt):
+				options[getopt] = all_opt[opt]["default"]
+
+	options["-o"]=options["-o"].lower()
+
 	if options.has_key("-v"):
 		options["log"] = LOG_MODE_VERBOSE
 	else:
@@ -496,9 +571,6 @@ def check_input(device_opt, opt):
 	if options.has_key("-R"):
 		options["-P"] = os.popen(options["-R"]).read().rstrip()
 
-	if 0 == options.has_key("-C"):
-		options["-C"] = ","
-
 	## VMware
 	#######
 	if options.has_key("-B"):