_config_lock = locking.SharedLock()
# job id used for resource management at config upgrade time
-_UPGRADE_CONFIG_JID="jid-cfg-upgrade"
+_UPGRADE_CONFIG_JID = "jid-cfg-upgrade"
def _ValidateConfig(data):
return self._temporary_secrets.Generate(self._AllDRBDSecrets(),
utils.GenerateSecret,
ec_id)
+
def _AllLVs(self):
"""Compute the list of all LVs.
for pnum in keys:
pdata = ports[pnum]
if len(pdata) > 1:
- txt = ", ".join(["%s/%s" % val for val in pdata])
+ txt = utils.CommaJoin(["%s/%s" % val for val in pdata])
result.append("tcp/udp port %s has duplicates: %s" % (pnum, txt))
# highest used tcp port check
node.offline))
# drbd minors check
- d_map, duplicates = self._UnlockedComputeDRBDMap()
+ _, duplicates = self._UnlockedComputeDRBDMap()
for node, minor, instance_a, instance_b in duplicates:
result.append("DRBD minor %d on node %s is assigned twice to instances"
" %s and %s" % (minor, node, instance_a, instance_b))
# IP checks
- ips = { data.cluster.master_ip: ["cluster_ip"] }
- def _helper(ip, name):
- if ip in ips:
- ips[ip].append(name)
- else:
- ips[ip] = [name]
+ default_nicparams = data.cluster.nicparams[constants.PP_DEFAULT]
+ ips = {}
+
+ def _AddIpAddress(ip, name):
+ ips.setdefault(ip, []).append(name)
+
+ _AddIpAddress(data.cluster.master_ip, "cluster_ip")
for node in data.nodes.values():
- _helper(node.primary_ip, "node:%s/primary" % node.name)
+ _AddIpAddress(node.primary_ip, "node:%s/primary" % node.name)
if node.secondary_ip != node.primary_ip:
- _helper(node.secondary_ip, "node:%s/secondary" % node.name)
+ _AddIpAddress(node.secondary_ip, "node:%s/secondary" % node.name)
+
+ for instance in data.instances.values():
+ for idx, nic in enumerate(instance.nics):
+ if nic.ip is None:
+ continue
+
+ nicparams = objects.FillDict(default_nicparams, nic.nicparams)
+ nic_mode = nicparams[constants.NIC_MODE]
+ nic_link = nicparams[constants.NIC_LINK]
+
+ if nic_mode == constants.NIC_MODE_BRIDGED:
+ link = "bridge:%s" % nic_link
+ elif nic_mode == constants.NIC_MODE_ROUTED:
+ link = "route:%s" % nic_link
+ else:
+ raise errors.ProgrammerError("NIC mode '%s' not handled" % nic_mode)
+
+ _AddIpAddress("%s/%s" % (link, nic.ip),
+ "instance:%s/nic:%d" % (instance.name, idx))
for ip, owners in ips.items():
if len(owners) > 1:
result.append("IP address %s is used by multiple owners: %s" %
- (ip, ", ".join(owners)))
+ (ip, utils.CommaJoin(owners)))
+
return result
@locking.ssynchronized(_config_lock, shared=1)
"""
if not item.uuid:
item.uuid = self._GenerateUniqueID(ec_id)
- elif item.uuid in self._AllIDs(temporary=True):
- raise errors.ConfigurationError("Cannot add '%s': UUID already in use" %
- (item.name, item.uuid))
+ elif item.uuid in self._AllIDs(include_temporary=True):
+ raise errors.ConfigurationError("Cannot add '%s': UUID %s already"
+ " in use" % (item.name, item.uuid))
def _SetInstanceStatus(self, instance_name, status):
"""Set the instance's status to a given value.
return self._config_data.nodes[node_name]
-
@locking.ssynchronized(_config_lock, shared=1)
def GetNodeInfo(self, node_name):
"""Get the configuration of a node, as stored in the config.
"""
return self._config_data.nodes.keys()
-
@locking.ssynchronized(_config_lock, shared=1)
def GetNodeList(self):
"""Return the list of nodes which are in the configuration.
# only called at config init time, without the lock held
self.DropECReservations(_UPGRADE_CONFIG_JID)
-
def _DistributeConfig(self, feedback_fn):
"""Distribute the configuration to the other nodes.
config_errors = self._UnlockedVerifyConfig()
if config_errors:
errmsg = ("Configuration data is not consistent: %s" %
- (", ".join(config_errors)))
+ (utils.CommaJoin(config_errors)))
logging.critical(errmsg)
if feedback_fn:
feedback_fn(errmsg)
self._temporary_ids.DropECReservations(ec_id)
self._temporary_macs.DropECReservations(ec_id)
self._temporary_secrets.DropECReservations(ec_id)
-