Revision e11a1b77 lib/config.py

b/lib/config.py
864 864
    """
865 865
    return self._config_data.cluster.primary_ip_family
866 866

  
867
  @locking.ssynchronized(_config_lock)
868
  def AddNodeGroup(self, group, ec_id, check_uuid=True):
869
    """Add a node group to the configuration.
870

  
871
    @type group: L{objects.NodeGroup}
872
    @param group: the NodeGroup object to add
873
    @type ec_id: string
874
    @param ec_id: unique id for the job to use when creating a missing UUID
875
    @type check_uuid: bool
876
    @param check_uuid: add an UUID to the group if it doesn't have one or, if
877
                       it does, ensure that it does not exist in the
878
                       configuration already
879

  
880
    """
881
    self._UnlockedAddNodeGroup(group, ec_id, check_uuid)
882
    self._WriteConfig()
883

  
884
  def _UnlockedAddNodeGroup(self, group, ec_id, check_uuid):
885
    """Add a node group to the configuration.
886

  
887
    """
888
    logging.info("Adding node group %s to configuration", group.name)
889

  
890
    # Some code might need to add a node group with a pre-populated UUID
891
    # generated with ConfigWriter.GenerateUniqueID(). We allow them to bypass
892
    # the "does this UUID" exist already check.
893
    if check_uuid:
894
      self._EnsureUUID(group, ec_id)
895

  
896
    group.serial_no = 1
897
    group.ctime = group.mtime = time.time()
898

  
899
    self._config_data.nodegroups[group.uuid] = group
900
    self._config_data.cluster.serial_no += 1
901

  
902
  @locking.ssynchronized(_config_lock)
903
  def RemoveNodeGroup(self, group_uuid):
904
    """Remove a node group from the configuration.
905

  
906
    @type group_uuid: string
907
    @param group_uuid: the UUID of the node group to remove
908

  
909
    """
910
    logging.info("Removing node group %s from configuration", group_uuid)
911

  
912
    if group_uuid not in self._config_data.nodegroups:
913
      raise errors.ConfigurationError("Unknown node group '%s'" % group_uuid)
914

  
915
    del self._config_data.nodegroups[group_uuid]
916
    self._config_data.cluster.serial_no += 1
917
    self._WriteConfig()
918

  
867 919
  @locking.ssynchronized(_config_lock, shared=1)
868 920
  def LookupNodeGroup(self, target):
869 921
    """Lookup a node group's UUID.
......
1434 1486
        item.uuid = self._GenerateUniqueID(_UPGRADE_CONFIG_JID)
1435 1487
        modified = True
1436 1488
    if not self._config_data.nodegroups:
1437
      default_nodegroup_uuid = self._GenerateUniqueID(_UPGRADE_CONFIG_JID)
1438
      default_nodegroup = objects.NodeGroup(
1439
          uuid=default_nodegroup_uuid,
1440
          name="default",
1441
          members=[],
1442
          )
1443
      self._config_data.nodegroups[default_nodegroup_uuid] = default_nodegroup
1489
      default_nodegroup = objects.NodeGroup(name="default", members=[])
1490
      self._UnlockedAddNodeGroup(default_nodegroup, _UPGRADE_CONFIG_JID, True)
1444 1491
      modified = True
1445 1492
    for node in self._config_data.nodes.values():
1446 1493
      if not node.group:
......
1712 1759
      update_serial = True
1713 1760
    elif isinstance(target, objects.Instance):
1714 1761
      test = target in self._config_data.instances.values()
1762
    elif isinstance(target, objects.NodeGroup):
1763
      test = target in self._config_data.nodegroups.values()
1715 1764
    else:
1716 1765
      raise errors.ProgrammerError("Invalid object type (%s) passed to"
1717 1766
                                   " ConfigWriter.Update" % type(target))

Also available in: Unified diff