Revision 1d4a4b26 lib/config.py

b/lib/config.py
1436 1436
      raise errors.ConfigurationError("Cannot add '%s': UUID %s already"
1437 1437
                                      " in use" % (item.name, item.uuid))
1438 1438

  
1439
  def _SetInstanceStatus(self, instance_name, status):
1439
  def _SetInstanceStatus(self, instance_name, status, disks_active):
1440 1440
    """Set the instance's status to a given value.
1441 1441

  
1442 1442
    """
1443
    assert status in constants.ADMINST_ALL, \
1444
           "Invalid status '%s' passed to SetInstanceStatus" % (status,)
1445

  
1446 1443
    if instance_name not in self._config_data.instances:
1447 1444
      raise errors.ConfigurationError("Unknown instance '%s'" %
1448 1445
                                      instance_name)
1449 1446
    instance = self._config_data.instances[instance_name]
1450
    if instance.admin_state != status:
1447

  
1448
    if status is None:
1449
      status = instance.admin_state
1450
    if disks_active is None:
1451
      disks_active = instance.disks_active
1452

  
1453
    assert status in constants.ADMINST_ALL, \
1454
           "Invalid status '%s' passed to SetInstanceStatus" % (status,)
1455

  
1456
    if instance.admin_state != status or \
1457
       instance.disks_active != disks_active:
1451 1458
      instance.admin_state = status
1459
      instance.disks_active = disks_active
1452 1460
      instance.serial_no += 1
1453 1461
      instance.mtime = time.time()
1454 1462
      self._WriteConfig()
......
1457 1465
  def MarkInstanceUp(self, instance_name):
1458 1466
    """Mark the instance status to up in the config.
1459 1467

  
1468
    This also sets the instance disks active flag.
1469

  
1460 1470
    """
1461
    self._SetInstanceStatus(instance_name, constants.ADMINST_UP)
1471
    self._SetInstanceStatus(instance_name, constants.ADMINST_UP, True)
1462 1472

  
1463 1473
  @locking.ssynchronized(_config_lock)
1464 1474
  def MarkInstanceOffline(self, instance_name):
1465 1475
    """Mark the instance status to down in the config.
1466 1476

  
1477
    This also clears the instance disks active flag.
1478

  
1467 1479
    """
1468
    self._SetInstanceStatus(instance_name, constants.ADMINST_OFFLINE)
1480
    self._SetInstanceStatus(instance_name, constants.ADMINST_OFFLINE, False)
1469 1481

  
1470 1482
  @locking.ssynchronized(_config_lock)
1471 1483
  def RemoveInstance(self, instance_name):
......
1531 1543
  def MarkInstanceDown(self, instance_name):
1532 1544
    """Mark the status of an instance to down in the configuration.
1533 1545

  
1546
    This does not touch the instance disks active flag, as shut down instances
1547
    can still have active disks.
1548

  
1549
    """
1550
    self._SetInstanceStatus(instance_name, constants.ADMINST_DOWN, None)
1551

  
1552
  @locking.ssynchronized(_config_lock)
1553
  def MarkInstanceDisksActive(self, instance_name):
1554
    """Mark the status of instance disks active.
1555

  
1556
    """
1557
    self._SetInstanceStatus(instance_name, None, True)
1558

  
1559
  @locking.ssynchronized(_config_lock)
1560
  def MarkInstanceDisksInactive(self, instance_name):
1561
    """Mark the status of instance disks inactive.
1562

  
1534 1563
    """
1535
    self._SetInstanceStatus(instance_name, constants.ADMINST_DOWN)
1564
    self._SetInstanceStatus(instance_name, None, False)
1536 1565

  
1537 1566
  def _UnlockedGetInstanceList(self):
1538 1567
    """Get the list of instances.

Also available in: Unified diff