@@ -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 }
0 commit comments