Revision 3dcbd510 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
1338 | 1338 |
@type vcpus: string |
1339 | 1339 |
@param vcpus: the count of VCPUs the instance has |
1340 | 1340 |
@type nics: list |
1341 |
@param nics: list of tuples (ip, mac, mode, link) representing |
|
1341 |
@param nics: list of tuples (ip, mac, mode, link, network) representing
|
|
1342 | 1342 |
the NICs the instance has |
1343 | 1343 |
@type disk_template: string |
1344 | 1344 |
@param disk_template: the disk template of the instance |
... | ... | |
1373 | 1373 |
} |
1374 | 1374 |
if nics: |
1375 | 1375 |
nic_count = len(nics) |
1376 |
for idx, (ip, mac, mode, link) in enumerate(nics): |
|
1376 |
for idx, (ip, mac, mode, link, network) in enumerate(nics):
|
|
1377 | 1377 |
if ip is None: |
1378 | 1378 |
ip = "" |
1379 | 1379 |
env["INSTANCE_NIC%d_IP" % idx] = ip |
1380 | 1380 |
env["INSTANCE_NIC%d_MAC" % idx] = mac |
1381 | 1381 |
env["INSTANCE_NIC%d_MODE" % idx] = mode |
1382 | 1382 |
env["INSTANCE_NIC%d_LINK" % idx] = link |
1383 |
env["INSTANCE_NIC%d_NETWORK" % idx] = network |
|
1383 | 1384 |
if mode == constants.NIC_MODE_BRIDGED: |
1384 | 1385 |
env["INSTANCE_NIC%d_BRIDGE" % idx] = link |
1385 | 1386 |
else: |
... | ... | |
1429 | 1430 |
filled_params = cluster.SimpleFillNIC(nic.nicparams) |
1430 | 1431 |
mode = filled_params[constants.NIC_MODE] |
1431 | 1432 |
link = filled_params[constants.NIC_LINK] |
1432 |
hooks_nics.append((ip, mac, mode, link)) |
|
1433 |
network = nic.network |
|
1434 |
hooks_nics.append((ip, mac, mode, link, network)) |
|
1433 | 1435 |
return hooks_nics |
1434 | 1436 |
|
1435 | 1437 |
|
... | ... | |
9423 | 9425 |
"""Run the allocator based on input opcode. |
9424 | 9426 |
|
9425 | 9427 |
""" |
9428 |
#TODO Export network to iallocator so that it chooses a pnode |
|
9429 |
# in a nodegroup that has the desired network connected to |
|
9426 | 9430 |
nics = [n.ToDict() for n in self.nics] |
9427 | 9431 |
ial = IAllocator(self.cfg, self.rpc, |
9428 | 9432 |
mode=constants.IALLOCATOR_MODE_ALLOC, |
... | ... | |
9756 | 9760 |
if nic_mode is None or nic_mode == constants.VALUE_AUTO: |
9757 | 9761 |
nic_mode = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_MODE] |
9758 | 9762 |
|
9759 |
# in routed mode, for the first nic, the default ip is 'auto' |
|
9760 |
if nic_mode == constants.NIC_MODE_ROUTED and idx == 0: |
|
9761 |
default_ip_mode = constants.VALUE_AUTO |
|
9763 |
net = nic.get(constants.INIC_NETWORK, None) |
|
9764 |
link = nic.get(constants.NIC_LINK, None) |
|
9765 |
ip = nic.get(constants.INIC_IP, None) |
|
9766 |
|
|
9767 |
if net is None or net.lower() == constants.VALUE_NONE: |
|
9768 |
net = None |
|
9762 | 9769 |
else: |
9763 |
default_ip_mode = constants.VALUE_NONE |
|
9770 |
if nic_mode_req is not None or link is not None: |
|
9771 |
raise errors.OpPrereqError("If network is given, no mode or link" |
|
9772 |
" is allowed to be passed", |
|
9773 |
errors.ECODE_INVAL) |
|
9764 | 9774 |
|
9765 | 9775 |
# ip validity checks |
9766 |
ip = nic.get(constants.INIC_IP, default_ip_mode) |
|
9767 | 9776 |
if ip is None or ip.lower() == constants.VALUE_NONE: |
9768 | 9777 |
nic_ip = None |
9769 | 9778 |
elif ip.lower() == constants.VALUE_AUTO: |
... | ... | |
9773 | 9782 |
errors.ECODE_INVAL) |
9774 | 9783 |
nic_ip = self.hostname1.ip |
9775 | 9784 |
else: |
9776 |
if not netutils.IPAddress.IsValid(ip): |
|
9785 |
# We defer pool operations until later, so that the iallocator has |
|
9786 |
# filled in the instance's node(s) dimara |
|
9787 |
if ip.lower() == constants.NIC_IP_POOL: |
|
9788 |
if net is None: |
|
9789 |
raise errors.OpPrereqError("if ip=pool, parameter network" |
|
9790 |
" must be passed too", |
|
9791 |
errors.ECODE_INVAL) |
|
9792 |
|
|
9793 |
elif not netutils.IPAddress.IsValid(ip): |
|
9777 | 9794 |
raise errors.OpPrereqError("Invalid IP address '%s'" % ip, |
9778 | 9795 |
errors.ECODE_INVAL) |
9796 |
|
|
9779 | 9797 |
nic_ip = ip |
9780 | 9798 |
|
9781 | 9799 |
# TODO: check the ip address for uniqueness |
... | ... | |
9796 | 9814 |
errors.ECODE_NOTUNIQUE) |
9797 | 9815 |
|
9798 | 9816 |
# Build nic parameters |
9799 |
link = nic.get(constants.INIC_LINK, None) |
|
9800 |
if link == constants.VALUE_AUTO: |
|
9801 |
link = cluster.nicparams[constants.PP_DEFAULT][constants.NIC_LINK] |
|
9802 | 9817 |
nicparams = {} |
9803 | 9818 |
if nic_mode_req: |
9804 | 9819 |
nicparams[constants.NIC_MODE] = nic_mode |
... | ... | |
9807 | 9822 |
|
9808 | 9823 |
check_params = cluster.SimpleFillNIC(nicparams) |
9809 | 9824 |
objects.NIC.CheckParameterSyntax(check_params) |
9810 |
self.nics.append(objects.NIC(mac=mac, ip=nic_ip, nicparams=nicparams)) |
|
9825 |
self.nics.append(objects.NIC(mac=mac, ip=nic_ip, |
|
9826 |
network=net, nicparams=check_params)) |
|
9811 | 9827 |
|
9812 | 9828 |
# disk checks/pre-build |
9813 | 9829 |
default_vg = self.cfg.GetVGName() |
... | ... | |
9910 | 9926 |
|
9911 | 9927 |
self.secondaries = [] |
9912 | 9928 |
|
9929 |
# Fill in any IPs from IP pools. This must happen here, because we need to |
|
9930 |
# know the nic's primary node, as specified by the iallocator |
|
9931 |
for idx, nic in enumerate(self.nics): |
|
9932 |
net = nic.network |
|
9933 |
if net is not None: |
|
9934 |
netparams = self.cfg.GetGroupNetParams(net, self.pnode.name) |
|
9935 |
if netparams is None: |
|
9936 |
raise errors.OpPrereqError("No netparams found for network" |
|
9937 |
" %s. Propably not connected to" |
|
9938 |
" node's %s nodegroup" % |
|
9939 |
(net, self.pnode.name), |
|
9940 |
errors.ECODE_INVAL) |
|
9941 |
self.LogInfo("NIC/%d inherits netparams %s" % |
|
9942 |
(idx, netparams.values())) |
|
9943 |
nic.nicparams = dict(netparams) |
|
9944 |
if nic.ip is not None: |
|
9945 |
filled_params = cluster.SimpleFillNIC(nic.nicparams) |
|
9946 |
if nic.ip.lower() == constants.NIC_IP_POOL: |
|
9947 |
try: |
|
9948 |
nic.ip = self.cfg.GenerateIp(net, self.proc.GetECId()) |
|
9949 |
except errors.ReservationError: |
|
9950 |
raise errors.OpPrereqError("Unable to get a free IP for NIC %d" |
|
9951 |
" from the address pool" % idx, |
|
9952 |
errors.ECODE_STATE) |
|
9953 |
self.LogInfo("Chose IP %s from network %s", nic.ip, net) |
|
9954 |
else: |
|
9955 |
try: |
|
9956 |
self.cfg.ReserveIp(net, nic.ip, self.proc.GetECId()) |
|
9957 |
except errors.ReservationError: |
|
9958 |
raise errors.OpPrereqError("IP address %s already in use" |
|
9959 |
" or does not belong to network %s" % |
|
9960 |
(nic.ip, net), |
|
9961 |
errors.ECODE_NOTUNIQUE) |
|
9962 |
else: |
|
9963 |
# net is None, ip None or given |
|
9964 |
if self.op.conflicts_check: |
|
9965 |
_CheckForConflictingIp(self, nic.ip, self.pnode.name) |
|
9966 |
|
|
9967 |
|
|
9913 | 9968 |
# mirror node verification |
9914 | 9969 |
if self.op.disk_template in constants.DTS_INT_MIRROR: |
9915 | 9970 |
if self.op.snode == pnode.name: |
... | ... | |
14945 | 15000 |
"ip": nic.ip, |
14946 | 15001 |
"mode": filled_params[constants.NIC_MODE], |
14947 | 15002 |
"link": filled_params[constants.NIC_LINK], |
15003 |
"network": nic.network, |
|
14948 | 15004 |
} |
14949 | 15005 |
if filled_params[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
14950 | 15006 |
nic_dict["bridge"] = filled_params[constants.NIC_LINK] |
... | ... | |
15982 | 16038 |
except KeyError: |
15983 | 16039 |
raise errors.OpPrereqError("Unknown query resource '%s'" % name, |
15984 | 16040 |
errors.ECODE_INVAL) |
16041 |
|
|
16042 |
def _CheckForConflictingIp(lu, ip, node): |
|
16043 |
"""In case of conflicting ip raise error. |
|
16044 |
|
|
16045 |
@type ip: string |
|
16046 |
@param ip: ip address |
|
16047 |
@type node: string |
|
16048 |
@param node: node name |
|
16049 |
|
|
16050 |
""" |
|
16051 |
(conf_net, conf_netparams) = lu.cfg.CheckIPInNodeGroup(ip, node) |
|
16052 |
if conf_net is not None: |
|
16053 |
raise errors.OpPrereqError("Conflicting IP found:" |
|
16054 |
" %s <> %s." % (ip, conf_net), |
|
16055 |
errors.ECODE_INVAL) |
|
16056 |
|
|
16057 |
return (None, None) |
Also available in: Unified diff