VPC: CS-15668 - IpAssoc: unplug the nics before pluggning new ones

This commit is contained in:
Alena Prokharchyk 2012-07-23 16:18:04 -07:00
parent f1e2be7157
commit 46cd99f01e
4 changed files with 20 additions and 60 deletions

View File

@ -296,7 +296,8 @@ public class NicProfile {
@Override
public String toString() {
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").append(reservationId).toString();
return new StringBuilder("NicProfile[").append(id).append("-").append(vmId).append("-").
append(reservationId).append("-").append(ip4Address).append("-").append(broadcastUri).toString();
}
}

View File

@ -1871,7 +1871,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
InsufficientAddressCapacityException, ConcurrentOperationException{
NetworkVO ntwkVO = _networksDao.findById(network.getId());
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network);
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested);
NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName());
if (requested != null && requested.getMode() == null) {
@ -7427,7 +7427,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//1) allocate nic (if needed)
if (nic == null) {
s_logger.debug("Allocating nic for the " + vm + " in network " + network);
int deviceId = _nicDao.countNics(vm.getId());
nic = allocateNic(requested, network, false,
@ -7453,9 +7452,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
NicProfile nic = null;
if (requested != null && requested.getBroadCastUri() != null) {
String broadcastUri = requested.getBroadCastUri().toString();
String ipAddress = requested.getIp4Address();
NicVO nicVO = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
if (nicVO != null) {
nic = getNicProfile(vm, network.getId());
if (ipAddress == null || nicVO.getIp4Address().equals(ipAddress)) {
nic = getNicProfile(vm, network.getId());
}
}
} else {
NicVO nicVO = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getId());

View File

@ -538,46 +538,17 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
Map<String, PublicIpAddress> nicsToPlug = nicsToChange.first();
Map<String, PublicIpAddress> nicsToUnplug = nicsToChange.second();
//find out nics to unplug
for (PublicIpAddress ip : ipAddress) {
long publicNtwkId = ip.getNetworkId();
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
if (!_networkMgr.ipUsedInVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
if (ip.getState() == IpAddress.State.Releasing) {
Nic nic = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, router.getId(), ip.getAddress().addr());
if (nic != null) {
nicsToUnplug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to unplug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() +
" in public network id =" + publicNtwkId);
}
}
}
//find out nics to plug
for (PublicIpAddress ip : ipAddress) {
URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag());
long publicNtwkId = ip.getNetworkId();
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
if (!_networkMgr.ipUsedInVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) {
//nic has to be plugged only when there are no nics for this vlan tag exist on VR
Nic nic = _nicDao.findByInstanceIdNetworkIdAndBroadcastUri(publicNtwkId, router.getId(),
broadcastUri.toString());
if ((nic == null && nicsToPlug.get(ip.getVlanTag()) == null) || nicsToUnplug.get(ip.getVlanTag()) != null) {
nicsToPlug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to plug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() +
" in public network id =" + publicNtwkId);
}
//1) Unplug the nics
for (String vlanTag : nicsToUnplug.keySet()) {
Network publicNtwk = null;
try {
publicNtwk = _networkMgr.getNetwork(nicsToUnplug.get(vlanTag).getNetworkId());
URI broadcastUri = BroadcastDomainType.Vlan.toUri(vlanTag);
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to remove router " + router + " from vlan " + vlanTag +
" in public network " + publicNtwk + " due to ", e);
return false;
}
}
@ -627,20 +598,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
});
//4) Unplug the nics
for (String vlanTag : nicsToUnplug.keySet()) {
Network publicNtwk = null;
try {
publicNtwk = _networkMgr.getNetwork(nicsToUnplug.get(vlanTag).getNetworkId());
URI broadcastUri = BroadcastDomainType.Vlan.toUri(vlanTag);
_itMgr.removeVmFromNetwork(router, publicNtwk, broadcastUri);
} catch (ConcurrentOperationException e) {
s_logger.warn("Failed to remove router " + router + " from vlan " + vlanTag +
" in public network " + publicNtwk + " due to ", e);
return false;
}
}
return result;
}
@ -662,7 +619,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
defaultDns1 = nic.getDns1();
defaultDns2 = nic.getDns2();
}
s_logger.debug("Removing nic of type " + nic.getTrafficType() + " from the nics passed on vm start. " +
s_logger.debug("Removing nic " + nic + " of type " + nic.getTrafficType() + " from the nics passed on vm start. " +
"The nic will be plugged later");
it.remove();
}

View File

@ -2453,7 +2453,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("Adding vm " + vm + " to network " + network);
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));