Commit 4a265c08 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Re-introduce constants for most often used arguments


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4f3d5b76
......@@ -54,6 +54,8 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"GetOnlineNodes", "JobExecutor", "SYNC_OPT", "CONFIRM_OPT",
"ArgJobId", "ArgSuggest", "ArgUnknown", "ArgFile", "ArgCommand",
"ArgInstance", "ArgNode", "ArgChoice",
"ARGS_NONE", "ARGS_ONE_INSTANCE", "ARGS_ONE_NODE",
"ARGS_MANY_INSTANCES", "ARGS_MANY_NODES",
]
NO_PREFIX = "no_"
......@@ -129,6 +131,13 @@ class ArgCommand(_Argument):
"""
ARGS_NONE = []
ARGS_MANY_INSTANCES = [ArgInstance()]
ARGS_MANY_NODES = [ArgNode()]
ARGS_ONE_INSTANCE = [ArgInstance(min=1, max=1)]
ARGS_ONE_NODE = [ArgNode(min=1, max=1)]
def _ExtractTagsObject(opts, args):
"""Extract the tag type object.
......
......@@ -261,14 +261,14 @@ import_opts = [
]
commands = {
'list': (PrintExportList, [],
'list': (PrintExportList, ARGS_NONE,
[DEBUG_OPT,
cli_option("--node", dest="nodes", default=[], action="append",
help="List only backups stored on this node"
" (can be used multiple times)"),
],
"", "Lists instance exports available in the ganeti cluster"),
'export': (ExportInstance, [ArgInstance(min=1, max=1)],
'export': (ExportInstance, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT,
cli_option("-n", "--node", dest="node", help="Target node",
metavar="<node>"),
......@@ -277,7 +277,7 @@ commands = {
help="Don't shutdown the instance (unsafe)"), ],
"-n <target_node> [opts...] <name>",
"Exports an instance to an image"),
'import': (ImportInstance, [ArgInstance(min=1, max=1)], import_opts,
'import': (ImportInstance, ARGS_ONE_INSTANCE, import_opts,
("[...] -t disk-type -n node[:secondary-node]"
" <name>"),
"Imports an instance from an exported image"),
......
......@@ -601,7 +601,7 @@ commands = {
],
"[opts...] <cluster_name>",
"Initialises a new cluster configuration"),
'destroy': (DestroyCluster, [],
'destroy': (DestroyCluster, ARGS_NONE,
[DEBUG_OPT,
cli_option("--yes-do-it", dest="yes_do_it",
help="Destroy cluster",
......@@ -612,31 +612,31 @@ commands = {
[DEBUG_OPT, FORCE_OPT],
"<new_name>",
"Renames the cluster"),
'redist-conf': (RedistributeConfig, [], [DEBUG_OPT, SUBMIT_OPT],
'redist-conf': (RedistributeConfig, ARGS_NONE, [DEBUG_OPT, SUBMIT_OPT],
"",
"Forces a push of the configuration file and ssconf files"
" to the nodes in the cluster"),
'verify': (VerifyCluster, [], [DEBUG_OPT,
'verify': (VerifyCluster, ARGS_NONE, [DEBUG_OPT,
cli_option("--no-nplus1-mem", dest="skip_nplusone_mem",
help="Skip N+1 memory redundancy tests",
action="store_true",
default=False,),
],
"", "Does a check on the cluster configuration"),
'verify-disks': (VerifyDisks, [], [DEBUG_OPT],
'verify-disks': (VerifyDisks, ARGS_NONE, [DEBUG_OPT],
"", "Does a check on the cluster disk status"),
'repair-disk-sizes': (RepairDiskSizes, [ArgInstance()], [DEBUG_OPT],
'repair-disk-sizes': (RepairDiskSizes, ARGS_MANY_INSTANCES, [DEBUG_OPT],
"", "Updates mismatches in recorded disk sizes"),
'masterfailover': (MasterFailover, [], [DEBUG_OPT,
'masterfailover': (MasterFailover, ARGS_NONE, [DEBUG_OPT,
cli_option("--no-voting", dest="no_voting",
help="Skip node agreement check (dangerous)",
action="store_true",
default=False,),
],
"", "Makes the current node the master"),
'version': (ShowClusterVersion, [], [DEBUG_OPT],
'version': (ShowClusterVersion, ARGS_NONE, [DEBUG_OPT],
"", "Shows the cluster version"),
'getmaster': (ShowClusterMaster, [], [DEBUG_OPT],
'getmaster': (ShowClusterMaster, ARGS_NONE, [DEBUG_OPT],
"", "Shows the cluster master"),
'copyfile': (ClusterCopyFile, [ArgFile(min=1, max=1)],
[DEBUG_OPT, node_option],
......@@ -645,9 +645,9 @@ commands = {
'command': (RunClusterCommand, [ArgCommand(min=1)], [DEBUG_OPT, node_option],
"[-n node...] <command>",
"Runs a command on all (or only some) nodes"),
'info': (ShowClusterConfig, [], [DEBUG_OPT],
'info': (ShowClusterConfig, ARGS_NONE, [DEBUG_OPT],
"", "Show cluster configuration"),
'list-tags': (ListTags, [],
'list-tags': (ListTags, ARGS_NONE,
[DEBUG_OPT], "", "List the tags of the cluster"),
'add-tags': (AddTags, [ArgUnknown()], [DEBUG_OPT, TAG_SRC_OPT],
"tag...", "Add tags to the cluster"),
......@@ -660,7 +660,7 @@ commands = {
[ArgChoice(min=1, max=1, choices=["drain", "undrain", "info"])],
[DEBUG_OPT],
"drain|undrain|info", "Change queue properties"),
'modify': (SetClusterParams, [],
'modify': (SetClusterParams, ARGS_NONE,
[DEBUG_OPT,
cli_option("-g", "--vg-name", dest="vg_name",
help="Specify the volume group name "
......
......@@ -142,7 +142,7 @@ commands = {
'submit-job': (GenericOpCodes, [ArgFile(min=1)], [DEBUG_OPT],
"<op_list_file...>", "Submits jobs built from json files"
" containing a list of serialized opcodes"),
'allocator': (TestAllocator, [ArgInstance(min=1, max=1)],
'allocator': (TestAllocator, ARGS_ONE_INSTANCE,
[DEBUG_OPT,
cli_option("--dir", dest="direction",
default="in", choices=["in", "out"],
......
......@@ -1425,14 +1425,14 @@ commands = {
[DEBUG_OPT],
"<instances_file.json>",
"Create a bunch of instances based on specs in the file."),
'console': (ConnectToInstanceConsole, [ArgInstance(min=1, max=1)],
'console': (ConnectToInstanceConsole, ARGS_ONE_INSTANCE,
[DEBUG_OPT,
cli_option("--show-cmd", dest="show_command",
action="store_true", default=False,
help=("Show command instead of executing it"))],
"[--show-cmd] <instance>",
"Opens a console on the specified instance"),
'failover': (FailoverInstance, [ArgInstance(min=1, max=1)],
'failover': (FailoverInstance, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT,
cli_option("--ignore-consistency", dest="ignore_consistency",
action="store_true", default=False,
......@@ -1443,7 +1443,7 @@ commands = {
"[-f] <instance>",
"Stops the instance and starts it on the backup node, using"
" the remote mirror (only for instances of type drbd)"),
'migrate': (MigrateInstance, [ArgInstance(min=1, max=1)],
'migrate': (MigrateInstance, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT,
cli_option("--non-live", dest="live",
default=True, action="store_false",
......@@ -1463,7 +1463,7 @@ commands = {
"[-f] <instance>",
"Migrate instance to its secondary node"
" (only for instances of type drbd)"),
'move': (MoveInstance, [ArgInstance(min=1, max=1)],
'move': (MoveInstance, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT, SUBMIT_OPT,
cli_option("-n", "--new-node", dest="target_node",
help="Destinattion node", metavar="NODE",
......@@ -1472,7 +1472,7 @@ commands = {
"[-f] <instance>",
"Move instance to an arbitrary node"
" (only for instances of type file and lv)"),
'info': (ShowInstanceConfig, [ArgInstance()],
'info': (ShowInstanceConfig, ARGS_MANY_INSTANCES,
[DEBUG_OPT,
cli_option("-s", "--static", dest="static",
action="store_true", default=False,
......@@ -1483,7 +1483,7 @@ commands = {
" This can take a long time to run, use wisely."),
], "[-s] {--all | <instance>...}",
"Show information on the specified instance(s)"),
'list': (ListInstances, [ArgInstance()],
'list': (ListInstances, ARGS_MANY_INSTANCES,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT],
"[<instance>...]",
"Lists the instances and their status. The available fields are"
......@@ -1506,7 +1506,7 @@ commands = {
SUBMIT_OPT,
],
"[-f] <instance>", "Reinstall a stopped instance"),
'remove': (RemoveInstance, [ArgInstance(min=1, max=1)],
'remove': (RemoveInstance, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT,
cli_option("--ignore-failures", dest="ignore_failures",
action="store_true", default=False,
......@@ -1526,7 +1526,7 @@ commands = {
SUBMIT_OPT,
],
"<instance> <new_name>", "Rename the instance"),
'replace-disks': (ReplaceDisks, [ArgInstance(min=1, max=1)],
'replace-disks': (ReplaceDisks, ARGS_ONE_INSTANCE,
[DEBUG_OPT,
cli_option("-n", "--new-secondary", dest="new_secondary",
help=("New secondary node (for secondary"
......@@ -1558,7 +1558,7 @@ commands = {
],
"[-s|-p|-n NODE|-I NAME] <instance>",
"Replaces all disks for the instance"),
'modify': (SetInstanceParams, [ArgInstance(min=1, max=1)],
'modify': (SetInstanceParams, ARGS_ONE_INSTANCE,
[DEBUG_OPT, FORCE_OPT,
cli_option("-H", "--hypervisor", type="keyval",
default={}, dest="hypervisor",
......@@ -1610,7 +1610,7 @@ commands = {
SUBMIT_OPT,
],
"<instance>", "Reboots an instance"),
'activate-disks': (ActivateDisks, [ArgInstance(min=1, max=1)],
'activate-disks': (ActivateDisks, ARGS_ONE_INSTANCE,
[DEBUG_OPT, SUBMIT_OPT,
cli_option("--ignore-size", dest="ignore_size",
default=False, action="store_true",
......@@ -1620,11 +1620,11 @@ commands = {
],
"<instance>",
"Activate an instance's disks"),
'deactivate-disks': (DeactivateDisks, [ArgInstance(min=1, max=1)],
'deactivate-disks': (DeactivateDisks, ARGS_ONE_INSTANCE,
[DEBUG_OPT, SUBMIT_OPT],
"<instance>",
"Deactivate an instance's disks"),
'recreate-disks': (RecreateDisks, [ArgInstance(min=1, max=1)],
'recreate-disks': (RecreateDisks, ARGS_ONE_INSTANCE,
[DEBUG_OPT, SUBMIT_OPT,
cli_option("--disks", dest="disks", default=None,
help="Comma-separated list of disks"
......@@ -1643,7 +1643,7 @@ commands = {
help="Don't wait for sync (DANGEROUS!)"),
],
"<instance> <disk> <size>", "Grow an instance's disk"),
'list-tags': (ListTags, [ArgInstance(min=1, max=1)], [DEBUG_OPT],
'list-tags': (ListTags, ARGS_ONE_INSTANCE, [DEBUG_OPT],
"<instance_name>", "List the tags of the given instance"),
'add-tags': (AddTags, [ArgInstance(min=1, max=1), ArgUnknown()],
[DEBUG_OPT, TAG_SRC_OPT],
......
......@@ -636,7 +636,7 @@ commands = {
],
"[-s ip] [--readd] [--no-ssh-key-check] <node_name>",
"Add a node to the cluster"),
'evacuate': (EvacuateNode, [ArgNode(min=1, max=1)],
'evacuate': (EvacuateNode, ARGS_ONE_NODE,
[DEBUG_OPT, FORCE_OPT,
cli_option("-n", "--new-secondary", dest="dst_node",
help="New secondary node", metavar="NODE",
......@@ -650,7 +650,7 @@ commands = {
"[-f] {-I <iallocator> | -n <dst>} <node>",
"Relocate the secondary instances from a node"
" to other nodes (only for instances with drbd disk template)"),
'failover': (FailoverNode, [ArgNode(min=1, max=1)],
'failover': (FailoverNode, ARGS_ONE_NODE,
[DEBUG_OPT, FORCE_OPT,
cli_option("--ignore-consistency", dest="ignore_consistency",
action="store_true", default=False,
......@@ -660,7 +660,7 @@ commands = {
"[-f] <node>",
"Stops the primary instances on a node and start them on their"
" secondary node (only for instances with drbd disk template)"),
'migrate': (MigrateNode, [ArgNode(min=1, max=1)],
'migrate': (MigrateNode, ARGS_ONE_NODE,
[DEBUG_OPT, FORCE_OPT,
cli_option("--non-live", dest="live",
default=True, action="store_false",
......@@ -672,16 +672,16 @@ commands = {
"[-f] <node>",
"Migrate all the primary instance on a node away from it"
" (only for instances of type drbd)"),
'info': (ShowNodeConfig, [ArgNode()], [DEBUG_OPT],
'info': (ShowNodeConfig, ARGS_MANY_NODES, [DEBUG_OPT],
"[<node_name>...]", "Show information about the node(s)"),
'list': (ListNodes, [ArgNode()],
'list': (ListNodes, ARGS_MANY_NODES,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT],
"[nodes...]",
"Lists the nodes in the cluster. The available fields"
" are (see the man page for details): %s"
" The default field list is (in order): %s." %
(", ".join(_LIST_HEADERS), ", ".join(_LIST_DEF_FIELDS))),
'modify': (SetNodeParams, [ArgNode(min=1, max=1)],
'modify': (SetNodeParams, ARGS_ONE_NODE,
[DEBUG_OPT, FORCE_OPT,
SUBMIT_OPT,
cli_option("-C", "--master-candidate", dest="master_candidate",
......@@ -696,15 +696,15 @@ commands = {
help="Set the drained flag on the node"),
],
"<node>", "Alters the parameters of a node"),
'powercycle': (PowercycleNode, [ArgNode(min=1, max=1)],
'powercycle': (PowercycleNode, ARGS_ONE_NODE,
[DEBUG_OPT, FORCE_OPT, CONFIRM_OPT],
"<node_name>", "Tries to forcefully powercycle a node"),
'remove': (RemoveNode, [ArgNode(min=1, max=1)], [DEBUG_OPT],
'remove': (RemoveNode, ARGS_ONE_NODE, [DEBUG_OPT],
"<node_name>", "Removes a node from the cluster"),
'volumes': (ListVolumes, [ArgNode()],
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
"[<node_name>...]", "List logical volumes on node(s)"),
'physical-volumes': (ListPhysicalVolumes, [ArgNode()],
'physical-volumes': (ListPhysicalVolumes, ARGS_MANY_NODES,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT,
FIELDS_OPT, _STORAGE_TYPE_OPT],
"[<node_name>...]",
......@@ -730,7 +730,7 @@ commands = {
[DEBUG_OPT],
"<node_name> <storage_type> <name>",
"Repairs a storage volume on a node"),
'list-tags': (ListTags, [ArgNode(min=1, max=1)], [DEBUG_OPT],
'list-tags': (ListTags, ARGS_ONE_NODE, [DEBUG_OPT],
"<node_name>", "List the tags of the given node"),
'add-tags': (AddTags, [ArgNode(min=1, max=1), ArgUnknown()],
[DEBUG_OPT, TAG_SRC_OPT],
......
......@@ -145,9 +145,9 @@ def DiagnoseOS(opts, args):
commands = {
'list': (ListOS, [], [DEBUG_OPT, NOHDR_OPT], "",
'list': (ListOS, ARGS_NONE, [DEBUG_OPT, NOHDR_OPT], "",
"Lists all valid OSes on the master"),
'diagnose': (DiagnoseOS, [], [DEBUG_OPT], "",
'diagnose': (DiagnoseOS, ARGS_NONE, [DEBUG_OPT], "",
"Diagnose all OSes"),
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment