Revision 57de31c0

b/lib/cli.py
137 137
  "NOVOTING_OPT",
138 138
  "NO_REMEMBER_OPT",
139 139
  "NWSYNC_OPT",
140
  "OFFLINE_INST_OPT",
141
  "ONLINE_INST_OPT",
140 142
  "ON_PRIMARY_OPT",
141 143
  "ON_SECONDARY_OPT",
142 144
  "OFFLINE_OPT",
......
685 687
                        default=True, action="store_false",
686 688
                        help="Don't wait for sync (DANGEROUS!)")
687 689

  
690
ONLINE_INST_OPT = cli_option("--online", dest="online_inst",
691
                             action="store_true", default=False,
692
                             help="Enable offline instance")
693

  
694
OFFLINE_INST_OPT = cli_option("--offline", dest="offline_inst",
695
                              action="store_true", default=False,
696
                              help="Disable down instance")
697

  
688 698
DISK_TEMPLATE_OPT = cli_option("-t", "--disk-template", dest="disk_template",
689 699
                               help=("Custom disk setup (%s)" %
690 700
                                     utils.CommaJoin(constants.DISK_TEMPLATES)),
b/lib/client/gnt_instance.py
1248 1248

  
1249 1249
  """
1250 1250
  if not (opts.nics or opts.disks or opts.disk_template or
1251
          opts.hvparams or opts.beparams or opts.os or opts.osparams):
1251
          opts.hvparams or opts.beparams or opts.os or opts.osparams or
1252
          opts.offline_inst or opts.online_inst):
1252 1253
    ToStderr("Please give at least one of the parameters.")
1253 1254
    return 1
1254 1255

  
......
1305 1306
                                   osparams=opts.osparams,
1306 1307
                                   force_variant=opts.force_variant,
1307 1308
                                   force=opts.force,
1308
                                   wait_for_sync=opts.wait_for_sync)
1309
                                   wait_for_sync=opts.wait_for_sync,
1310
                                   offline_inst=opts.offline_inst,
1311
                                   online_inst=opts.online_inst)
1309 1312

  
1310 1313
  # even if here we process the result, we allow submit only
1311 1314
  result = SubmitOrSend(op, opts)
......
1487 1490
    SetInstanceParams, ARGS_ONE_INSTANCE,
1488 1491
    [BACKEND_OPT, DISK_OPT, FORCE_OPT, HVOPTS_OPT, NET_OPT, SUBMIT_OPT,
1489 1492
     DISK_TEMPLATE_OPT, SINGLE_NODE_OPT, OS_OPT, FORCE_VARIANT_OPT,
1490
     OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT],
1493
     OSPARAMS_OPT, DRY_RUN_OPT, PRIORITY_OPT, NWSYNC_OPT, OFFLINE_INST_OPT,
1494
     ONLINE_INST_OPT],
1491 1495
    "<instance>", "Alters the parameters of an instance"),
1492 1496
  "shutdown": (
1493 1497
    GenericManyOps("shutdown", _ShutdownInstance), [ArgInstance()],
b/lib/cmdlib.py
10982 10982

  
10983 10983
  def CheckArguments(self):
10984 10984
    if not (self.op.nics or self.op.disks or self.op.disk_template or
10985
            self.op.hvparams or self.op.beparams or self.op.os_name):
10985
            self.op.hvparams or self.op.beparams or self.op.os_name or
10986
            self.op.online_inst or self.op.offline_inst):
10986 10987
      raise errors.OpPrereqError("No changes submitted", errors.ECODE_INVAL)
10987 10988

  
10988 10989
    if self.op.hvparams:
......
11449 11450
                                     (disk_op, len(instance.disks)),
11450 11451
                                     errors.ECODE_INVAL)
11451 11452

  
11453
    # disabling the instance
11454
    if self.op.offline_inst:
11455
      _CheckInstanceState(self, instance, INSTANCE_DOWN,
11456
                          msg="cannot change instance state to offline")
11457

  
11458
    # enabling the instance
11459
    if self.op.online_inst:
11460
      _CheckInstanceState(self, instance, INSTANCE_OFFLINE,
11461
                          msg="cannot make instance go online")
11462

  
11452 11463
  def _ConvertPlainToDrbd(self, feedback_fn):
11453 11464
    """Converts an instance from plain to drbd.
11454 11465

  
......
11709 11720
      for key, val in self.op.osparams.iteritems():
11710 11721
        result.append(("os/%s" % key, val))
11711 11722

  
11723
    # online/offline instance
11724
    if self.op.online_inst:
11725
      self.cfg.MarkInstanceDown(instance.name)
11726
      result.append(("admin_state", constants.ADMINST_DOWN))
11727
    if self.op.offline_inst:
11728
      self.cfg.MarkInstanceOffline(instance.name)
11729
      result.append(("admin_state", constants.ADMINST_OFFLINE))
11730

  
11712 11731
    self.cfg.Update(instance, feedback_fn)
11713 11732

  
11714 11733
    assert not (self.owned_locks(locking.LEVEL_NODE_RES) or
b/lib/config.py
1193 1193
    """Mark the instance status to up in the config.
1194 1194

  
1195 1195
    """
1196
    self._SetInstanceStatus(instance_name, True)
1196
    self._SetInstanceStatus(instance_name, constants.ADMINST_UP)
1197

  
1198
  @locking.ssynchronized(_config_lock)
1199
  def MarkInstanceOffline(self, instance_name):
1200
    """Mark the instance status to down in the config.
1201

  
1202
    """
1203
    self._SetInstanceStatus(instance_name, constants.ADMINST_OFFLINE)
1197 1204

  
1198 1205
  @locking.ssynchronized(_config_lock)
1199 1206
  def RemoveInstance(self, instance_name):
b/lib/opcodes.py
1351 1351
    ("osparams", None, ht.TMaybeDict, "Per-instance OS parameters"),
1352 1352
    ("wait_for_sync", True, ht.TBool,
1353 1353
     "Whether to wait for the disk to synchronize, when changing template"),
1354
    ("offline_inst", False, ht.TBool,
1355
     "Whether to turn off the down instance completely"),
1356
    ("online_inst", False, ht.TBool,
1357
     "Whether to enable the offline instance"),
1354 1358
    ]
1355 1359
  OP_RESULT = _TSetParamsResult
1356 1360

  

Also available in: Unified diff