Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=f1662bf0e... Commit: f1662bf0e0508cae1a34b414580f0db896aa8162 Parent: a4c92e3dd9809a486f6231a96e0be7c45266231e Author: Marek 'marx' Grac mgrac@redhat.com AuthorDate: Wed Dec 3 19:53:01 2014 +0100 Committer: Marek 'marx' Grac mgrac@redhat.com CommitterDate: Thu Dec 4 23:00:09 2014 +0100
[refactor] function metadata(..)
--- fence/agents/lib/fencing.py.py | 38 ++++++++++-------------------------- fence/agents/netio/fence_netio.py | 7 +---- fence/agents/rsb/fence_rsb.py | 5 ++- 3 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index fc0b55c..83ce41a 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -516,9 +516,8 @@ def metadata(avail_opt, options, docs): print "<?xml version=\"1.0\" ?>" print "<resource-agent name="" + os.path.basename(sys.argv[0]) + \ "" shortdesc="" + docs["shortdesc"] + "" >" - if "symlink" in docs: - for (symlink, desc) in docs["symlink"]: - print "<symlink name="" + symlink + "" shortdesc="" + desc + ""/>" + for (symlink, desc) in docs.get("symlink", []): + print "<symlink name="" + symlink + "" shortdesc="" + desc + ""/>" print "<longdesc>" + docs["longdesc"] + "</longdesc>" if docs.has_key("vendorurl"): print "<vendor-url>" + docs["vendorurl"] + "</vendor-url>" @@ -530,30 +529,18 @@ def metadata(avail_opt, options, docs): default = "" if all_opt[option].has_key("default"): default = str(all_opt[option]["default"]) - elif options.has_key("--" + all_opt[option]["longopt"]) and all_opt[option]["getopt"].endswith(":"): - if options["--" + all_opt[option]["longopt"]]: - try: - default = options["--" + all_opt[option]["longopt"]] - except TypeError: - ## @todo/@note: Currently there is no clean way how to handle lists - ## we can create a string from it but we can't set it on command line - default = str(options["--" + all_opt[option]["longopt"]]) elif options.has_key("--" + all_opt[option]["longopt"]): default = "true"
if default: - default = default.replace("&", "&") - default = default.replace('"', """) - default = default.replace('<', "<") - default = default.replace('>', ">") - default = default.replace("'", "'") - default = "default="" + default + "" " + default = "default="" + _encode_html_entities(default) + "" "
mixed = all_opt[option]["help"] ## split it between option and help text res = re.compile(r"^(.*?--\S+)\s+", re.IGNORECASE | re.S).search(mixed) if None != res: mixed = res.group(1) + # @todo: replace with _encode_html_entities but update XML metadata in regression tests mixed = mixed.replace("<", "<").replace(">", ">") print "\t\t<getopt mixed="" + mixed + "" />"
@@ -571,14 +558,9 @@ def metadata(avail_opt, options, docs): print "\t</parameter>" print "</parameters>" print "<actions>" - if avail_opt.count("fabric_fencing") == 1: - ## do 'unfence' at the start - if avail_opt.count("on_target") == 1: - print "\t<action name="on" on_target="1" automatic="1"/>" - else: - print "\t<action name="on" automatic="1"/>" - else: - print "\t<action name="on" automatic="0"/>" + + on_target = ' on_target="1"' if avail_opt.count("on_target") else '' + print "\t<action name="on"%s automatic="%d"/>" % (on_target, avail_opt.count("fabric_fencing")) print "\t<action name="off" />"
if avail_opt.count("fabric_fencing") == 0: @@ -796,8 +778,6 @@ def show_docs(options, docs=None): docs["shortdesc"] = "Fence agent" docs["longdesc"] = ""
- ## Process special options (and exit) - ##### if options.has_key("--help"): usage(device_opt) sys.exit(0) @@ -1257,3 +1237,7 @@ def _validate_input(options): "for %s from the valid values: %s" % \ ("--" + all_opt[opt]["longopt"], str(all_opt[opt]["choices"])))
+ +def _encode_html_entities(text): + return text.replace("&", "&").replace('"', """).replace('<', "<"). \ + replace('>', ">").replace("'", "'") diff --git a/fence/agents/netio/fence_netio.py b/fence/agents/netio/fence_netio.py index 1a37206..7b67e15 100755 --- a/fence/agents/netio/fence_netio.py +++ b/fence/agents/netio/fence_netio.py @@ -57,12 +57,9 @@ def main():
atexit.register(atexit_handler)
- opt = process_input(device_opt) - - # set default port for telnet only - if not opt.has_key("--ipport"): - opt["--ipport"] = "1234" + all_opt["ipport"]["default"] = "1234"
+ opt = process_input(device_opt) opt["eol"] = "\r\n" options = check_input(device_opt, opt)
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py index 73941b6..2ee85fe 100755 --- a/fence/agents/rsb/fence_rsb.py +++ b/fence/agents/rsb/fence_rsb.py @@ -47,9 +47,10 @@ def main():
opt = process_input(device_opt)
- # set default port for telnet only if not opt.has_key("--ssh") and not opt.has_key("--ipport"): - opt["--ipport"] = "3172" + # set default value like it should be set as usually + all_opt["ipport"]["default"] = "3172" + opt["--ipport"] = all_opt["ipport"]["default"]
options = check_input(device_opt, opt)
cluster-commits@lists.fedorahosted.org