diff --git a/lib/cli.py b/lib/cli.py index 13c13801c88b536c819e72719cb89206f95601b8..87ca657180e9c0bc84138ad879e26b14e8766934 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -38,7 +38,7 @@ from ganeti import luxi from ganeti import ssconf from ganeti import rpc -from optparse import (OptionParser, make_option, TitledHelpFormatter, +from optparse import (OptionParser, TitledHelpFormatter, Option, OptionValueError) @@ -231,53 +231,6 @@ def RemoveTags(opts, args): SubmitOpCode(op) -DEBUG_OPT = make_option("-d", "--debug", default=False, - action="store_true", - help="Turn debugging on") - -NOHDR_OPT = make_option("--no-headers", default=False, - action="store_true", dest="no_headers", - help="Don't display column headers") - -SEP_OPT = make_option("--separator", default=None, - action="store", dest="separator", - help="Separator between output fields" - " (defaults to one space)") - -USEUNITS_OPT = make_option("--units", default=None, - dest="units", choices=('h', 'm', 'g', 't'), - help="Specify units for output (one of hmgt)") - -FIELDS_OPT = make_option("-o", "--output", dest="output", action="store", - type="string", help="Comma separated list of" - " output fields", - metavar="FIELDS") - -FORCE_OPT = make_option("-f", "--force", dest="force", action="store_true", - default=False, help="Force the operation") - -CONFIRM_OPT = make_option("--yes", dest="confirm", action="store_true", - default=False, help="Do not require confirmation") - -TAG_SRC_OPT = make_option("--from", dest="tags_source", - default=None, help="File with tag names") - -SUBMIT_OPT = make_option("--submit", dest="submit_only", - default=False, action="store_true", - help="Submit the job and return the job ID, but" - " don't wait for the job to finish") - -SYNC_OPT = make_option("--sync", dest="do_locking", - default=False, action="store_true", - help="Grab locks while doing the queries" - " in order to ensure more consistent results") - -_DRY_RUN_OPT = make_option("--dry-run", default=False, - action="store_true", - help="Do not execute the operation, just run the" - " check steps and verify it it could be executed") - - def check_unit(option, opt, value): """OptParsers custom converter for units. @@ -384,6 +337,53 @@ class CliOption(Option): cli_option = CliOption +DEBUG_OPT = cli_option("-d", "--debug", default=False, + action="store_true", + help="Turn debugging on") + +NOHDR_OPT = cli_option("--no-headers", default=False, + action="store_true", dest="no_headers", + help="Don't display column headers") + +SEP_OPT = cli_option("--separator", default=None, + action="store", dest="separator", + help=("Separator between output fields" + " (defaults to one space)")) + +USEUNITS_OPT = cli_option("--units", default=None, + dest="units", choices=('h', 'm', 'g', 't'), + help="Specify units for output (one of hmgt)") + +FIELDS_OPT = cli_option("-o", "--output", dest="output", action="store", + type="string", metavar="FIELDS", + help="Comma separated list of output fields") + +FORCE_OPT = cli_option("-f", "--force", dest="force", action="store_true", + default=False, help="Force the operation") + +CONFIRM_OPT = cli_option("--yes", dest="confirm", action="store_true", + default=False, help="Do not require confirmation") + +TAG_SRC_OPT = cli_option("--from", dest="tags_source", + default=None, help="File with tag names") + +SUBMIT_OPT = cli_option("--submit", dest="submit_only", + default=False, action="store_true", + help=("Submit the job and return the job ID, but" + " don't wait for the job to finish")) + +SYNC_OPT = cli_option("--sync", dest="do_locking", + default=False, action="store_true", + help=("Grab locks while doing the queries" + " in order to ensure more consistent results")) + +_DRY_RUN_OPT = cli_option("--dry-run", default=False, + action="store_true", + help=("Do not execute the operation, just run the" + " check steps and verify it it could be" + " executed")) + + def _ParseArgs(argv, commands, aliases): """Parser for the command line arguments. diff --git a/scripts/gnt-backup b/scripts/gnt-backup index cb06160aa9474b29883c88444113d211bd3307f1..9529d4fe6e1c1731fd0efa9d6a825a9314065de0 100755 --- a/scripts/gnt-backup +++ b/scripts/gnt-backup @@ -24,7 +24,6 @@ # W0614: Unused import %s from wildcard import (since we need cli) import sys -from optparse import make_option from ganeti.cli import * from ganeti import opcodes @@ -212,15 +211,15 @@ def RemoveExport(opts, args): # this is defined separately due to readability only import_opts = [ DEBUG_OPT, - make_option("-n", "--node", dest="node", - help="Target node and optional secondary node", - metavar="<pnode>[:<snode>]"), + cli_option("-n", "--node", dest="node", + help="Target node and optional secondary node", + metavar="<pnode>[:<snode>]"), 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"), + cli_option("-t", "--disk-template", dest="disk_template", + help="Custom disk setup (diskless, file, plain, drbd)", + default=None, metavar="TEMPL"), cli_option("--disk", help="Disk information", default=[], dest="disks", action="append", @@ -233,47 +232,47 @@ import_opts = [ default=[], dest="nics", action="append", type="identkeyval"), - make_option("--no-nics", default=False, action="store_true", - help="Do not create any network cards for the instance"), - make_option("--no-wait-for-sync", dest="wait_for_sync", default=True, - action="store_false", help="Don't wait for sync (DANGEROUS!)"), - make_option("--src-node", dest="src_node", help="Source node", - metavar="<node>"), - make_option("--src-dir", dest="src_dir", help="Source directory", - metavar="<dir>"), - make_option("--no-ip-check", dest="ip_check", default=True, - action="store_false", help="Don't check that the instance's IP" - " is alive"), - make_option("-I", "--iallocator", metavar="<NAME>", - help="Select nodes for the instance automatically using the" - " <NAME> iallocator plugin", default=None, type="string"), - make_option("--file-storage-dir", dest="file_storage_dir", - help="Relative path under default cluster-wide file storage dir" - " to store file-based disks", default=None, - metavar="<DIR>"), - make_option("--file-driver", dest="file_driver", help="Driver to use" - " for image files", default="loop", metavar="<DRIVER>"), + cli_option("--no-nics", default=False, action="store_true", + help="Do not create any network cards for the instance"), + cli_option("--no-wait-for-sync", dest="wait_for_sync", default=True, + action="store_false", help="Don't wait for sync (DANGEROUS!)"), + cli_option("--src-node", dest="src_node", help="Source node", + metavar="<node>"), + cli_option("--src-dir", dest="src_dir", help="Source directory", + metavar="<dir>"), + cli_option("--no-ip-check", dest="ip_check", default=True, + action="store_false", help="Don't check that the instance's IP" + " is alive"), + cli_option("-I", "--iallocator", metavar="<NAME>", + help="Select nodes for the instance automatically using the" + " <NAME> iallocator plugin", default=None, type="string"), + cli_option("--file-storage-dir", dest="file_storage_dir", + help="Relative path under default cluster-wide file storage dir" + " to store file-based disks", default=None, + metavar="<DIR>"), + cli_option("--file-driver", dest="file_driver", help="Driver to use" + " for image files", default="loop", metavar="<DRIVER>"), cli_option("-H", "--hypervisor", dest="hypervisor", - help="Hypervisor and hypervisor options, in the format" - " hypervisor:option=value,option=value,...", default=None, - type="identkeyval"), + help="Hypervisor and hypervisor options, in the format" + " hypervisor:option=value,option=value,...", default=None, + type="identkeyval"), ] commands = { 'list': (PrintExportList, [], [DEBUG_OPT, - make_option("--node", dest="nodes", default=[], action="append", - help="List only backups stored on this node" - " (can be used multiple times)"), + 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)], [DEBUG_OPT, FORCE_OPT, - make_option("-n", "--node", dest="node", help="Target node", - metavar="<node>"), - make_option("","--noshutdown", dest="shutdown", - action="store_false", default=True, - help="Don't shutdown the instance (unsafe)"), ], + cli_option("-n", "--node", dest="node", help="Target node", + metavar="<node>"), + cli_option("","--noshutdown", dest="shutdown", + action="store_false", default=True, + 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, diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster index 5a68f7a74f8323c919673d34b725b145b8ae03f8..8e8be698c72c78cbe5ed40ca4a1662ec72fc15c0 100755 --- a/scripts/gnt-cluster +++ b/scripts/gnt-cluster @@ -24,7 +24,6 @@ # W0614: Unused import %s from wildcard import (since we need cli) import sys -from optparse import make_option import os.path from ganeti.cli import * @@ -536,57 +535,56 @@ def QueueOps(opts, args): # this is an option common to more than one command, so we declare # it here and reuse it -node_option = make_option("-n", "--node", action="append", dest="nodes", - help="Node to copy to (if not given, all nodes)," - " can be given multiple times", - metavar="<node>", default=[]) +node_option = cli_option("-n", "--node", action="append", dest="nodes", + help="Node to copy to (if not given, all nodes)," + " can be given multiple times", + metavar="<node>", default=[]) commands = { 'init': (InitCluster, [ArgUnknown(min=1, max=1)], [DEBUG_OPT, - make_option("-s", "--secondary-ip", dest="secondary_ip", - help="Specify the secondary ip for this node;" - " if given, the entire cluster must have secondary" - " addresses", - metavar="ADDRESS", default=None), - make_option("-m", "--mac-prefix", dest="mac_prefix", - help="Specify the mac prefix for the instance IP" - " addresses, in the format XX:XX:XX", - metavar="PREFIX", - default=constants.DEFAULT_MAC_PREFIX,), - make_option("-g", "--vg-name", dest="vg_name", - help="Specify the volume group name " - " (cluster-wide) for disk allocation [xenvg]", - metavar="VG", - default=None,), - make_option("--master-netdev", dest="master_netdev", - help="Specify the node interface (cluster-wide)" - " on which the master IP address will be added " - " [%s]" % constants.DEFAULT_BRIDGE, - metavar="NETDEV", - default=constants.DEFAULT_BRIDGE,), - make_option("--file-storage-dir", dest="file_storage_dir", - help="Specify the default directory (cluster-wide)" - " for storing the file-based disks [%s]" % - constants.DEFAULT_FILE_STORAGE_DIR, - metavar="DIR", - default=constants.DEFAULT_FILE_STORAGE_DIR,), - make_option("--no-lvm-storage", dest="lvm_storage", - help="No support for lvm based instances" - " (cluster-wide)", - action="store_false", default=True,), - make_option("--no-etc-hosts", dest="modify_etc_hosts", - help="Don't modify /etc/hosts" - " (cluster-wide)", - action="store_false", default=True,), - make_option("--enabled-hypervisors", dest="enabled_hypervisors", - help="Comma-separated list of hypervisors", - type="string", - default=constants.DEFAULT_ENABLED_HYPERVISOR), + cli_option("-s", "--secondary-ip", dest="secondary_ip", + help="Specify the secondary ip for this node;" + " if given, the entire cluster must have secondary" + " addresses", + metavar="ADDRESS", default=None), + cli_option("-m", "--mac-prefix", dest="mac_prefix", + help="Specify the mac prefix for the instance IP" + " addresses, in the format XX:XX:XX", + metavar="PREFIX", + default=constants.DEFAULT_MAC_PREFIX,), + cli_option("-g", "--vg-name", dest="vg_name", + help="Specify the volume group name " + " (cluster-wide) for disk allocation [xenvg]", + metavar="VG", + default=None,), + cli_option("--master-netdev", dest="master_netdev", + help="Specify the node interface (cluster-wide)" + " on which the master IP address will be added " + " [%s]" % constants.DEFAULT_BRIDGE, + metavar="NETDEV", + default=constants.DEFAULT_BRIDGE,), + cli_option("--file-storage-dir", dest="file_storage_dir", + help="Specify the default directory (cluster-wide)" + " for storing the file-based disks [%s]" % + constants.DEFAULT_FILE_STORAGE_DIR, + metavar="DIR", + default=constants.DEFAULT_FILE_STORAGE_DIR,), + cli_option("--no-lvm-storage", dest="lvm_storage", + help="No support for lvm based instances" + " (cluster-wide)", + action="store_false", default=True,), + cli_option("--no-etc-hosts", dest="modify_etc_hosts", + help="Don't modify /etc/hosts" + " (cluster-wide)", + action="store_false", default=True,), + cli_option("--enabled-hypervisors", dest="enabled_hypervisors", + help="Comma-separated list of hypervisors", + type="string", + default=constants.DEFAULT_ENABLED_HYPERVISOR), cli_option("-H", "--hypervisor-parameters", dest="hvparams", - help="Hypervisor and hypervisor options, in the" - " format" - " hypervisor:option=value,option=value,...", + help="Hypervisor and hypervisor options, in the format" + " hypervisor:option=value,option=value,...", default=[], action="append", type="identkeyval"), @@ -596,18 +594,18 @@ commands = { 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", - dest="candidate_pool_size", type="int"), + cli_option("-C", "--candidate-pool-size", + default=constants.MASTER_POOL_SIZE_DEFAULT, + help="Set the candidate pool size", + dest="candidate_pool_size", type="int"), ], "[opts...] <cluster_name>", "Initialises a new cluster configuration"), 'destroy': (DestroyCluster, [], [DEBUG_OPT, - make_option("--yes-do-it", dest="yes_do_it", - help="Destroy cluster", - action="store_true"), + cli_option("--yes-do-it", dest="yes_do_it", + help="Destroy cluster", + action="store_true"), ], "", "Destroy cluster"), 'rename': (RenameCluster, [ArgUnknown(min=1, max=1)], @@ -619,10 +617,10 @@ commands = { "Forces a push of the configuration file and ssconf files" " to the nodes in the cluster"), 'verify': (VerifyCluster, [], [DEBUG_OPT, - make_option("--no-nplus1-mem", dest="skip_nplusone_mem", - help="Skip N+1 memory redundancy tests", - action="store_true", - default=False,), + 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], @@ -630,10 +628,10 @@ commands = { 'repair-disk-sizes': (RepairDiskSizes, [ArgInstance()], [DEBUG_OPT], "", "Updates mismatches in recorded disk sizes"), 'masterfailover': (MasterFailover, [], [DEBUG_OPT, - make_option("--no-voting", dest="no_voting", - help="Skip node agreement check (dangerous)", - action="store_true", - default=False,), + 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], @@ -664,18 +662,18 @@ commands = { "drain|undrain|info", "Change queue properties"), 'modify': (SetClusterParams, [], [DEBUG_OPT, - make_option("-g", "--vg-name", dest="vg_name", - help="Specify the volume group name " - " (cluster-wide) for disk allocation " - "and enable lvm based storage", - metavar="VG",), - make_option("--no-lvm-storage", dest="lvm_storage", - help="Disable support for lvm based instances" - " (cluster-wide)", - action="store_false", default=True,), - make_option("--enabled-hypervisors", dest="enabled_hypervisors", - help="Comma-separated list of hypervisors", - type="string", default=None), + cli_option("-g", "--vg-name", dest="vg_name", + help="Specify the volume group name " + " (cluster-wide) for disk allocation " + "and enable lvm based storage", + metavar="VG",), + cli_option("--no-lvm-storage", dest="lvm_storage", + help="Disable support for lvm based instances" + " (cluster-wide)", + action="store_false", default=True,), + cli_option("--enabled-hypervisors", dest="enabled_hypervisors", + help="Comma-separated list of hypervisors", + type="string", default=None), cli_option("-H", "--hypervisor-parameters", dest="hvparams", help="Hypervisor and hypervisor options, in the" " format" @@ -689,9 +687,9 @@ commands = { 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"), + cli_option("-C", "--candidate-pool-size", default=None, + help="Set the candidate pool size", + dest="candidate_pool_size", type="int"), ], "[opts...]", "Alters the parameters of the cluster"), diff --git a/scripts/gnt-debug b/scripts/gnt-debug index 91f2e102cdc0bd0ab79ea01fee4ef09c3dc13a71..cec1aaafebc7b6df2bbabe8a5f8bad80d89a4fb6 100755 --- a/scripts/gnt-debug +++ b/scripts/gnt-debug @@ -27,8 +27,6 @@ import sys import simplejson import time -from optparse import make_option - from ganeti.cli import * from ganeti import cli from ganeti import opcodes @@ -133,12 +131,12 @@ def TestAllocator(opts, args): commands = { 'delay': (Delay, [ArgUnknown(min=1, max=1)], [DEBUG_OPT, - make_option("--no-master", dest="on_master", default=True, - action="store_false", - help="Do not sleep in the master code"), - make_option("-n", dest="on_nodes", default=[], - action="append", - help="Select nodes to sleep on"), + cli_option("--no-master", dest="on_master", default=True, + action="store_false", + help="Do not sleep in the master code"), + cli_option("-n", dest="on_nodes", default=[], + action="append", + help="Select nodes to sleep on"), ], "[opts...] <duration>", "Executes a TestDelay OpCode"), 'submit-job': (GenericOpCodes, [ArgFile(min=1)], [DEBUG_OPT], @@ -146,33 +144,33 @@ commands = { " containing a list of serialized opcodes"), 'allocator': (TestAllocator, [ArgInstance(min=1, max=1)], [DEBUG_OPT, - make_option("--dir", dest="direction", - default="in", choices=["in", "out"], - help="Show allocator input (in) or allocator" - " results (out)"), - make_option("--algorithm", dest="allocator", - default=None, - help="Allocator algorithm name"), - make_option("-m", "--mode", default="relocate", - choices=["relocate", "allocate"], - help="Request mode, either allocate or" - " relocate"), + cli_option("--dir", dest="direction", + default="in", choices=["in", "out"], + help="Show allocator input (in) or allocator" + " results (out)"), + cli_option("--algorithm", dest="allocator", + default=None, + help="Allocator algorithm name"), + cli_option("-m", "--mode", default="relocate", + choices=["relocate", "allocate"], + help="Request mode, either allocate or" + " relocate"), cli_option("--mem", default=128, type="unit", help="Memory size for the instance (MiB)"), - make_option("--disks", default="4096,4096", - help="Comma separated list of disk sizes (MiB)"), - make_option("-t", "--disk-template", default="drbd", - help="Select the disk template"), - make_option("--nics", default="00:11:22:33:44:55", - help="Comma separated list of nics, each nic" - " definition is of form mac/ip/bridge, if" - " missing values are replace by None"), - make_option("-o", "--os-type", default=None, - help="Select os for the instance"), - make_option("-p", "--vcpus", default=1, type="int", - help="Select number of VCPUs for the instance"), - make_option("--tags", default=None, - help="Comma separated list of tags"), + cli_option("--disks", default="4096,4096", + help="Comma separated list of disk sizes (MiB)"), + cli_option("-t", "--disk-template", default="drbd", + help="Select the disk template"), + cli_option("--nics", default="00:11:22:33:44:55", + help="Comma separated list of nics, each nic" + " definition is of form mac/ip/bridge, if" + " missing values are replace by None"), + cli_option("-o", "--os-type", default=None, + help="Select os for the instance"), + cli_option("-p", "--vcpus", default=1, type="int", + help="Select number of VCPUs for the instance"), + cli_option("--tags", default=None, + help="Comma separated list of tags"), ], "{opts...} <instance>", "Executes a TestAllocator OpCode"), } diff --git a/scripts/gnt-instance b/scripts/gnt-instance index 5484ff2e62bc2b8bca0b38ca7eb88a5bc4da06a5..bdfc0b98c714e75931f66d452248137846ca43d5 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -28,7 +28,6 @@ import os import itertools import simplejson import time -from optparse import make_option from cStringIO import StringIO from ganeti.cli import * @@ -1332,52 +1331,52 @@ def SetInstanceParams(opts, args): # options used in more than one cmd -node_opt = make_option("-n", "--node", dest="node", help="Target node", - metavar="<node>") +node_opt = cli_option("-n", "--node", dest="node", help="Target node", + metavar="<node>") os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run", metavar="<os>") # multi-instance selection options -m_force_multi = make_option("--force-multiple", dest="force_multi", - help="Do not ask for confirmation when more than" - " one instance is affected", - action="store_true", default=False) +m_force_multi = cli_option("--force-multiple", dest="force_multi", + help="Do not ask for confirmation when more than" + " one instance is affected", + action="store_true", default=False) -m_pri_node_opt = make_option("--primary", dest="multi_mode", - help="Filter by nodes (primary only)", - const=_SHUTDOWN_NODES_PRI, action="store_const") +m_pri_node_opt = cli_option("--primary", dest="multi_mode", + help="Filter by nodes (primary only)", + const=_SHUTDOWN_NODES_PRI, action="store_const") -m_sec_node_opt = make_option("--secondary", dest="multi_mode", - help="Filter by nodes (secondary only)", - const=_SHUTDOWN_NODES_SEC, action="store_const") +m_sec_node_opt = cli_option("--secondary", dest="multi_mode", + help="Filter by nodes (secondary only)", + const=_SHUTDOWN_NODES_SEC, action="store_const") -m_node_opt = make_option("--node", dest="multi_mode", - help="Filter by nodes (primary and secondary)", - const=_SHUTDOWN_NODES_BOTH, action="store_const") +m_node_opt = cli_option("--node", dest="multi_mode", + help="Filter by nodes (primary and secondary)", + const=_SHUTDOWN_NODES_BOTH, action="store_const") -m_clust_opt = make_option("--all", dest="multi_mode", - help="Select all instances in the cluster", - const=_SHUTDOWN_CLUSTER, action="store_const") +m_clust_opt = cli_option("--all", dest="multi_mode", + help="Select all instances in the cluster", + const=_SHUTDOWN_CLUSTER, action="store_const") -m_inst_opt = make_option("--instance", dest="multi_mode", - help="Filter by instance name [default]", - const=_SHUTDOWN_INSTANCES, action="store_const") +m_inst_opt = cli_option("--instance", dest="multi_mode", + help="Filter by instance name [default]", + const=_SHUTDOWN_INSTANCES, action="store_const") # this is defined separately due to readability only add_opts = [ DEBUG_OPT, - make_option("-n", "--node", dest="node", - help="Target node and optional secondary node", - metavar="<pnode>[:<snode>]"), + cli_option("-n", "--node", dest="node", + help="Target node and optional secondary node", + metavar="<pnode>[:<snode>]"), os_opt, 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"), + cli_option("-t", "--disk-template", dest="disk_template", + help="Custom disk setup (diskless, file, plain or drbd)", + default=None, metavar="TEMPL"), cli_option("-s", "--os-size", dest="sd_size", help="Disk size for a" " single-disk configuration, when not using the --disk option," " in MiB unless a suffix is used", @@ -1390,29 +1389,29 @@ add_opts = [ default=[], dest="nics", action="append", type="identkeyval"), - make_option("--no-nics", default=False, action="store_true", - help="Do not create any network cards for the instance"), - make_option("--no-wait-for-sync", dest="wait_for_sync", default=True, - action="store_false", help="Don't wait for sync (DANGEROUS!)"), - make_option("--no-start", dest="start", default=True, - action="store_false", help="Don't start the instance after" - " creation"), - make_option("--no-ip-check", dest="ip_check", default=True, - action="store_false", help="Don't check that the instance's IP" - " is alive (only valid with --no-start)"), - make_option("--file-storage-dir", dest="file_storage_dir", - help="Relative path under default cluster-wide file storage dir" - " to store file-based disks", default=None, - metavar="<DIR>"), - make_option("--file-driver", dest="file_driver", help="Driver to use" - " for image files", default="loop", metavar="<DRIVER>"), - make_option("-I", "--iallocator", metavar="<NAME>", - help="Select nodes for the instance automatically using the" - " <NAME> iallocator plugin", default=None, type="string"), + cli_option("--no-nics", default=False, action="store_true", + help="Do not create any network cards for the instance"), + cli_option("--no-wait-for-sync", dest="wait_for_sync", default=True, + action="store_false", help="Don't wait for sync (DANGEROUS!)"), + cli_option("--no-start", dest="start", default=True, + action="store_false", help="Don't start the instance after" + " creation"), + cli_option("--no-ip-check", dest="ip_check", default=True, + action="store_false", help="Don't check that the instance's IP" + " is alive (only valid with --no-start)"), + cli_option("--file-storage-dir", dest="file_storage_dir", + help="Relative path under default cluster-wide file storage dir" + " to store file-based disks", default=None, + metavar="<DIR>"), + cli_option("--file-driver", dest="file_driver", help="Driver to use" + " for image files", default="loop", metavar="<DRIVER>"), + cli_option("-I", "--iallocator", metavar="<NAME>", + help="Select nodes for the instance automatically using the" + " <NAME> iallocator plugin", default=None, type="string"), cli_option("-H", "--hypervisor", dest="hypervisor", - help="Hypervisor and hypervisor options, in the format" - " hypervisor:option=value,option=value,...", default=None, - type="identkeyval"), + help="Hypervisor and hypervisor options, in the format" + " hypervisor:option=value,option=value,...", default=None, + type="identkeyval"), SUBMIT_OPT, ] @@ -1426,17 +1425,17 @@ commands = { "Create a bunch of instances based on specs in the file."), 'console': (ConnectToInstanceConsole, [ArgInstance(min=1, max=1)], [DEBUG_OPT, - make_option("--show-cmd", dest="show_command", - action="store_true", default=False, - help=("Show command instead of executing it"))], + 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)], [DEBUG_OPT, FORCE_OPT, - make_option("--ignore-consistency", dest="ignore_consistency", - action="store_true", default=False, - help="Ignore the consistency of the disks on" - " the secondary"), + cli_option("--ignore-consistency", dest="ignore_consistency", + action="store_true", default=False, + help="Ignore the consistency of the disks on" + " the secondary"), SUBMIT_OPT, ], "[-f] <instance>", @@ -1444,42 +1443,42 @@ commands = { " the remote mirror (only for instances of type drbd)"), 'migrate': (MigrateInstance, [ArgInstance(min=1, max=1)], [DEBUG_OPT, FORCE_OPT, - make_option("--non-live", dest="live", - default=True, action="store_false", - help="Do a non-live migration (this usually means" - " freeze the instance, save the state," - " transfer and only then resume running on the" - " secondary node)"), - make_option("--cleanup", dest="cleanup", - default=False, action="store_true", - help="Instead of performing the migration, try to" - " recover from a failed cleanup. This is safe" - " to run even if the instance is healthy, but it" - " will create extra replication traffic and " - " disrupt briefly the replication (like during the" - " migration"), + cli_option("--non-live", dest="live", + default=True, action="store_false", + help="Do a non-live migration (this usually means" + " freeze the instance, save the state," + " transfer and only then resume running on the" + " secondary node)"), + cli_option("--cleanup", dest="cleanup", + default=False, action="store_true", + help="Instead of performing the migration, try to" + " recover from a failed cleanup. This is safe" + " to run even if the instance is healthy, but it" + " will create extra replication traffic and " + " disrupt briefly the replication (like during the" + " migration"), ], "[-f] <instance>", "Migrate instance to its secondary node" " (only for instances of type drbd)"), 'move': (MoveInstance, [ArgInstance(min=1, max=1)], [DEBUG_OPT, FORCE_OPT, SUBMIT_OPT, - make_option("-n", "--new-node", dest="target_node", - help="Destinattion node", metavar="NODE", - default=None), + cli_option("-n", "--new-node", dest="target_node", + help="Destinattion node", metavar="NODE", + default=None), ], "[-f] <instance>", "Move instance to an arbitrary node" " (only for instances of type file and lv)"), 'info': (ShowInstanceConfig, [ArgInstance()], [DEBUG_OPT, - make_option("-s", "--static", dest="static", - action="store_true", default=False, - help="Only show configuration data, not runtime data"), - make_option("--all", dest="show_all", - default=False, action="store_true", - help="Show info on all instances on the cluster." - " This can take a long time to run, use wisely."), + cli_option("-s", "--static", dest="static", + action="store_true", default=False, + help="Only show configuration data, not runtime data"), + cli_option("--all", dest="show_all", + default=False, action="store_true", + help="Show info on all instances on the cluster." + " This can take a long time to run, use wisely."), ], "[-s] {--all | <instance>...}", "Show information on the specified instance(s)"), 'list': (ListInstances, [ArgInstance()], @@ -1498,61 +1497,61 @@ commands = { m_force_multi, m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, - make_option("--select-os", dest="select_os", - action="store_true", default=False, - help="Interactive OS reinstall, lists available" - " OS templates for selection"), + cli_option("--select-os", dest="select_os", + action="store_true", default=False, + help="Interactive OS reinstall, lists available" + " OS templates for selection"), SUBMIT_OPT, ], "[-f] <instance>", "Reinstall a stopped instance"), 'remove': (RemoveInstance, [ArgInstance(min=1, max=1)], [DEBUG_OPT, FORCE_OPT, - make_option("--ignore-failures", dest="ignore_failures", - action="store_true", default=False, - help=("Remove the instance from the cluster even" - " if there are failures during the removal" - " process (shutdown, disk removal, etc.)")), + cli_option("--ignore-failures", dest="ignore_failures", + action="store_true", default=False, + help=("Remove the instance from the cluster even" + " if there are failures during the removal" + " process (shutdown, disk removal, etc.)")), SUBMIT_OPT, ], "[-f] <instance>", "Shuts down the instance and removes it"), 'rename': (RenameInstance, [ArgInstance(min=1, max=1), ArgUnknown(min=1, max=1)], [DEBUG_OPT, - make_option("--no-ip-check", dest="ignore_ip", - help="Do not check that the IP of the new name" - " is alive", - default=False, action="store_true"), + cli_option("--no-ip-check", dest="ignore_ip", + help="Do not check that the IP of the new name" + " is alive", + default=False, action="store_true"), SUBMIT_OPT, ], "<instance> <new_name>", "Rename the instance"), 'replace-disks': (ReplaceDisks, [ArgInstance(min=1, max=1)], [DEBUG_OPT, - make_option("-n", "--new-secondary", dest="new_secondary", - help=("New secondary node (for secondary" - " node change)"), metavar="NODE", - default=None), - make_option("-p", "--on-primary", dest="on_primary", - default=False, action="store_true", - help=("Replace the disk(s) on the primary" - " node (only for the drbd template)")), - make_option("-s", "--on-secondary", dest="on_secondary", - default=False, action="store_true", - help=("Replace the disk(s) on the secondary" - " node (only for the drbd template)")), - make_option("-a", "--auto", dest="auto", - default=False, action="store_true", - help=("Automatically replace faulty disks" - " (only for the drbd template)")), - make_option("--disks", dest="disks", default=None, - help="Comma-separated list of disks" - " indices to replace (e.g. 0,2) (optional," - " defaults to all disks)"), - make_option("-I", "--iallocator", metavar="<NAME>", - help="Select new secondary for the instance" - " automatically using the" - " <NAME> iallocator plugin (enables" - " secondary node replacement)", - default=None, type="string"), + cli_option("-n", "--new-secondary", dest="new_secondary", + help=("New secondary node (for secondary" + " node change)"), metavar="NODE", + default=None), + cli_option("-p", "--on-primary", dest="on_primary", + default=False, action="store_true", + help=("Replace the disk(s) on the primary" + " node (only for the drbd template)")), + cli_option("-s", "--on-secondary", dest="on_secondary", + default=False, action="store_true", + help=("Replace the disk(s) on the secondary" + " node (only for the drbd template)")), + cli_option("-a", "--auto", dest="auto", + default=False, action="store_true", + help=("Automatically replace faulty disks" + " (only for the drbd template)")), + cli_option("--disks", dest="disks", default=None, + help="Comma-separated list of disks" + " indices to replace (e.g. 0,2) (optional," + " defaults to all disks)"), + cli_option("-I", "--iallocator", metavar="<NAME>", + help="Select new secondary for the instance" + " automatically using the" + " <NAME> iallocator plugin (enables" + " secondary node replacement)", + default=None, type="string"), SUBMIT_OPT, ], "[-s|-p|-n NODE|-I NAME] <instance>", @@ -1591,19 +1590,19 @@ commands = { default={}, dest="hvparams", help="Temporary hypervisor parameters"), cli_option("-B", "--backend", type="keyval", - default={}, dest="beparams", - help="Temporary backend parameters"), + default={}, dest="beparams", + help="Temporary backend parameters"), ], "<instance>", "Starts an instance"), 'reboot': (RebootInstance, [ArgInstance(min=1)], [DEBUG_OPT, m_force_multi, - make_option("-t", "--type", dest="reboot_type", - help="Type of reboot: soft/hard/full", - default=constants.INSTANCE_REBOOT_HARD, - type="string", metavar="<REBOOT>"), - make_option("--ignore-secondaries", dest="ignore_secondaries", - default=False, action="store_true", - help="Ignore errors from secondaries"), + cli_option("-t", "--type", dest="reboot_type", + help="Type of reboot: soft/hard/full", + default=constants.INSTANCE_REBOOT_HARD, + type="string", metavar="<REBOOT>"), + cli_option("--ignore-secondaries", dest="ignore_secondaries", + default=False, action="store_true", + help="Ignore errors from secondaries"), m_node_opt, m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, SUBMIT_OPT, @@ -1611,11 +1610,11 @@ commands = { "<instance>", "Reboots an instance"), 'activate-disks': (ActivateDisks, [ArgInstance(min=1, max=1)], [DEBUG_OPT, SUBMIT_OPT, - make_option("--ignore-size", dest="ignore_size", - default=False, action="store_true", - help="Ignore current recorded size" - " (useful for forcing activation when" - " the recorded size is wrong)"), + cli_option("--ignore-size", dest="ignore_size", + default=False, action="store_true", + help="Ignore current recorded size" + " (useful for forcing activation when" + " the recorded size is wrong)"), ], "<instance>", "Activate an instance's disks"), @@ -1625,10 +1624,10 @@ commands = { "Deactivate an instance's disks"), 'recreate-disks': (RecreateDisks, [ArgInstance(min=1, max=1)], [DEBUG_OPT, SUBMIT_OPT, - make_option("--disks", dest="disks", default=None, - help="Comma-separated list of disks" - " indices to replace (e.g. 0,2) (optional," - " defaults to all disks)"), + cli_option("--disks", dest="disks", default=None, + help="Comma-separated list of disks" + " indices to replace (e.g. 0,2) (optional," + " defaults to all disks)"), ], "<instance>", "Recreate an instance's disks"), @@ -1636,10 +1635,10 @@ commands = { [ArgInstance(min=1, max=1), ArgUnknown(min=1, max=1), ArgUnknown(min=1, max=1)], [DEBUG_OPT, SUBMIT_OPT, - make_option("--no-wait-for-sync", - dest="wait_for_sync", default=True, - action="store_false", - help="Don't wait for sync (DANGEROUS!)"), + cli_option("--no-wait-for-sync", + dest="wait_for_sync", default=True, + action="store_false", + 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], diff --git a/scripts/gnt-node b/scripts/gnt-node index 00c2d3899aa6818065377559d8e5f8facfbeec63..a23e8223cce9b71cdc90cde77ff1100f7b1bdf5f 100755 --- a/scripts/gnt-node +++ b/scripts/gnt-node @@ -24,7 +24,6 @@ # W0614: Unused import %s from wildcard import (since we need cli) import sys -from optparse import make_option from ganeti.cli import * from ganeti import cli @@ -625,50 +624,50 @@ def SetNodeParams(opts, args): commands = { 'add': (AddNode, [ArgUnknown(min=1, max=1)], [DEBUG_OPT, - make_option("-s", "--secondary-ip", dest="secondary_ip", - help="Specify the secondary ip for the node", - metavar="ADDRESS", default=None), - make_option("--readd", dest="readd", - default=False, action="store_true", - help="Readd old node after replacing it"), - make_option("--no-ssh-key-check", dest="ssh_key_check", - default=True, action="store_false", - help="Disable SSH key fingerprint checking"), + cli_option("-s", "--secondary-ip", dest="secondary_ip", + help="Specify the secondary ip for the node", + metavar="ADDRESS", default=None), + cli_option("--readd", dest="readd", + default=False, action="store_true", + help="Readd old node after replacing it"), + cli_option("--no-ssh-key-check", dest="ssh_key_check", + default=True, action="store_false", + help="Disable SSH key fingerprint checking"), ], "[-s ip] [--readd] [--no-ssh-key-check] <node_name>", "Add a node to the cluster"), 'evacuate': (EvacuateNode, [ArgNode(min=1, max=1)], [DEBUG_OPT, FORCE_OPT, - make_option("-n", "--new-secondary", dest="dst_node", - help="New secondary node", metavar="NODE", - default=None), - make_option("-I", "--iallocator", metavar="<NAME>", - help="Select new secondary for the instance" - " automatically using the" - " <NAME> iallocator plugin", - default=None, type="string"), + cli_option("-n", "--new-secondary", dest="dst_node", + help="New secondary node", metavar="NODE", + default=None), + cli_option("-I", "--iallocator", metavar="<NAME>", + help="Select new secondary for the instance" + " automatically using the" + " <NAME> iallocator plugin", + default=None, type="string"), ], "[-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)], [DEBUG_OPT, FORCE_OPT, - make_option("--ignore-consistency", dest="ignore_consistency", - action="store_true", default=False, - help="Ignore the consistency of the disks on" - " the secondary"), + cli_option("--ignore-consistency", dest="ignore_consistency", + action="store_true", default=False, + help="Ignore the consistency of the disks on" + " the secondary"), ], "[-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)], [DEBUG_OPT, FORCE_OPT, - make_option("--non-live", dest="live", - default=True, action="store_false", - help="Do a non-live migration (this usually means" - " freeze the instance, save the state," - " transfer and only then resume running on the" - " secondary node)"), + cli_option("--non-live", dest="live", + default=True, action="store_false", + help="Do a non-live migration (this usually means" + " freeze the instance, save the state," + " transfer and only then resume running on the" + " secondary node)"), ], "[-f] <node>", "Migrate all the primary instance on a node away from it" @@ -685,16 +684,16 @@ commands = { 'modify': (SetNodeParams, [ArgNode(min=1, max=1)], [DEBUG_OPT, FORCE_OPT, SUBMIT_OPT, - make_option("-C", "--master-candidate", dest="master_candidate", - choices=('yes', 'no'), default=None, - metavar="yes|no", - help="Set the master_candidate flag on the node"), - make_option("-O", "--offline", dest="offline", metavar="yes|no", - choices=('yes', 'no'), default=None, - help="Set the offline flag on the node"), - make_option("-D", "--drained", dest="drained", metavar="yes|no", - choices=('yes', 'no'), default=None, - help="Set the drained flag on the node"), + cli_option("-C", "--master-candidate", dest="master_candidate", + choices=('yes', 'no'), default=None, + metavar="yes|no", + help="Set the master_candidate flag on the node"), + cli_option("-O", "--offline", dest="offline", metavar="yes|no", + choices=('yes', 'no'), default=None, + help="Set the offline flag on the node"), + cli_option("-D", "--drained", dest="drained", metavar="yes|no", + choices=('yes', 'no'), default=None, + help="Set the drained flag on the node"), ], "<node>", "Alters the parameters of a node"), 'powercycle': (PowercycleNode, [ArgNode(min=1, max=1)], @@ -716,10 +715,10 @@ commands = { choices=_MODIFIABLE_STORAGE_TYPES), ArgFile(min=1, max=1)], [DEBUG_OPT, - make_option("--allocatable", dest="allocatable", - choices=["yes", "no"], default=None, - metavar="yes|no", - help="Set the allocatable flag on a volume"), + cli_option("--allocatable", dest="allocatable", + choices=["yes", "no"], default=None, + metavar="yes|no", + help="Set the allocatable flag on a volume"), ], "<node_name> <storage_type> <name>", "Modify storage volume on a node"), diff --git a/scripts/gnt-os b/scripts/gnt-os index 41d3dca4df4c51fdf7e2cd556c97792eeaf3688c..9ad2c1423358a69eb9b4a7a31c1c344f24cea004 100755 --- a/scripts/gnt-os +++ b/scripts/gnt-os @@ -24,7 +24,6 @@ # W0614: Unused import %s from wildcard import (since we need cli) import sys -from optparse import make_option from ganeti.cli import * from ganeti import opcodes