diff --git a/lib/cli.py b/lib/cli.py index 08827061ab3c824b0b5fd44fd14b8b5621d82deb..796cd0c46933a6a8fdc454a2dbd8c79c793038b8 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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 diff --git a/lib/cmdlib.py b/lib/cmdlib.py index a8a071fdb4b5aa7549b850ae69746c8d261468a2..b857e39f2c5db3f103b0bac6fdec1d85a992ce37 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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): diff --git a/lib/opcodes.py b/lib/opcodes.py index 9a8b2f67eea3a3ef96c47ce91098d55313bf74e6..b093af0a92b7ea178bb8f40b5a61ac90235176e5 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -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", diff --git a/scripts/gnt-backup b/scripts/gnt-backup index f5598cbc2b80eaa0e9e8789e51024d249a2f25ce..e0370351568ba6d73dabccf77e7ac6a47461f8c1 100755 --- a/scripts/gnt-backup +++ b/scripts/gnt-backup @@ -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, ]