Revision e588764d

b/lib/cli.py
71 71
  "HVOPTS_OPT",
72 72
  "HYPERVISOR_OPT",
73 73
  "IALLOCATOR_OPT",
74
  "IDENTIFY_DEFAULTS_OPT",
74 75
  "IGNORE_CONSIST_OPT",
75 76
  "IGNORE_FAILURES_OPT",
76 77
  "IGNORE_SECONDARIES_OPT",
......
921 922
               " health, by shutting down unknown instances, shutting down"
922 923
               " unknown DRBD devices, etc.")
923 924

  
925
IDENTIFY_DEFAULTS_OPT = \
926
    cli_option("--identify-defaults", dest="identify_defaults",
927
               default=False, action="store_true",
928
               help="Identify which saved instance parameters are equal to"
929
               " the current cluster defaults and set them as such, instead"
930
               " of marking them as overridden")
931

  
924 932

  
925 933
def _ParseArgs(argv, commands, aliases):
926 934
  """Parser for the command line arguments.
......
1599 1607
    src_node = None
1600 1608
    src_path = None
1601 1609
    no_install = opts.no_install
1610
    identify_defaults = False
1602 1611
  elif mode == constants.INSTANCE_IMPORT:
1603 1612
    start = False
1604 1613
    os_type = None
1605 1614
    src_node = opts.src_node
1606 1615
    src_path = opts.src_dir
1607 1616
    no_install = None
1617
    identify_defaults = opts.identify_defaults
1608 1618
  else:
1609 1619
    raise errors.ProgrammerError("Invalid creation mode %s" % mode)
1610 1620

  
......
1627 1637
                                os_type=os_type,
1628 1638
                                src_node=src_node,
1629 1639
                                src_path=src_path,
1630
                                no_install=no_install)
1640
                                no_install=no_install,
1641
                                identify_defaults=identify_defaults)
1631 1642

  
1632 1643
  SubmitOrSend(op, opts)
1633 1644
  return 0
b/lib/cmdlib.py
5988 5988
    """
5989 5989
    # set optional parameters to none if they don't exist
5990 5990
    for attr in ["pnode", "snode", "iallocator", "hypervisor",
5991
                 "disk_template"]:
5991
                 "disk_template", "identify_defaults"]:
5992 5992
      if not hasattr(self.op, attr):
5993 5993
        setattr(self.op, attr, None)
5994 5994

  
......
6313 6313
            einfo.has_option(constants.INISECT_INS, name)):
6314 6314
          self.op.beparams[name] = einfo.get(constants.INISECT_INS, name)
6315 6315

  
6316
  def _RevertToDefaults(self, cluster):
6317
    """Revert the instance parameters to the default values.
6318

  
6319
    """
6320
    # hvparams
6321
    hv_defs = cluster.GetHVDefaults(self.op.hypervisor, self.op.os_type)
6322
    for name in self.op.hvparams.keys():
6323
      if name in hv_defs and hv_defs[name] == self.op.hvparams[name]:
6324
        del self.op.hvparams[name]
6325
    # beparams
6326
    be_defs = cluster.beparams.get(constants.PP_DEFAULT, {})
6327
    for name in self.op.beparams.keys():
6328
      if name in be_defs and be_defs[name] == self.op.beparams[name]:
6329
        del self.op.beparams[name]
6330
    # nic params
6331
    nic_defs = cluster.nicparams.get(constants.PP_DEFAULT, {})
6332
    for nic in self.op.nics:
6333
      for name in constants.NICS_PARAMETERS:
6334
        if name in nic and name in nic_defs and nic[name] == nic_defs[name]:
6335
          del nic[name]
6336

  
6316 6337
  def CheckPrereq(self):
6317 6338
    """Check prerequisites.
6318 6339

  
......
6355 6376
    self.be_full = objects.FillDict(cluster.beparams[constants.PP_DEFAULT],
6356 6377
                                    self.op.beparams)
6357 6378

  
6379
    # now that hvp/bep are in final format, let's reset to defaults,
6380
    # if told to do so
6381
    if self.op.identify_defaults:
6382
      self._RevertToDefaults(cluster)
6383

  
6358 6384
    # NIC buildup
6359 6385
    self.nics = []
6360 6386
    for idx, nic in enumerate(self.op.nics):
b/lib/opcodes.py
465 465
    "os_type", "force_variant", "no_install",
466 466
    "pnode", "disk_template", "snode", "mode",
467 467
    "disks", "nics",
468
    "src_node", "src_path", "start",
468
    "src_node", "src_path", "start", "identify_defaults",
469 469
    "wait_for_sync", "ip_check", "name_check",
470 470
    "file_storage_dir", "file_driver",
471 471
    "iallocator",
b/scripts/gnt-backup
125 125

  
126 126
# this is defined separately due to readability only
127 127
import_opts = [
128
  NODE_PLACEMENT_OPT,
129 128
  BACKEND_OPT,
130
  DISK_TEMPLATE_OPT,
131 129
  DISK_OPT,
132
  OS_SIZE_OPT,
130
  DISK_TEMPLATE_OPT,
131
  FILESTORE_DIR_OPT,
132
  FILESTORE_DRIVER_OPT,
133
  HYPERVISOR_OPT,
134
  IALLOCATOR_OPT,
135
  IDENTIFY_DEFAULTS_OPT,
133 136
  NET_OPT,
137
  NODE_PLACEMENT_OPT,
138
  NOIPCHECK_OPT,
139
  NONAMECHECK_OPT,
134 140
  NONICS_OPT,
135 141
  NWSYNC_OPT,
142
  OS_SIZE_OPT,
136 143
  SRC_DIR_OPT,
137 144
  SRC_NODE_OPT,
138
  NOIPCHECK_OPT,
139
  NONAMECHECK_OPT,
140
  IALLOCATOR_OPT,
141
  FILESTORE_DIR_OPT,
142
  FILESTORE_DRIVER_OPT,
143
  HYPERVISOR_OPT,
144 145
  SUBMIT_OPT,
145 146
  ]
146 147

  

Also available in: Unified diff