@@ -475,7 +475,7 @@ public void createFirewallRulesCommands(final List<? extends FirewallRule> rules
475475
476476 public void createAssociateIPCommands (final VirtualRouter router , final List <? extends PublicIpAddress > ips , final Commands cmds , final long vmId ) {
477477 final String ipAssocCommand = "IPAssocCommand" ;
478- createRedundantAssociateIPCommands (router , ips , cmds , ipAssocCommand , vmId );
478+ createRedundantAssociateIPCommands (router , ips , cmds , ipAssocCommand , false );
479479 }
480480
481481 public void createNetworkACLsCommands (final List <? extends NetworkACLItem > rules , final VirtualRouter router , final Commands cmds , final long guestNetworkId ,
@@ -645,7 +645,7 @@ public void createVpcAssociatePublicIPCommands(final VirtualRouter router, final
645645
646646 final String ipAssocCommand = "IPAssocVpcCommand" ;
647647 if (router .getIsRedundantRouter ()) {
648- createRedundantAssociateIPCommands (router , ips , cmds , ipAssocCommand , 0 );
648+ createRedundantAssociateIPCommands (router , ips , cmds , ipAssocCommand , true );
649649 return ;
650650 }
651651
@@ -742,7 +742,7 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
742742 }
743743 }
744744
745- public void createRedundantAssociateIPCommands (final VirtualRouter router , final List <? extends PublicIpAddress > ips , final Commands cmds , final String ipAssocCommand , final long vmId ) {
745+ public void createRedundantAssociateIPCommands (final VirtualRouter router , final List <? extends PublicIpAddress > ips , final Commands cmds , final String ipAssocCommand , final boolean isVPC ) {
746746
747747 // Ensure that in multiple vlans case we first send all ip addresses of
748748 // vlan1, then all ip addresses of vlan2, etc..
@@ -840,7 +840,16 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
840840 }
841841
842842 // for network if the ips does not have any rules, then only last ip
843- List <IPAddressVO > userIps = _ipAddressDao .listByAssociatedNetwork (associatedWithNetworkId , null );
843+ final List <IPAddressVO > userIps = _ipAddressDao .listByAssociatedNetwork (associatedWithNetworkId , null );
844+ boolean hasSourceNat = false ;
845+ if (isVPC && userIps .size () > 0 && userIps .get (0 ) != null ) {
846+ // All ips should belong to a VPC
847+ final Long vpcId = userIps .get (0 ).getVpcId ();
848+ final List <IPAddressVO > sourceNatIps = _ipAddressDao .listByAssociatedVpc (vpcId , true );
849+ if (sourceNatIps != null && sourceNatIps .size () > 0 ) {
850+ hasSourceNat = true ;
851+ }
852+ }
844853
845854 int ipsWithrules = 0 ;
846855 int ipsStaticNat = 0 ;
@@ -864,7 +873,7 @@ public int compare(final PublicIpAddress o1, final PublicIpAddress o2) {
864873 cmd .setAccessDetail (NetworkElementCommand .ZONE_NETWORK_TYPE , dcVo .getNetworkType ().toString ());
865874
866875 // if there is 1 static nat then it will be checked for remove at the resource
867- if (ipsWithrules == 0 && ipsStaticNat == 0 ) {
876+ if (ipsWithrules == 0 && ipsStaticNat == 0 && ! hasSourceNat ) {
868877 // there is only one ip address for the network.
869878 cmd .setAccessDetail (NetworkElementCommand .NETWORK_PUB_LAST_IP , "true" );
870879 } else {
0 commit comments