Commit b8716596 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Re-add check for duplicate instance IP

This was originally implemented in 0ce8f948 and partially
rolled back in 9b65e0d4

. Apart from re-adding the check,
this patch does some housekeeping by renaming the “_helper”
function to “_AddIpAddress”.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarGuido Trotter <>
parent 8619a3bd
......@@ -5688,7 +5688,7 @@ class LUCreateInstance(LogicalUnit):
nic_ip = ip
# TODO: check the ip for uniqueness !!
# TODO: check the ip address for uniqueness
if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip:
raise errors.OpPrereqError("Routed nic mode requires an ip address",
......@@ -430,22 +430,43 @@ class ConfigWriter:
" %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] = [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" %
_AddIpAddress(node.primary_ip, "node:%s/primary" %
if node.secondary_ip != node.primary_ip:
_helper(node.secondary_ip, "node:%s/secondary" %
_AddIpAddress(node.secondary_ip, "node:%s/secondary" %
for instance in data.instances.values():
for idx, nic in enumerate(instance.nics):
if nic.ip is None:
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
raise errors.ProgrammerError("NIC mode '%s' not handled" % nic_mode)
_AddIpAddress("%s/%s" % (link, nic.ip),
"instance:%s/nic:%d" % (, 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)))
return result
@locking.ssynchronized(_config_lock, shared=1)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment