Revision b44bd844 lib/cmdlib.py

b/lib/cmdlib.py
73 73
#: a required instance name (for single-instance LUs)
74 74
_PInstanceName = ("instance_name", ht.NoDefault, ht.TNonEmptyString)
75 75

  
76
#: Whether to ignore offline nodes
77
_PIgnoreOfflineNodes = ("ignore_offline_nodes", False, ht.TBool)
76 78

  
77 79
#: a required node name (for single-node LUs)
78 80
_PNodeName = ("node_name", ht.NoDefault, ht.TNonEmptyString)
......
4413 4415
  _OP_PARAMS = [
4414 4416
    _PInstanceName,
4415 4417
    _PForce,
4418
    _PIgnoreOfflineNodes,
4416 4419
    ("hvparams", ht.EmptyDict, ht.TDict),
4417 4420
    ("beparams", ht.EmptyDict, ht.TDict),
4418 4421
    ]
......
4461 4464
      hv_type.CheckParameterSyntax(filled_hvp)
4462 4465
      _CheckHVParams(self, instance.all_nodes, instance.hypervisor, filled_hvp)
4463 4466

  
4464
    _CheckNodeOnline(self, instance.primary_node)
4467
    self.primary_offline = self.cfg.GetNodeInfo(instance.primary_node).offline
4465 4468

  
4466
    bep = self.cfg.GetClusterInfo().FillBE(instance)
4467
    # check bridges existence
4468
    _CheckInstanceBridgesExist(self, instance)
4469
    if self.primary_offline and self.op.ignore_offline_nodes:
4470
      self.proc.LogWarning("Ignoring offline primary node")
4471

  
4472
      if self.op.hvparams or self.op.beparams:
4473
        self.proc.LogWarning("Overridden parameters are ignored")
4474
    else:
4475
      _CheckNodeOnline(self, instance.primary_node)
4476

  
4477
      bep = self.cfg.GetClusterInfo().FillBE(instance)
4469 4478

  
4470
    remote_info = self.rpc.call_instance_info(instance.primary_node,
4471
                                              instance.name,
4472
                                              instance.hypervisor)
4473
    remote_info.Raise("Error checking node %s" % instance.primary_node,
4474
                      prereq=True, ecode=errors.ECODE_ENVIRON)
4475
    if not remote_info.payload: # not running already
4476
      _CheckNodeFreeMemory(self, instance.primary_node,
4477
                           "starting instance %s" % instance.name,
4478
                           bep[constants.BE_MEMORY], instance.hypervisor)
4479
      # check bridges existence
4480
      _CheckInstanceBridgesExist(self, instance)
4481

  
4482
      remote_info = self.rpc.call_instance_info(instance.primary_node,
4483
                                                instance.name,
4484
                                                instance.hypervisor)
4485
      remote_info.Raise("Error checking node %s" % instance.primary_node,
4486
                        prereq=True, ecode=errors.ECODE_ENVIRON)
4487
      if not remote_info.payload: # not running already
4488
        _CheckNodeFreeMemory(self, instance.primary_node,
4489
                             "starting instance %s" % instance.name,
4490
                             bep[constants.BE_MEMORY], instance.hypervisor)
4479 4491

  
4480 4492
  def Exec(self, feedback_fn):
4481 4493
    """Start the instance.
......
4486 4498

  
4487 4499
    self.cfg.MarkInstanceUp(instance.name)
4488 4500

  
4489
    node_current = instance.primary_node
4501
    if self.primary_offline:
4502
      assert self.op.ignore_offline_nodes
4503
      self.proc.LogInfo("Primary node offline, marked instance as started")
4504
    else:
4505
      node_current = instance.primary_node
4490 4506

  
4491
    _StartInstanceDisks(self, instance, force)
4507
      _StartInstanceDisks(self, instance, force)
4492 4508

  
4493
    result = self.rpc.call_instance_start(node_current, instance,
4494
                                          self.op.hvparams, self.op.beparams)
4495
    msg = result.fail_msg
4496
    if msg:
4497
      _ShutdownInstanceDisks(self, instance)
4498
      raise errors.OpExecError("Could not start instance: %s" % msg)
4509
      result = self.rpc.call_instance_start(node_current, instance,
4510
                                            self.op.hvparams, self.op.beparams)
4511
      msg = result.fail_msg
4512
      if msg:
4513
        _ShutdownInstanceDisks(self, instance)
4514
        raise errors.OpExecError("Could not start instance: %s" % msg)
4499 4515

  
4500 4516

  
4501 4517
class LURebootInstance(LogicalUnit):
......
4587 4603
  HTYPE = constants.HTYPE_INSTANCE
4588 4604
  _OP_PARAMS = [
4589 4605
    _PInstanceName,
4606
    _PIgnoreOfflineNodes,
4590 4607
    ("timeout", constants.DEFAULT_SHUTDOWN_TIMEOUT, ht.TPositiveInt),
4591 4608
    ]
4592 4609
  REQ_BGL = False
......
4614 4631
    self.instance = self.cfg.GetInstanceInfo(self.op.instance_name)
4615 4632
    assert self.instance is not None, \
4616 4633
      "Cannot retrieve locked instance %s" % self.op.instance_name
4617
    _CheckNodeOnline(self, self.instance.primary_node)
4634

  
4635
    self.primary_offline = \
4636
      self.cfg.GetNodeInfo(self.instance.primary_node).offline
4637

  
4638
    if self.primary_offline and self.op.ignore_offline_nodes:
4639
      self.proc.LogWarning("Ignoring offline primary node")
4640
    else:
4641
      _CheckNodeOnline(self, self.instance.primary_node)
4618 4642

  
4619 4643
  def Exec(self, feedback_fn):
4620 4644
    """Shutdown the instance.
......
4623 4647
    instance = self.instance
4624 4648
    node_current = instance.primary_node
4625 4649
    timeout = self.op.timeout
4650

  
4626 4651
    self.cfg.MarkInstanceDown(instance.name)
4627
    result = self.rpc.call_instance_shutdown(node_current, instance, timeout)
4628
    msg = result.fail_msg
4629
    if msg:
4630
      self.proc.LogWarning("Could not shutdown instance: %s" % msg)
4631 4652

  
4632
    _ShutdownInstanceDisks(self, instance)
4653
    if self.primary_offline:
4654
      assert self.op.ignore_offline_nodes
4655
      self.proc.LogInfo("Primary node offline, marked instance as stopped")
4656
    else:
4657
      result = self.rpc.call_instance_shutdown(node_current, instance, timeout)
4658
      msg = result.fail_msg
4659
      if msg:
4660
        self.proc.LogWarning("Could not shutdown instance: %s" % msg)
4661

  
4662
      _ShutdownInstanceDisks(self, instance)
4633 4663

  
4634 4664

  
4635 4665
class LUReinstallInstance(LogicalUnit):

Also available in: Unified diff