X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/24818e8f214f44bd88715ccd2a787a968461a325..aff173bb7a40a59c820f53dac6e64f450a9e4dc5:/lib/config.py diff --git a/lib/config.py b/lib/config.py index 50fc784..d8c2605 100644 --- a/lib/config.py +++ b/lib/config.py @@ -96,6 +96,18 @@ class ConfigWriter: raise errors.ConfigurationError("Can't generate unique MAC") return mac + def IsMacInUse(self, mac): + """Predicate: check if the specified MAC is in use in the Ganeti cluster. + + This only checks instances managed by this cluster, it does not + check for potential collisions elsewhere. + + """ + self._OpenConfig() + self._ReleaseLock() + all_macs = self._AllMACs() + return mac in all_macs + def _ComputeAllLVs(self): """Compute the list of all LVs. @@ -168,15 +180,15 @@ class ConfigWriter: for instance_name in data.instances: instance = data.instances[instance_name] if instance.primary_node not in data.nodes: - result.append("Instance '%s' has invalid primary node '%s'" % + result.append("instance '%s' has invalid primary node '%s'" % (instance_name, instance.primary_node)) for snode in instance.secondary_nodes: if snode not in data.nodes: - result.append("Instance '%s' has invalid secondary node '%s'" % + result.append("instance '%s' has invalid secondary node '%s'" % (instance_name, snode)) for idx, nic in enumerate(instance.nics): if nic.mac in seen_macs: - result.append("Instance '%s' has NIC %d mac %s duplicate" % + result.append("instance '%s' has NIC %d mac %s duplicate" % (instance_name, idx, nic.mac)) else: seen_macs.append(nic.mac)