Commit 295728df authored by Guido Trotter's avatar Guido Trotter
Browse files

Instance Creation: generate nics earlier

We want the real nic to be shown to the hooks and the allocators, so
we'll generate them in CheckPrereq. We also write a comment about the
race condition we generate. This race condition existed even before, so
moving this generation will just lenghen it a bit. A separate patch
mitigates its effects.

This patch also adds an ENDIF comment for a very long if, and removes a
double empty line inside the CheckPrereq function of LUCreateInstance.

Reviewed-by: iustin
parent fd965830
......@@ -4434,7 +4434,6 @@ class LUCreateInstance(LogicalUnit):
raise errors.OpPrereqError("Cluster does not support lvm-based"
" instances")
if self.op.mode == constants.INSTANCE_IMPORT:
src_node = self.op.src_node
src_path = self.op.src_path
......@@ -4500,6 +4499,7 @@ class LUCreateInstance(LogicalUnit):
nic_mac_ini = 'nic%d_mac' % idx
nic.mac = export_info.get(constants.INISECT_INS, nic_mac_ini)
# ENDIF: self.op.mode == constants.INSTANCE_IMPORT
# ip ping checks (we use the same ip that was resolved in ExpandNames)
if self.op.start and not self.op.ip_check:
raise errors.OpPrereqError("Cannot ignore IP address conflicts when"
......@@ -4510,6 +4510,18 @@ class LUCreateInstance(LogicalUnit):
raise errors.OpPrereqError("IP %s of instance %s already in use" %
(self.check_ip, self.op.instance_name))
#### mac address generation
# By generating here the mac address both the allocator and the hooks get
# the real final mac address rather than the 'auto' or 'generate' value.
# There is a race condition between the generation and the instance object
# creation, which means that we know the mac is valid now, but we're not
# sure it will be when we actually add the instance. If things go bad
# adding the instance will abort because of a duplicate mac, and the
# creation job will fail.
for nic in self.nics:
if nic.mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
nic.mac = self.cfg.GenerateMAC()
#### allocator run
if self.op.iallocator is not None:
......@@ -4599,10 +4611,6 @@ class LUCreateInstance(LogicalUnit):
instance = self.op.instance_name
pnode_name =
for nic in self.nics:
if nic.mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
nic.mac = self.cfg.GenerateMAC()
ht_kind = self.op.hypervisor
if ht_kind in constants.HTS_REQ_PORT:
network_port = self.cfg.AllocatePort()
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