Commit e588764d authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a identify-defaults options for import



When importing an instance, all the saved valued will be used as
explicitly specified values, overriding the cluster defaults. This means
export+import will change the status (from default to explicitly
specified) of parameters.

This patch adds a new option that changes the behaviour to identify
parameter values which are equal to the current cluster defaults and
mark them as such. It does this for hv, be and nic parameters.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent b6cd72b2
......@@ -71,6 +71,7 @@ __all__ = [
"HVOPTS_OPT",
"HYPERVISOR_OPT",
"IALLOCATOR_OPT",
"IDENTIFY_DEFAULTS_OPT",
"IGNORE_CONSIST_OPT",
"IGNORE_FAILURES_OPT",
"IGNORE_SECONDARIES_OPT",
......@@ -921,6 +922,13 @@ MAINTAIN_NODE_HEALTH_OPT = \
" health, by shutting down unknown instances, shutting down"
" unknown DRBD devices, etc.")
IDENTIFY_DEFAULTS_OPT = \
cli_option("--identify-defaults", dest="identify_defaults",
default=False, action="store_true",
help="Identify which saved instance parameters are equal to"
" the current cluster defaults and set them as such, instead"
" of marking them as overridden")
def _ParseArgs(argv, commands, aliases):
"""Parser for the command line arguments.
......@@ -1599,12 +1607,14 @@ def GenericInstanceCreate(mode, opts, args):
src_node = None
src_path = None
no_install = opts.no_install
identify_defaults = False
elif mode == constants.INSTANCE_IMPORT:
start = False
os_type = None
src_node = opts.src_node
src_path = opts.src_dir
no_install = None
identify_defaults = opts.identify_defaults
else:
raise errors.ProgrammerError("Invalid creation mode %s" % mode)
......@@ -1627,7 +1637,8 @@ def GenericInstanceCreate(mode, opts, args):
os_type=os_type,
src_node=src_node,
src_path=src_path,
no_install=no_install)
no_install=no_install,
identify_defaults=identify_defaults)
SubmitOrSend(op, opts)
return 0
......
......@@ -5988,7 +5988,7 @@ class LUCreateInstance(LogicalUnit):
"""
# set optional parameters to none if they don't exist
for attr in ["pnode", "snode", "iallocator", "hypervisor",
"disk_template"]:
"disk_template", "identify_defaults"]:
if not hasattr(self.op, attr):
setattr(self.op, attr, None)
......@@ -6313,6 +6313,27 @@ class LUCreateInstance(LogicalUnit):
einfo.has_option(constants.INISECT_INS, name)):
self.op.beparams[name] = einfo.get(constants.INISECT_INS, name)
def _RevertToDefaults(self, cluster):
"""Revert the instance parameters to the default values.
"""
# hvparams
hv_defs = cluster.GetHVDefaults(self.op.hypervisor, self.op.os_type)
for name in self.op.hvparams.keys():
if name in hv_defs and hv_defs[name] == self.op.hvparams[name]:
del self.op.hvparams[name]
# beparams
be_defs = cluster.beparams.get(constants.PP_DEFAULT, {})
for name in self.op.beparams.keys():
if name in be_defs and be_defs[name] == self.op.beparams[name]:
del self.op.beparams[name]
# nic params
nic_defs = cluster.nicparams.get(constants.PP_DEFAULT, {})
for nic in self.op.nics:
for name in constants.NICS_PARAMETERS:
if name in nic and name in nic_defs and nic[name] == nic_defs[name]:
del nic[name]
def CheckPrereq(self):
"""Check prerequisites.
......@@ -6355,6 +6376,11 @@ class LUCreateInstance(LogicalUnit):
self.be_full = objects.FillDict(cluster.beparams[constants.PP_DEFAULT],
self.op.beparams)
# now that hvp/bep are in final format, let's reset to defaults,
# if told to do so
if self.op.identify_defaults:
self._RevertToDefaults(cluster)
# NIC buildup
self.nics = []
for idx, nic in enumerate(self.op.nics):
......
......@@ -465,7 +465,7 @@ class OpCreateInstance(OpCode):
"os_type", "force_variant", "no_install",
"pnode", "disk_template", "snode", "mode",
"disks", "nics",
"src_node", "src_path", "start",
"src_node", "src_path", "start", "identify_defaults",
"wait_for_sync", "ip_check", "name_check",
"file_storage_dir", "file_driver",
"iallocator",
......
......@@ -125,22 +125,23 @@ def RemoveExport(opts, args):
# this is defined separately due to readability only
import_opts = [
NODE_PLACEMENT_OPT,
BACKEND_OPT,
DISK_TEMPLATE_OPT,
DISK_OPT,
OS_SIZE_OPT,
DISK_TEMPLATE_OPT,
FILESTORE_DIR_OPT,
FILESTORE_DRIVER_OPT,
HYPERVISOR_OPT,
IALLOCATOR_OPT,
IDENTIFY_DEFAULTS_OPT,
NET_OPT,
NODE_PLACEMENT_OPT,
NOIPCHECK_OPT,
NONAMECHECK_OPT,
NONICS_OPT,
NWSYNC_OPT,
OS_SIZE_OPT,
SRC_DIR_OPT,
SRC_NODE_OPT,
NOIPCHECK_OPT,
NONAMECHECK_OPT,
IALLOCATOR_OPT,
FILESTORE_DIR_OPT,
FILESTORE_DRIVER_OPT,
HYPERVISOR_OPT,
SUBMIT_OPT,
]
......
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