Revision e8e079f3 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
1340 | 1340 |
@type vcpus: string |
1341 | 1341 |
@param vcpus: the count of VCPUs the instance has |
1342 | 1342 |
@type nics: list |
1343 |
@param nics: list of tuples (ip, mac, mode, link) representing |
|
1343 |
@param nics: list of tuples (ip, mac, mode, link, network) representing
|
|
1344 | 1344 |
the NICs the instance has |
1345 | 1345 |
@type disk_template: string |
1346 | 1346 |
@param disk_template: the disk template of the instance |
... | ... | |
1375 | 1375 |
} |
1376 | 1376 |
if nics: |
1377 | 1377 |
nic_count = len(nics) |
1378 |
for idx, (ip, mac, mode, link) in enumerate(nics): |
|
1378 |
for idx, (ip, mac, mode, link, network) in enumerate(nics):
|
|
1379 | 1379 |
if ip is None: |
1380 | 1380 |
ip = "" |
1381 | 1381 |
env["INSTANCE_NIC%d_IP" % idx] = ip |
1382 | 1382 |
env["INSTANCE_NIC%d_MAC" % idx] = mac |
1383 | 1383 |
env["INSTANCE_NIC%d_MODE" % idx] = mode |
1384 | 1384 |
env["INSTANCE_NIC%d_LINK" % idx] = link |
1385 |
env["INSTANCE_NIC%d_NETWORK" % idx] = network |
|
1385 | 1386 |
if mode == constants.NIC_MODE_BRIDGED: |
1386 | 1387 |
env["INSTANCE_NIC%d_BRIDGE" % idx] = link |
1387 | 1388 |
else: |
... | ... | |
1431 | 1432 |
filled_params = cluster.SimpleFillNIC(nic.nicparams) |
1432 | 1433 |
mode = filled_params[constants.NIC_MODE] |
1433 | 1434 |
link = filled_params[constants.NIC_LINK] |
1434 |
hooks_nics.append((ip, mac, mode, link)) |
|
1435 |
network = nic.network |
|
1436 |
hooks_nics.append((ip, mac, mode, link, network)) |
|
1435 | 1437 |
return hooks_nics |
1436 | 1438 |
|
1437 | 1439 |
|
... | ... | |
9411 | 9413 |
if nic_mode is None or nic_mode == constants.VALUE_AUTO: |
9412 | 9414 |
nic_mode = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_MODE] |
9413 | 9415 |
|
9414 |
# in routed mode, for the first nic, the default ip is 'auto' |
|
9415 |
if nic_mode == constants.NIC_MODE_ROUTED and idx == 0: |
|
9416 |
default_ip_mode = constants.VALUE_AUTO |
|
9416 |
net = nic.get(constants.INIC_NETWORK, None) |
|
9417 |
link = nic.get(constants.NIC_LINK, None) |
|
9418 |
ip = nic.get(constants.INIC_IP, None) |
|
9419 |
|
|
9420 |
if net is None or net.lower() == constants.VALUE_NONE: |
|
9421 |
net = None |
|
9417 | 9422 |
else: |
9418 |
default_ip_mode = constants.VALUE_NONE |
|
9423 |
if nic_mode_req is not None or link is not None: |
|
9424 |
raise errors.OpPrereqError("If network is given, no mode or link" |
|
9425 |
" is allowed to be passed", |
|
9426 |
errors.ECODE_INVAL) |
|
9419 | 9427 |
|
9420 | 9428 |
# ip validity checks |
9421 |
ip = nic.get(constants.INIC_IP, default_ip_mode) |
|
9422 | 9429 |
if ip is None or ip.lower() == constants.VALUE_NONE: |
9423 | 9430 |
nic_ip = None |
9424 | 9431 |
elif ip.lower() == constants.VALUE_AUTO: |
... | ... | |
9428 | 9435 |
errors.ECODE_INVAL) |
9429 | 9436 |
nic_ip = default_ip |
9430 | 9437 |
else: |
9431 |
if not netutils.IPAddress.IsValid(ip): |
|
9438 |
# We defer pool operations until later, so that the iallocator has |
|
9439 |
# filled in the instance's node(s) dimara |
|
9440 |
if ip.lower() == constants.NIC_IP_POOL: |
|
9441 |
if net is None: |
|
9442 |
raise errors.OpPrereqError("if ip=pool, parameter network" |
|
9443 |
" must be passed too", |
|
9444 |
errors.ECODE_INVAL) |
|
9445 |
|
|
9446 |
elif not netutils.IPAddress.IsValid(ip): |
|
9432 | 9447 |
raise errors.OpPrereqError("Invalid IP address '%s'" % ip, |
9433 | 9448 |
errors.ECODE_INVAL) |
9449 |
|
|
9434 | 9450 |
nic_ip = ip |
9435 | 9451 |
|
9436 | 9452 |
# TODO: check the ip address for uniqueness |
... | ... | |
9452 | 9468 |
errors.ECODE_NOTUNIQUE) |
9453 | 9469 |
|
9454 | 9470 |
# Build nic parameters |
9455 |
link = nic.get(constants.INIC_LINK, None) |
|
9456 |
if link == constants.VALUE_AUTO: |
|
9457 |
link = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_LINK] |
|
9458 | 9471 |
nicparams = {} |
9459 | 9472 |
if nic_mode_req: |
9460 | 9473 |
nicparams[constants.NIC_MODE] = nic_mode |
... | ... | |
9749 | 9762 |
"""Run the allocator based on input opcode. |
9750 | 9763 |
|
9751 | 9764 |
""" |
9765 |
#TODO Export network to iallocator so that it chooses a pnode |
|
9766 |
# in a nodegroup that has the desired network connected to |
|
9752 | 9767 |
req = _CreateInstanceAllocRequest(self.op, self.disks, |
9753 | 9768 |
self.nics, self.be_full) |
9754 | 9769 |
ial = iallocator.IAllocator(self.cfg, self.rpc, req) |
... | ... | |
10138 | 10153 |
|
10139 | 10154 |
self.secondaries = [] |
10140 | 10155 |
|
10156 |
# Fill in any IPs from IP pools. This must happen here, because we need to |
|
10157 |
# know the nic's primary node, as specified by the iallocator |
|
10158 |
for idx, nic in enumerate(self.nics): |
|
10159 |
net = nic.network |
|
10160 |
if net is not None: |
|
10161 |
netparams = self.cfg.GetGroupNetParams(net, self.pnode.name) |
|
10162 |
if netparams is None: |
|
10163 |
raise errors.OpPrereqError("No netparams found for network" |
|
10164 |
" %s. Propably not connected to" |
|
10165 |
" node's %s nodegroup" % |
|
10166 |
(net, self.pnode.name), |
|
10167 |
errors.ECODE_INVAL) |
|
10168 |
self.LogInfo("NIC/%d inherits netparams %s" % |
|
10169 |
(idx, netparams.values())) |
|
10170 |
nic.nicparams = dict(netparams) |
|
10171 |
if nic.ip is not None: |
|
10172 |
filled_params = cluster.SimpleFillNIC(nic.nicparams) |
|
10173 |
if nic.ip.lower() == constants.NIC_IP_POOL: |
|
10174 |
try: |
|
10175 |
nic.ip = self.cfg.GenerateIp(net, self.proc.GetECId()) |
|
10176 |
except errors.ReservationError: |
|
10177 |
raise errors.OpPrereqError("Unable to get a free IP for NIC %d" |
|
10178 |
" from the address pool" % idx, |
|
10179 |
errors.ECODE_STATE) |
|
10180 |
self.LogInfo("Chose IP %s from network %s", nic.ip, net) |
|
10181 |
else: |
|
10182 |
try: |
|
10183 |
self.cfg.ReserveIp(net, nic.ip, self.proc.GetECId()) |
|
10184 |
except errors.ReservationError: |
|
10185 |
raise errors.OpPrereqError("IP address %s already in use" |
|
10186 |
" or does not belong to network %s" % |
|
10187 |
(nic.ip, net), |
|
10188 |
errors.ECODE_NOTUNIQUE) |
|
10189 |
else: |
|
10190 |
# net is None, ip None or given |
|
10191 |
if self.op.conflicts_check: |
|
10192 |
_CheckForConflictingIp(self, nic.ip, self.pnode.name) |
|
10193 |
|
|
10194 |
|
|
10141 | 10195 |
# mirror node verification |
10142 | 10196 |
if self.op.disk_template in constants.DTS_INT_MIRROR: |
10143 | 10197 |
if self.op.snode == pnode.name: |
... | ... | |
15943 | 15997 |
except KeyError: |
15944 | 15998 |
raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
15945 | 15999 |
errors.ECODE_INVAL) |
16000 |
|
|
16001 |
def _CheckForConflictingIp(lu, ip, node): |
|
16002 |
"""In case of conflicting ip raise error. |
|
16003 |
|
|
16004 |
@type ip: string |
|
16005 |
@param ip: ip address |
|
16006 |
@type node: string |
|
16007 |
@param node: node name |
|
16008 |
|
|
16009 |
""" |
|
16010 |
(conf_net, conf_netparams) = lu.cfg.CheckIPInNodeGroup(ip, node) |
|
16011 |
if conf_net is not None: |
|
16012 |
raise errors.OpPrereqError("Conflicting IP found:" |
|
16013 |
" %s <> %s." % (ip, conf_net), |
|
16014 |
errors.ECODE_INVAL) |
|
16015 |
|
|
16016 |
return (None, None) |
Also available in: Unified diff