Commit c38c44ad authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Make all options use cli_option


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent a8005e17
......@@ -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.
......
......@@ -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,
......
......@@ -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"),
......
......@@ -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"),
}
......
This diff is collapsed.
......@@ -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,"