Skip to content

Commit 46cd99f

Browse files
author
Alena Prokharchyk
committed
VPC: CS-15668 - IpAssoc: unplug the nics before pluggning new ones
1 parent f1e2be7 commit 46cd99f

4 files changed

Lines changed: 20 additions & 60 deletions

File tree

api/src/com/cloud/vm/NicProfile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ public void deallocate() {
296296

297297
@Override
298298
public String toString() {
299-
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").append(reservationId).toString();
299+
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").
300+
append(reservationId).append("-").append(ip4Address).append("-").append(broadcastUri).toString();
300301
}
301302

302303
}

server/src/com/cloud/network/NetworkManagerImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,7 @@ public Pair<NicProfile,Integer> allocateNic(NicProfile requested, Network networ
18711871
InsufficientAddressCapacityException, ConcurrentOperationException{
18721872

18731873
NetworkVO ntwkVO = _networksDao.findById(network.getId());
1874-
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network);
1874+
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
18751875
NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName());
18761876

18771877
if (requested != null && requested.getMode() == null) {
@@ -7427,7 +7427,6 @@ public NicProfile createNicForVm(Network network, NicProfile requested, Reservat
74277427

74287428
//1) allocate nic (if needed)
74297429
if (nic == null) {
7430-
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
74317430
int deviceId = _nicDao.countNics(vm.getId());
74327431

74337432
nic = allocateNic(requested, network, false,
@@ -7453,9 +7452,12 @@ private NicProfile getNicProfileForVm(Network network, NicProfile requested, Vir
74537452
NicProfile nic = null;
74547453
if (requested != null && requested.getBroadCastUri() != null) {
74557454
String broadcastUri = requested.getBroadCastUri().toString();
7455+
String ipAddress = requested.getIp4Address();
74567456
NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
74577457
if (nicVO != null) {
7458-
nic = getNicProfile(vm, network.getId());
7458+
if (ipAddress == null || nicVO.getIp4Address().equals(ipAddress)) {
7459+
nic = getNicProfile(vm, network.getId());
7460+
}
74597461
}
74607462
} else {
74617463
NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());

server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -538,46 +538,17 @@ public boolean associatePublicIP(Network network, final List<? extends PublicIpA
538538
Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
539539
Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
540540

541-
542-
//find out nics to unplug
543-
for (PublicIpAddress ip : ipAddress) {
544-
long publicNtwkId = ip.getNetworkId();
545-
546-
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
547-
if (!_networkMgr.ipUsedInVpc(ip)) {
548-
ip.setState(IpAddress.State.Releasing);
549-
}
550-
551-
if (ip.getState() == IpAddress.State.Releasing) {
552-
Nic nic = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, router.getId(), ip.getAddress().addr());
553-
if (nic != null) {
554-
nicsToUnplug.put(ip.getVlanTag(), ip);
555-
s_logger.debug("Need to unplug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() +
556-
" in public network id =" + publicNtwkId);
557-
}
558-
}
559-
}
560-
561-
//find out nics to plug
562-
for (PublicIpAddress ip : ipAddress) {
563-
URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag());
564-
long publicNtwkId = ip.getNetworkId();
565-
566-
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
567-
if (!_networkMgr.ipUsedInVpc(ip)) {
568-
ip.setState(IpAddress.State.Releasing);
569-
}
570-
571-
if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) {
572-
//nic has to be plugged only when there are no nics for this vlan tag exist on VR
573-
Nic nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(publicNtwkId, router.getId(),
574-
broadcastUri.toString());
575-
576-
if ((nic == null && nicsToPlug.get(ip.getVlanTag()) == null) || nicsToUnplug.get(ip.getVlanTag()) != null) {
577-
nicsToPlug.put(ip.getVlanTag(), ip);
578-
s_logger.debug("Need to plug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() +
579-
" in public network id =" + publicNtwkId);
580-
}
541+
//1) Unplug the nics
542+
for (String vlanTag : nicsToUnplug.keySet()) {
543+
Network publicNtwk = null;
544+
try {
545+
publicNtwk = _networkMgr.getNetwork(nicsToUnplug.get(vlanTag).getNetworkId());
546+
URI broadcastUri = BroadcastDomainType.Vlan.toUri(vlanTag);
547+
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
548+
} catch (ConcurrentOperationException e) {
549+
s_logger.warn("Failed to remove router " + router + " from vlan " + vlanTag +
550+
" in public network " + publicNtwk + " due to ", e);
551+
return false;
581552
}
582553
}
583554

@@ -627,20 +598,6 @@ public boolean execute(Network network, VirtualRouter router) throws ResourceUna
627598
}
628599
});
629600

630-
//4) Unplug the nics
631-
for (String vlanTag : nicsToUnplug.keySet()) {
632-
Network publicNtwk = null;
633-
try {
634-
publicNtwk = _networkMgr.getNetwork(nicsToUnplug.get(vlanTag).getNetworkId());
635-
URI broadcastUri = BroadcastDomainType.Vlan.toUri(vlanTag);
636-
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
637-
} catch (ConcurrentOperationException e) {
638-
s_logger.warn("Failed to remove router " + router + " from vlan " + vlanTag +
639-
" in public network " + publicNtwk + " due to ", e);
640-
return false;
641-
}
642-
}
643-
644601
return result;
645602
}
646603

@@ -662,7 +619,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterV
662619
defaultDns1 = nic.getDns1();
663620
defaultDns2 = nic.getDns2();
664621
}
665-
s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from the nics passed on vm start. " +
622+
s_logger.debug("Removing nic " + nic + " of type " + nic.getTrafficType() + " from the nics passed on vm start. " +
666623
"The nic will be plugged later");
667624
it.remove();
668625
}

server/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ public boolean upgradeVmDb(long vmId, long serviceOfferingId) {
24532453
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
24542454
ResourceUnavailableException, InsufficientCapacityException {
24552455

2456-
s_logger.debug("Adding vm " + vm + " to network " + network);
2456+
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
24572457
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
24582458
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
24592459
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));

0 commit comments

Comments
 (0)