json_filename = args[0]
try:
- fd = open(json_filename, 'r')
- instance_data = simplejson.load(fd)
- fd.close()
+ instance_data = simplejson.loads(utils.ReadFile(json_filename))
except Exception, err:
ToStderr("Can't parse the instance definition file: %s" % str(err))
return 1
"""
if not (opts.nics or opts.disks or
- opts.hypervisor or opts.beparams):
+ opts.hvparams or opts.beparams):
ToStderr("Please give at least one of the parameters.")
return 1
utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES,
allowed_values=[constants.VALUE_DEFAULT])
- for param in opts.hypervisor:
- if isinstance(opts.hypervisor[param], basestring):
- if opts.hypervisor[param].lower() == "default":
- opts.hypervisor[param] = constants.VALUE_DEFAULT
+ for param in opts.hvparams:
+ if isinstance(opts.hvparams[param], basestring):
+ if opts.hvparams[param].lower() == "default":
+ opts.hvparams[param] = constants.VALUE_DEFAULT
- utils.ForceDictType(opts.hypervisor, constants.HVS_PARAMETER_TYPES,
+ utils.ForceDictType(opts.hvparams, constants.HVS_PARAMETER_TYPES,
allowed_values=[constants.VALUE_DEFAULT])
for idx, (nic_op, nic_dict) in enumerate(opts.nics):
op = opcodes.OpSetInstanceParams(instance_name=args[0],
nics=opts.nics,
disks=opts.disks,
- hvparams=opts.hypervisor,
+ hvparams=opts.hvparams,
beparams=opts.beparams,
force=opts.force)
metavar="<node>",
completion_suggest=OPT_COMPL_ONE_NODE)
-os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run",
- metavar="<os>",
- completion_suggest=OPT_COMPL_ONE_OS)
-
# multi-instance selection options
m_force_multi = cli_option("--force-multiple", dest="force_multi",
help="Do not ask for confirmation when more than"
DEBUG_OPT,
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"),
- cli_option("-t", "--disk-template", dest="disk_template",
- help="Custom disk setup (diskless, file, plain or drbd)",
- default=None, metavar="TEMPL",
- choices=list(constants.DISK_TEMPLATES)),
+ metavar="<pnode>[:<snode>]",
+ completion_suggest=OPT_COMPL_INST_ADD_NODES),
+ OS_OPT,
+ BACKEND_OPT,
+ DISK_TEMPLATE_OPT,
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",
default=None, type="unit", metavar="<size>"),
- cli_option("--disk", help="Disk information",
- default=[], dest="disks",
- action="append",
- type="identkeyval"),
- cli_option("--net", help="NIC information",
- default=[], dest="nics",
- action="append",
- type="identkeyval"),
- 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!)"),
+ DISK_OPT,
+ NET_OPT,
+ NONICS_OPT,
+ NWSYNC_OPT,
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>",
- choices=list(constants.FILE_DRIVER)),
- cli_option("-I", "--iallocator", metavar="<NAME>",
- help="Select nodes for the instance automatically using the"
- " <NAME> iallocator plugin", default=None, type="string",
- completion_suggest=OPT_COMPL_ONE_IALLOCATOR),
- cli_option("-H", "--hypervisor", dest="hypervisor",
- help="Hypervisor and hypervisor options, in the format"
- " hypervisor:option=value,option=value,...", default=None,
- type="identkeyval"),
+ NOIPCHECK_OPT,
+ FILESTORE_DIR_OPT,
+ FILESTORE_DRIVER_OPT,
+ IALLOCATOR_OPT,
+ HYPERVISOR_OPT,
SUBMIT_OPT,
]
" list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
),
'reinstall': (ReinstallInstance, [ArgInstance(min=1)],
- [DEBUG_OPT, FORCE_OPT, os_opt,
+ [DEBUG_OPT, FORCE_OPT, OS_OPT,
m_force_multi,
m_node_opt, m_pri_node_opt, m_sec_node_opt,
m_clust_opt, m_inst_opt,
"[-f] <instance>", "Shuts down the instance and removes it"),
'rename': (RenameInstance,
[ArgInstance(min=1, max=1), ArgHost(min=1, max=1)],
- [DEBUG_OPT,
- 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,
- ],
+ [DEBUG_OPT, NOIPCHECK_OPT, SUBMIT_OPT],
"<instance> <new_name>", "Rename the instance"),
'replace-disks': (ReplaceDisks, ARGS_ONE_INSTANCE,
[DEBUG_OPT,
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",
- completion_suggest=OPT_COMPL_ONE_IALLOCATOR),
+ DISKIDX_OPT,
+ IALLOCATOR_OPT,
SUBMIT_OPT,
],
"[-s|-p|-n NODE|-I NAME] <instance>",
"Replaces all disks for the instance"),
'modify': (SetInstanceParams, ARGS_ONE_INSTANCE,
- [DEBUG_OPT, FORCE_OPT,
- 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"),
- cli_option("--net", help="NIC changes",
- default=[], dest="nics",
- action="append",
- type="identkeyval"),
- SUBMIT_OPT,
- ],
+ [BACKEND_OPT, DEBUG_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT,
+ NET_OPT, SUBMIT_OPT],
"<instance>", "Alters the parameters of an instance"),
'shutdown': (ShutdownInstance, [ArgInstance(min=1)],
[DEBUG_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt,
m_node_opt, m_pri_node_opt, m_sec_node_opt,
m_clust_opt, m_inst_opt,
SUBMIT_OPT,
- 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"),
+ HVOPTS_OPT,
+ BACKEND_OPT,
],
"<instance>", "Starts an instance"),
'reboot': (RebootInstance, [ArgInstance(min=1)],
"<instance>",
"Deactivate an instance's disks"),
'recreate-disks': (RecreateDisks, ARGS_ONE_INSTANCE,
- [DEBUG_OPT, SUBMIT_OPT,
- 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)"),
- ],
+ [DEBUG_OPT, SUBMIT_OPT, DISKIDX_OPT],
"<instance>",
"Recreate an instance's disks"),
'grow-disk': (GrowDisk,
[ArgInstance(min=1, max=1), ArgUnknown(min=1, max=1),
ArgUnknown(min=1, max=1)],
- [DEBUG_OPT, SUBMIT_OPT,
- cli_option("--no-wait-for-sync",
- dest="wait_for_sync", default=True,
- action="store_false",
- help="Don't wait for sync (DANGEROUS!)"),
- ],
+ [DEBUG_OPT, SUBMIT_OPT, NWSYNC_OPT],
"<instance> <disk> <size>", "Grow an instance's disk"),
'list-tags': (ListTags, ARGS_ONE_INSTANCE, [DEBUG_OPT],
"<instance_name>", "List the tags of the given instance"),