diff --git a/lib/cli.py b/lib/cli.py index cf51a19a11b3118df84a11fb0496d08c3370a483..ab3a1d55ba205c2c19aaddf9db34b18ce228195f 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -44,7 +44,7 @@ from optparse import (OptionParser, make_option, TitledHelpFormatter, __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", "SubmitOpCode", "GetClient", - "cli_option", "ikv_option", "keyval_option", + "cli_option", "GenerateTable", "AskUser", "ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE", "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT", "SUBMIT_OPT", @@ -233,15 +233,6 @@ def check_unit(option, opt, value): raise OptionValueError("option %s: %s" % (opt, err)) -class CliOption(Option): - """Custom option class for optparse. - - """ - TYPES = Option.TYPES + ("unit",) - TYPE_CHECKER = copy.copy(Option.TYPE_CHECKER) - TYPE_CHECKER["unit"] = check_unit - - def _SplitKeyVal(opt, data): """Convert a KeyVal string into a dict. @@ -280,7 +271,10 @@ def _SplitKeyVal(opt, data): def check_ident_key_val(option, opt, value): - """Custom parser for the IdentKeyVal option type. + """Custom parser for ident:key=val,key=val options. + + This will store the parsed values as a tuple (ident, {key: val}). As such, + multiple uses of this option via action=append is possible. """ if ":" not in value: @@ -304,40 +298,32 @@ def check_ident_key_val(option, opt, value): return retval -class IdentKeyValOption(Option): - """Custom option class for ident:key=val,key=val options. - - This will store the parsed values as a tuple (ident, {key: val}). As - such, multiple uses of this option via action=append is possible. - - """ - TYPES = Option.TYPES + ("identkeyval",) - TYPE_CHECKER = copy.copy(Option.TYPE_CHECKER) - TYPE_CHECKER["identkeyval"] = check_ident_key_val - - def check_key_val(option, opt, value): - """Custom parser for the KeyVal option type. + """Custom parser class for key=val,key=val options. + + This will store the parsed values as a dict {key: val}. """ return _SplitKeyVal(opt, value) -class KeyValOption(Option): - """Custom option class for key=val,key=val options. - - This will store the parsed values as a dict {key: val}. +class CliOption(Option): + """Custom option class for optparse. """ - TYPES = Option.TYPES + ("keyval",) - TYPE_CHECKER = copy.copy(Option.TYPE_CHECKER) + TYPES = Option.TYPES + ( + "identkeyval", + "keyval", + "unit", + ) + TYPE_CHECKER = Option.TYPE_CHECKER.copy() + TYPE_CHECKER["identkeyval"] = check_ident_key_val TYPE_CHECKER["keyval"] = check_key_val + TYPE_CHECKER["unit"] = check_unit # optparse.py sets make_option, so we do it for our own option class, too cli_option = CliOption -ikv_option = IdentKeyValOption -keyval_option = KeyValOption def _ParseArgs(argv, commands, aliases): diff --git a/scripts/gnt-backup b/scripts/gnt-backup index 0e82914d58ffbc2718eb55ff95806d2c639ca173..e005d914758f88797df431434ce683e46f8319f8 100755 --- a/scripts/gnt-backup +++ b/scripts/gnt-backup @@ -214,13 +214,13 @@ import_opts = [ make_option("-n", "--node", dest="node", help="Target node and optional secondary node", metavar="<pnode>[:<snode>]"), - keyval_option("-B", "--backend", dest="beparams", - type="keyval", default={}, - help="Backend parameters"), + cli_option("-B", "--backend", dest="beparams", + type="keyval", default={}, + help="Backend parameters"), make_option("-t", "--disk-template", dest="disk_template", help="Custom disk setup (diskless, file, plain, drbd)", default=None, metavar="TEMPL"), - ikv_option("--disk", help="Disk information", + cli_option("--disk", help="Disk information", default=[], dest="disks", action="append", type="identkeyval"), @@ -228,7 +228,7 @@ import_opts = [ " single-disk configuration, when not using the --disk option," " in MiB unless a suffix is used", default=None, type="unit", metavar="<size>"), - ikv_option("--net", help="NIC information", + cli_option("--net", help="NIC information", default=[], dest="nics", action="append", type="identkeyval"), @@ -252,7 +252,7 @@ import_opts = [ metavar="<DIR>"), make_option("--file-driver", dest="file_driver", help="Driver to use" " for image files", default="loop", metavar="<DRIVER>"), - ikv_option("-H", "--hypervisor", dest="hypervisor", + cli_option("-H", "--hypervisor", dest="hypervisor", help="Hypervisor and hypervisor options, in the format" " hypervisor:option=value,option=value,...", default=None, type="identkeyval"), diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 0ac37fc5ad5dd55623ce330a8d31b6453c394b18..60f7a4a4dc2858be8fcc1c2996dd0dcd49c57b36 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -583,19 +583,19 @@ commands = { help="Comma-separated list of hypervisors", type="string", default=constants.DEFAULT_ENABLED_HYPERVISOR), - ikv_option("-H", "--hypervisor-parameters", dest="hvparams", + cli_option("-H", "--hypervisor-parameters", dest="hvparams", help="Hypervisor and hypervisor options, in the" " format" " hypervisor:option=value,option=value,...", default=[], action="append", type="identkeyval"), - keyval_option("-B", "--backend-parameters", dest="beparams", - type="keyval", default={}, - help="Backend parameters"), - keyval_option("-N", "--nic-parameters", dest="nicparams", - type="keyval", default={}, - help="NIC parameters"), + cli_option("-B", "--backend-parameters", dest="beparams", + type="keyval", default={}, + help="Backend parameters"), + cli_option("-N", "--nic-parameters", dest="nicparams", + type="keyval", default={}, + help="NIC parameters"), make_option("-C", "--candidate-pool-size", default=constants.MASTER_POOL_SIZE_DEFAULT, help="Set the candidate pool size", @@ -672,19 +672,19 @@ commands = { make_option("--enabled-hypervisors", dest="enabled_hypervisors", help="Comma-separated list of hypervisors", type="string", default=None), - ikv_option("-H", "--hypervisor-parameters", dest="hvparams", + cli_option("-H", "--hypervisor-parameters", dest="hvparams", help="Hypervisor and hypervisor options, in the" " format" " hypervisor:option=value,option=value,...", default=[], action="append", type="identkeyval"), - keyval_option("-B", "--backend-parameters", dest="beparams", - type="keyval", default={}, - help="Backend parameters"), - keyval_option("-N", "--nic-parameters", dest="nicparams", - type="keyval", default={}, - help="NIC parameters"), + cli_option("-B", "--backend-parameters", dest="beparams", + type="keyval", default={}, + help="Backend parameters"), + cli_option("-N", "--nic-parameters", dest="nicparams", + type="keyval", default={}, + help="NIC parameters"), make_option("-C", "--candidate-pool-size", default=None, help="Set the candidate pool size", dest="candidate_pool_size", type="int"), diff --git a/scripts/gnt-instance b/scripts/gnt-instance index aeb6189228c0ba42cc77e7f6122f160ea3e05cfa..a0ae7c011b988c656c7ce139f40df14a7d449b6d 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -1345,9 +1345,9 @@ add_opts = [ help="Target node and optional secondary node", metavar="<pnode>[:<snode>]"), os_opt, - keyval_option("-B", "--backend", dest="beparams", - type="keyval", default={}, - help="Backend parameters"), + cli_option("-B", "--backend", dest="beparams", + type="keyval", default={}, + help="Backend parameters"), make_option("-t", "--disk-template", dest="disk_template", help="Custom disk setup (diskless, file, plain or drbd)", default=None, metavar="TEMPL"), @@ -1355,11 +1355,11 @@ add_opts = [ " single-disk configuration, when not using the --disk option," " in MiB unless a suffix is used", default=None, type="unit", metavar="<size>"), - ikv_option("--disk", help="Disk information", + cli_option("--disk", help="Disk information", default=[], dest="disks", action="append", type="identkeyval"), - ikv_option("--net", help="NIC information", + cli_option("--net", help="NIC information", default=[], dest="nics", action="append", type="identkeyval"), @@ -1382,7 +1382,7 @@ add_opts = [ make_option("-I", "--iallocator", metavar="<NAME>", help="Select nodes for the instance automatically using the" " <NAME> iallocator plugin", default=None, type="string"), - ikv_option("-H", "--hypervisor", dest="hypervisor", + cli_option("-H", "--hypervisor", dest="hypervisor", help="Hypervisor and hypervisor options, in the format" " hypervisor:option=value,option=value,...", default=None, type="identkeyval"), @@ -1522,17 +1522,17 @@ commands = { "Replaces all disks for the instance"), 'modify': (SetInstanceParams, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, - keyval_option("-H", "--hypervisor", type="keyval", - default={}, dest="hypervisor", - help="Change hypervisor parameters"), - keyval_option("-B", "--backend", type="keyval", - default={}, dest="beparams", - help="Change backend parameters"), - ikv_option("--disk", help="Disk changes", + cli_option("-H", "--hypervisor", type="keyval", + default={}, dest="hypervisor", + help="Change hypervisor parameters"), + cli_option("-B", "--backend", type="keyval", + default={}, dest="beparams", + help="Change backend parameters"), + cli_option("--disk", help="Disk changes", default=[], dest="disks", action="append", type="identkeyval"), - ikv_option("--net", help="NIC changes", + cli_option("--net", help="NIC changes", default=[], dest="nics", action="append", type="identkeyval"), @@ -1550,12 +1550,12 @@ commands = { m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, SUBMIT_OPT, - keyval_option("-H", "--hypervisor", type="keyval", - default={}, dest="hvparams", - help="Temporary hypervisor parameters"), - keyval_option("-B", "--backend", type="keyval", - default={}, dest="beparams", - help="Temporary backend parameters"), + cli_option("-H", "--hypervisor", type="keyval", + default={}, dest="hvparams", + help="Temporary hypervisor parameters"), + cli_option("-B", "--backend", type="keyval", + default={}, dest="beparams", + help="Temporary backend parameters"), ], "<instance>", "Starts an instance"),