Revision 5a292b36 lib/cmdlib.py
b/lib/cmdlib.py | ||
---|---|---|
1557 | 1557 |
link = filled_params[constants.NIC_LINK] |
1558 | 1558 |
netinfo = None |
1559 | 1559 |
if nic.network: |
1560 |
net_uuid = lu.cfg.LookupNetwork(nic.network) |
|
1561 |
netinfo = objects.Network.ToDict(lu.cfg.GetNetwork(net_uuid)) |
|
1562 |
|
|
1560 |
nobj = lu.cfg.GetNetwork(nic.network) |
|
1561 |
netinfo = objects.Network.ToDict(nobj) |
|
1563 | 1562 |
return (nic.ip, nic.mac, mode, link, nic.network, netinfo) |
1564 | 1563 |
|
1565 | 1564 |
|
... | ... | |
9950 | 9949 |
|
9951 | 9950 |
check_params = cluster.SimpleFillNIC(nicparams) |
9952 | 9951 |
objects.NIC.CheckParameterSyntax(check_params) |
9952 |
net_uuid = cfg.LookupNetwork(net) |
|
9953 | 9953 |
nics.append(objects.NIC(mac=mac, ip=nic_ip, |
9954 |
network=net, nicparams=nicparams)) |
|
9954 |
network=net_uuid, nicparams=nicparams))
|
|
9955 | 9955 |
|
9956 | 9956 |
return nics |
9957 | 9957 |
|
... | ... | |
10687 | 10687 |
# Fill in any IPs from IP pools. This must happen here, because we need to |
10688 | 10688 |
# know the nic's primary node, as specified by the iallocator |
10689 | 10689 |
for idx, nic in enumerate(self.nics): |
10690 |
net = nic.network |
|
10691 |
if net is not None: |
|
10692 |
netparams = self.cfg.GetGroupNetParams(net, self.pnode.name) |
|
10690 |
net_uuid = nic.network |
|
10691 |
if net_uuid is not None: |
|
10692 |
nobj = self.cfg.GetNetwork(net_uuid) |
|
10693 |
netparams = self.cfg.GetGroupNetParams(net_uuid, self.pnode.name) |
|
10693 | 10694 |
if netparams is None: |
10694 | 10695 |
raise errors.OpPrereqError("No netparams found for network" |
10695 | 10696 |
" %s. Propably not connected to" |
10696 | 10697 |
" node's %s nodegroup" % |
10697 |
(net, self.pnode.name),
|
|
10698 |
(nobj.name, self.pnode.name),
|
|
10698 | 10699 |
errors.ECODE_INVAL) |
10699 | 10700 |
self.LogInfo("NIC/%d inherits netparams %s" % |
10700 | 10701 |
(idx, netparams.values())) |
... | ... | |
10702 | 10703 |
if nic.ip is not None: |
10703 | 10704 |
if nic.ip.lower() == constants.NIC_IP_POOL: |
10704 | 10705 |
try: |
10705 |
nic.ip = self.cfg.GenerateIp(net, self.proc.GetECId()) |
|
10706 |
nic.ip = self.cfg.GenerateIp(net_uuid, self.proc.GetECId())
|
|
10706 | 10707 |
except errors.ReservationError: |
10707 | 10708 |
raise errors.OpPrereqError("Unable to get a free IP for NIC %d" |
10708 | 10709 |
" from the address pool" % idx, |
10709 | 10710 |
errors.ECODE_STATE) |
10710 |
self.LogInfo("Chose IP %s from network %s", nic.ip, net)
|
|
10711 |
self.LogInfo("Chose IP %s from network %s", nic.ip, nobj.name)
|
|
10711 | 10712 |
else: |
10712 | 10713 |
try: |
10713 |
self.cfg.ReserveIp(net, nic.ip, self.proc.GetECId()) |
|
10714 |
self.cfg.ReserveIp(net_uuid, nic.ip, self.proc.GetECId())
|
|
10714 | 10715 |
except errors.ReservationError: |
10715 | 10716 |
raise errors.OpPrereqError("IP address %s already in use" |
10716 | 10717 |
" or does not belong to network %s" % |
10717 |
(nic.ip, net),
|
|
10718 |
(nic.ip, nobj.name),
|
|
10718 | 10719 |
errors.ECODE_NOTUNIQUE) |
10719 | 10720 |
|
10720 | 10721 |
# net is None, ip None or given |
... | ... | |
13381 | 13382 |
nl = [self.cfg.GetMasterNode()] + list(self.instance.all_nodes) |
13382 | 13383 |
return (nl, nl) |
13383 | 13384 |
|
13384 |
def _PrepareNicModification(self, params, private, old_ip, old_net, |
|
13385 |
def _PrepareNicModification(self, params, private, old_ip, old_net_uuid,
|
|
13385 | 13386 |
old_params, cluster, pnode): |
13386 | 13387 |
|
13387 | 13388 |
update_params_dict = dict([(key, params[key]) |
... | ... | |
13391 | 13392 |
req_link = update_params_dict.get(constants.NIC_LINK, None) |
13392 | 13393 |
req_mode = update_params_dict.get(constants.NIC_MODE, None) |
13393 | 13394 |
|
13394 |
new_net = params.get(constants.INIC_NETWORK, old_net) |
|
13395 |
if new_net is not None: |
|
13396 |
netparams = self.cfg.GetGroupNetParams(new_net, pnode) |
|
13397 |
if netparams is None: |
|
13395 |
new_net_uuid = None |
|
13396 |
new_net_uuid_or_name = params.get(constants.INIC_NETWORK, old_net_uuid) |
|
13397 |
if new_net_uuid_or_name: |
|
13398 |
new_net_uuid = self.cfg.LookupNetwork(new_net_uuid_or_name) |
|
13399 |
new_net_obj = self.cfg.GetNetwork(new_net_uuid) |
|
13400 |
|
|
13401 |
if old_net_uuid: |
|
13402 |
old_net_obj = self.cfg.GetNetwork(old_net_uuid) |
|
13403 |
|
|
13404 |
if new_net_uuid: |
|
13405 |
netparams = self.cfg.GetGroupNetParams(new_net_uuid, pnode) |
|
13406 |
if not netparams: |
|
13398 | 13407 |
raise errors.OpPrereqError("No netparams found for the network" |
13399 |
" %s, probably not connected" % new_net,
|
|
13400 |
errors.ECODE_INVAL) |
|
13408 |
" %s, probably not connected" % |
|
13409 |
new_net_obj.name, errors.ECODE_INVAL)
|
|
13401 | 13410 |
new_params = dict(netparams) |
13402 | 13411 |
else: |
13403 | 13412 |
new_params = _GetUpdatedParams(old_params, update_params_dict) |
... | ... | |
13436 | 13445 |
elif mac in (constants.VALUE_AUTO, constants.VALUE_GENERATE): |
13437 | 13446 |
# otherwise generate the MAC address |
13438 | 13447 |
params[constants.INIC_MAC] = \ |
13439 |
self.cfg.GenerateMAC(new_net, self.proc.GetECId()) |
|
13448 |
self.cfg.GenerateMAC(new_net_uuid, self.proc.GetECId())
|
|
13440 | 13449 |
else: |
13441 | 13450 |
# or validate/reserve the current one |
13442 | 13451 |
try: |
... | ... | |
13445 | 13454 |
raise errors.OpPrereqError("MAC address '%s' already in use" |
13446 | 13455 |
" in cluster" % mac, |
13447 | 13456 |
errors.ECODE_NOTUNIQUE) |
13448 |
elif new_net != old_net:
|
|
13457 |
elif new_net_uuid != old_net_uuid:
|
|
13449 | 13458 |
|
13450 |
def get_net_prefix(net): |
|
13459 |
def get_net_prefix(net_uuid):
|
|
13451 | 13460 |
mac_prefix = None |
13452 |
if net: |
|
13453 |
uuid = self.cfg.LookupNetwork(net)
|
|
13454 |
mac_prefix = self.cfg.GetNetwork(uuid).mac_prefix
|
|
13461 |
if net_uuid:
|
|
13462 |
nobj = self.cfg.GetNetwork(net_uuid)
|
|
13463 |
mac_prefix = nobj.mac_prefix
|
|
13455 | 13464 |
|
13456 | 13465 |
return mac_prefix |
13457 | 13466 |
|
13458 |
new_prefix = get_net_prefix(new_net) |
|
13459 |
old_prefix = get_net_prefix(old_net) |
|
13467 |
new_prefix = get_net_prefix(new_net_uuid)
|
|
13468 |
old_prefix = get_net_prefix(old_net_uuid)
|
|
13460 | 13469 |
if old_prefix != new_prefix: |
13461 | 13470 |
params[constants.INIC_MAC] = \ |
13462 |
self.cfg.GenerateMAC(new_net, self.proc.GetECId()) |
|
13471 |
self.cfg.GenerateMAC(new_net_uuid, self.proc.GetECId())
|
|
13463 | 13472 |
|
13464 |
#if there is a change in nic-network configuration
|
|
13473 |
#if there is a change in nic's ip/network configuration
|
|
13465 | 13474 |
new_ip = params.get(constants.INIC_IP, old_ip) |
13466 |
if (new_ip, new_net) != (old_ip, old_net):
|
|
13475 |
if (new_ip, new_net_uuid) != (old_ip, old_net_uuid):
|
|
13467 | 13476 |
if new_ip: |
13468 |
if new_net:
|
|
13469 |
if new_ip.lower() == constants.NIC_IP_POOL:
|
|
13470 |
try:
|
|
13471 |
new_ip = self.cfg.GenerateIp(new_net, self.proc.GetECId())
|
|
13472 |
except errors.ReservationError:
|
|
13473 |
raise errors.OpPrereqError("Unable to get a free IP"
|
|
13474 |
" from the address pool",
|
|
13475 |
errors.ECODE_STATE)
|
|
13476 |
self.LogInfo("Chose IP %s from pool %s", new_ip, new_net)
|
|
13477 |
params[constants.INIC_IP] = new_ip
|
|
13478 |
elif new_ip != old_ip or new_net != old_net:
|
|
13479 |
try:
|
|
13480 |
self.LogInfo("Reserving IP %s in pool %s", new_ip, new_net)
|
|
13481 |
self.cfg.ReserveIp(new_net, new_ip, self.proc.GetECId())
|
|
13482 |
except errors.ReservationError:
|
|
13483 |
raise errors.OpPrereqError("IP %s not available in network %s" %
|
|
13484 |
(new_ip, new_net),
|
|
13485 |
errors.ECODE_NOTUNIQUE)
|
|
13486 |
elif new_ip.lower() == constants.NIC_IP_POOL:
|
|
13487 |
raise errors.OpPrereqError("ip=pool, but no network found",
|
|
13488 |
errors.ECODE_INVAL)
|
|
13477 |
if new_ip.lower() == constants.NIC_IP_POOL:
|
|
13478 |
if not new_net_uuid:
|
|
13479 |
raise errors.OpPrereqError("ip=pool, but no network found",
|
|
13480 |
errors.ECODE_INVAL)
|
|
13481 |
try:
|
|
13482 |
new_ip = self.cfg.GenerateIp(new_net_uuid, self.proc.GetECId())
|
|
13483 |
except errors.ReservationError:
|
|
13484 |
raise errors.OpPrereqError("Unable to get a free IP"
|
|
13485 |
" from the address pool",
|
|
13486 |
errors.ECODE_STATE)
|
|
13487 |
self.LogInfo("Chose IP %s from network %s", new_ip, new_net_obj.name)
|
|
13488 |
params[constants.INIC_IP] = new_ip
|
|
13489 |
elif new_ip != old_ip or new_net_uuid != old_net_uuid:
|
|
13490 |
try:
|
|
13491 |
self.cfg.ReserveIp(new_net_uuid, new_ip, self.proc.GetECId())
|
|
13492 |
self.LogInfo("Reserving IP %s in network %s",
|
|
13493 |
new_ip, new_net_obj.name)
|
|
13494 |
except errors.ReservationError:
|
|
13495 |
raise errors.OpPrereqError("IP %s not available in network %s" %
|
|
13496 |
(new_ip, new_net_obj.name),
|
|
13497 |
errors.ECODE_NOTUNIQUE)
|
|
13489 | 13498 |
|
13490 | 13499 |
# new net is None |
13491 |
elif self.op.conflicts_check: |
|
13500 |
elif not new_net_uuid and self.op.conflicts_check:
|
|
13492 | 13501 |
_CheckForConflictingIp(self, new_ip, pnode) |
13493 | 13502 |
|
13494 |
if old_ip and old_net:
|
|
13503 |
if old_ip: |
|
13495 | 13504 |
try: |
13496 |
self.cfg.ReleaseIp(old_net, old_ip, self.proc.GetECId()) |
|
13497 |
except errors.AddressPoolError, err:
|
|
13498 |
logging.warning("Releasing IP address '%s' from network '%s'"
|
|
13499 |
" failed: %s", old_ip, old_net, err)
|
|
13505 |
self.cfg.ReleaseIp(old_net_uuid, old_ip, self.proc.GetECId())
|
|
13506 |
except errors.AddressPoolError: |
|
13507 |
logging.warning("Release IP %s not contained in network %s",
|
|
13508 |
old_ip, old_net_obj.name)
|
|
13500 | 13509 |
|
13501 | 13510 |
# there are no changes in (net, ip) tuple |
13502 |
elif (old_net is not None and |
|
13511 |
elif (old_net_uuid is not None and
|
|
13503 | 13512 |
(req_link is not None or req_mode is not None)): |
13504 | 13513 |
raise errors.OpPrereqError("Not allowed to change link or mode of" |
13505 | 13514 |
" a NIC that is connected to a network", |
... | ... | |
16795 | 16804 |
self.connected = False |
16796 | 16805 |
return |
16797 | 16806 |
|
16798 |
_NetworkConflictCheck(self, lambda nic: nic.network == self.network_name,
|
|
16807 |
_NetworkConflictCheck(self, lambda nic: nic.network == self.network_uuid,
|
|
16799 | 16808 |
"disconnect from") |
16800 | 16809 |
|
16801 | 16810 |
def Exec(self, feedback_fn): |
Also available in: Unified diff