188188import com .cloud .utils .exception .CloudRuntimeException ;
189189import com .cloud .utils .net .Ip ;
190190import com .cloud .utils .net .NetUtils ;
191- import com .cloud .vm .DomainRouterVO ;
192191import com .cloud .vm .Nic ;
193192import com .cloud .vm .NicProfile ;
194193import com .cloud .vm .NicVO ;
@@ -1172,8 +1171,7 @@ private IpAddress associateIP(long ipId, boolean isSystem) throws ResourceAlloca
11721171 _ipAddressDao .markAsUnavailable (ip .getId ());
11731172 if (!applyIpAssociations (network , true )) {
11741173 // if fail to apply ip assciations again, unassign ip address without updating resource
1175- // count and
1176- // generating usage event as there is no need to keep it in the db
1174+ // count and generating usage event as there is no need to keep it in the db
11771175 _ipAddressDao .unassignIpAddress (ip .getId ());
11781176 }
11791177 } catch (Exception e ) {
@@ -1189,7 +1187,6 @@ private IpAddress associateIP(long ipId, boolean isSystem) throws ResourceAlloca
11891187 public boolean releasePublicIpAddress (long addrId , long userId , Account caller ) {
11901188
11911189 boolean success = true ;
1192-
11931190 // Cleanup all ip address resources - PF/LB/Static nat rules
11941191 if (!cleanupIpResources (addrId , userId , caller )) {
11951192 success = false ;
@@ -1217,10 +1214,14 @@ public boolean releasePublicIpAddress(long addrId, long userId, Account caller)
12171214 } catch (ResourceUnavailableException e ) {
12181215 throw new CloudRuntimeException ("We should never get to here because we used true when applyIpAssociations" , e );
12191216 }
1217+ } else {
1218+ if (ip .getState () == IpAddress .State .Releasing ) {
1219+ _ipAddressDao .unassignIpAddress (ip .getId ());
1220+ }
12201221 }
12211222
12221223 if (success ) {
1223- s_logger .debug ("released a public ip id=" + addrId );
1224+ s_logger .debug ("Released a public ip id=" + addrId );
12241225 }
12251226
12261227 return success ;
@@ -2449,9 +2450,9 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
24492450
24502451 //validate vpc
24512452 if (vpcId != null ) {
2452- Vpc vpc = _vpcMgr .getVpc (vpcId );
2453+ Vpc vpc = _vpcMgr .getActiveVpc (vpcId );
24532454 if (vpc == null ) {
2454- throw new InvalidParameterValueException ("Unable to find vpc by id " + vpcId );
2455+ throw new InvalidParameterValueException ("Unable to find enabled vpc by id " + vpcId );
24552456 }
24562457 _accountMgr .checkAccess (caller , null , false , vpc );
24572458 }
@@ -2657,7 +2658,7 @@ protected Network createVpcGuestNetwork(long ntwkOffId, String name, String disp
26572658 PhysicalNetwork pNtwk , long zoneId , ACLType aclType , Boolean subdomainAccess , long vpcId )
26582659 throws ConcurrentOperationException , InsufficientCapacityException , ResourceAllocationException {
26592660
2660- Vpc vpc = _vpcMgr .getVpc (vpcId );
2661+ Vpc vpc = _vpcMgr .getActiveVpc (vpcId );
26612662 //1) Validate if network can be created for VPC
26622663 _vpcMgr .validateGuestNtkwForVpc (_configMgr .getNetworkOffering (ntwkOffId ), cidr , networkDomain , owner , vpc );
26632664
@@ -2923,6 +2924,7 @@ public List<? extends Network> searchForNetworks(ListNetworksCmd cmd) {
29232924 boolean listAll = cmd .listAll ();
29242925 boolean isRecursive = cmd .isRecursive ();
29252926 Boolean specifyIpRanges = cmd .getSpecifyIpRanges ();
2927+ Long vpcId = cmd .getVpcId ();
29262928
29272929 // 1) default is system to false if not specified
29282930 // 2) reset parameter to false if it's specified by the regular user
@@ -3026,21 +3028,25 @@ public List<? extends Network> searchForNetworks(ListNetworksCmd cmd) {
30263028 if (domainId != null ) {
30273029 networksToReturn
30283030 .addAll (listDomainLevelNetworks (
3029- buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType , physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges ), searchFilter ,
3031+ buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType ,
3032+ physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges , vpcId ), searchFilter ,
30303033 domainId ));
30313034 }
30323035
30333036 if (!permittedAccounts .isEmpty ()) {
30343037 networksToReturn .addAll (listAccountSpecificNetworks (
3035- buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType , physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges ), searchFilter ,
3038+ buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType ,
3039+ physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges , vpcId ), searchFilter ,
30363040 permittedAccounts ));
30373041 } else if (domainId == null || listAll ) {
30383042 networksToReturn .addAll (listAccountSpecificNetworksByDomainPath (
3039- buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType , physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges ), searchFilter , path ,
3043+ buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType ,
3044+ physicalNetworkId , aclType , skipProjectNetworks , restartRequired , specifyIpRanges , vpcId ), searchFilter , path ,
30403045 isRecursive ));
30413046 }
30423047 } else {
3043- networksToReturn = _networksDao .search (buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId , guestIpType , trafficType , physicalNetworkId , null , skipProjectNetworks , restartRequired , specifyIpRanges ),
3048+ networksToReturn = _networksDao .search (buildNetworkSearchCriteria (sb , keyword , id , isSystem , zoneId ,
3049+ guestIpType , trafficType , physicalNetworkId , null , skipProjectNetworks , restartRequired , specifyIpRanges , vpcId ),
30443050 searchFilter );
30453051 }
30463052
@@ -3070,8 +3076,9 @@ public List<? extends Network> searchForNetworks(ListNetworksCmd cmd) {
30703076 }
30713077 }
30723078
3073- private SearchCriteria <NetworkVO > buildNetworkSearchCriteria (SearchBuilder <NetworkVO > sb , String keyword , Long id , Boolean isSystem , Long zoneId , String guestIpType , String trafficType , Long physicalNetworkId ,
3074- String aclType , boolean skipProjectNetworks , Boolean restartRequired , Boolean specifyIpRanges ) {
3079+ private SearchCriteria <NetworkVO > buildNetworkSearchCriteria (SearchBuilder <NetworkVO > sb , String keyword , Long id ,
3080+ Boolean isSystem , Long zoneId , String guestIpType , String trafficType , Long physicalNetworkId ,
3081+ String aclType , boolean skipProjectNetworks , Boolean restartRequired , Boolean specifyIpRanges , Long vpcId ) {
30753082 SearchCriteria <NetworkVO > sc = sb .create ();
30763083
30773084 if (isSystem != null ) {
@@ -3119,6 +3126,10 @@ private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<Netwo
31193126 if (specifyIpRanges != null ) {
31203127 sc .addAnd ("specifyIpRanges" , SearchCriteria .Op .EQ , specifyIpRanges );
31213128 }
3129+
3130+ if (vpcId != null ) {
3131+ sc .addAnd ("vpcId" , SearchCriteria .Op .EQ , vpcId );
3132+ }
31223133
31233134 return sc ;
31243135 }
0 commit comments