Skip to content

Commit b9a4e79

Browse files
author
Alena Prokharchyk
committed
1) Added search by vpcId to listRouters/listNetworks Apis
2) Don't allow to add new networks/implement existing ones for VPC in Disabled state. Disabled state indicates that there was unsuccessful attempt to remove the VPC, and the further cleanup will be taken care of by cleanup thread. Conflicts: server/src/com/cloud/network/dao/IPAddressDao.java server/src/com/cloud/server/ManagementServerImpl.java
1 parent d5507e1 commit b9a4e79

20 files changed

Lines changed: 246 additions & 54 deletions

‎api/src/com/cloud/api/commands/ListNetworksCmd.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public class ListNetworksCmd extends BaseListProjectAndAccountResourcesCmd {
7171

7272
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if need to list only networks which support specifying ip ranges")
7373
private Boolean specifyIpRanges;
74+
75+
@IdentityMapper(entityTableName="vpc")
76+
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC")
77+
private Long vpcId;
7478

7579
/////////////////////////////////////////////////////
7680
/////////////////// Accessors ///////////////////////
@@ -116,7 +120,11 @@ public Boolean getSpecifyIpRanges() {
116120
return specifyIpRanges;
117121
}
118122

119-
/////////////////////////////////////////////////////
123+
public Long getVpcId() {
124+
return vpcId;
125+
}
126+
127+
/////////////////////////////////////////////////////
120128
/////////////// API Implementation///////////////////
121129
/////////////////////////////////////////////////////
122130
@Override

‎api/src/com/cloud/api/commands/ListRoutersCmd.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.log4j.Logger;
2323

2424
import com.cloud.api.ApiConstants;
25-
import com.cloud.api.BaseCmd.CommandType;
2625
import com.cloud.api.BaseListProjectAndAccountResourcesCmd;
2726
import com.cloud.api.IdentityMapper;
2827
import com.cloud.api.Implementation;
@@ -67,6 +66,10 @@ public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd {
6766
@IdentityMapper(entityTableName="networks")
6867
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id")
6968
private Long networkId;
69+
70+
@IdentityMapper(entityTableName="vpc")
71+
@Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="List networks by VPC")
72+
private Long vpcId;
7073

7174
/////////////////////////////////////////////////////
7275
/////////////////// Accessors ///////////////////////
@@ -99,6 +102,10 @@ public Long getZoneId() {
99102
public Long getNetworkId() {
100103
return networkId;
101104
}
105+
106+
public Long getVpcId() {
107+
return vpcId;
108+
}
102109

103110
/////////////////////////////////////////////////////
104111
/////////////// API Implementation///////////////////

‎api/src/com/cloud/api/commands/UpdateVPCOfferingCmd.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd{
4646
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC offering")
4747
private String displayText;
4848

49-
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering")
49+
@Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="update state for the VPC offering; " +
50+
"supported states - Enabled/Disabled")
5051
private String state;
5152

5253
/////////////////////////////////////////////////////

‎api/src/com/cloud/api/response/DomainRouterResponse.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.util.Date;
2020

2121
import com.cloud.api.ApiConstants;
22-
import com.cloud.utils.IdentityProxy;
2322
import com.cloud.serializer.Param;
23+
import com.cloud.utils.IdentityProxy;
2424
import com.cloud.vm.VirtualMachine.State;
2525
import com.google.gson.annotations.SerializedName;
2626

@@ -137,6 +137,9 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
137137
@SerializedName("scriptsversion") @Param(description="the version of scripts")
138138
private String scriptsVersion;
139139

140+
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to")
141+
private IdentityProxy vpcId = new IdentityProxy("vpc");
142+
140143
@Override
141144
public Long getObjectId() {
142145
return getId();
@@ -305,4 +308,8 @@ public void setProjectId(Long projectId) {
305308
public void setProjectName(String projectName) {
306309
this.projectName = projectName;
307310
}
311+
312+
public void setVpcId(Long vpcId) {
313+
this.vpcId.setValue(vpcId);
314+
}
308315
}

‎api/src/com/cloud/api/response/NetworkResponse.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
131131
@SerializedName(ApiConstants.SPECIFY_IP_RANGES) @Param(description="true if network supports specifying ip ranges, false otherwise")
132132
private Boolean specifyIpRanges;
133133

134+
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to")
135+
private IdentityProxy vpcId = new IdentityProxy("vpc");
136+
134137
public void setId(Long id) {
135138
this.id.setValue(id);
136139
}
@@ -272,4 +275,8 @@ public void setRestartRequired(Boolean restartRequired) {
272275
public void setSpecifyIpRanges(Boolean specifyIpRanges) {
273276
this.specifyIpRanges = specifyIpRanges;
274277
}
278+
279+
public void setVpcId(Long vpcId) {
280+
this.vpcId.setValue(vpcId);
281+
}
275282
}

‎api/src/com/cloud/network/element/VpcProvider.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@
1717
import com.cloud.exception.InsufficientCapacityException;
1818
import com.cloud.exception.InsufficientNetworkCapacityException;
1919
import com.cloud.exception.ResourceUnavailableException;
20-
import com.cloud.network.Network;
2120
import com.cloud.network.vpc.Vpc;
22-
import com.cloud.vm.NicProfile;
2321
import com.cloud.vm.ReservationContext;
24-
import com.cloud.vm.VirtualMachine;
25-
import com.cloud.vm.VirtualMachineProfile;
2622

2723
/**
2824
* @author Alena Prokharchyk

‎api/src/com/cloud/network/vpc/VpcService.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public interface VpcService {
3333
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices);
3434

3535
public Vpc getVpc(long vpcId);
36+
37+
public Vpc getActiveVpc(long vpcId);
3638

37-
public List<Network> getVpcNetworks(long vpcId);
39+
public List<? extends Network> getVpcNetworks(long vpcId);
3840

3941
Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(long vpcOffId);
4042

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,8 @@ public DomainRouterResponse createDomainRouterResponse(VirtualRouter router) {
16591659
routerResponse.setDns1(zone.getDns1());
16601660
routerResponse.setDns2(zone.getDns2());
16611661
}
1662+
1663+
routerResponse.setVpcId(router.getVpcId());
16621664

16631665
routerResponse.setObjectName("domainrouter");
16641666
return routerResponse;
@@ -2888,6 +2890,7 @@ public NetworkResponse createNetworkResponse(Network network) {
28882890
}
28892891

28902892
response.setSpecifyIpRanges(network.getSpecifyIpRanges());
2893+
response.setVpcId(network.getVpcId());
28912894

28922895
response.setObjectName("network");
28932896
return response;

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@
188188
import com.cloud.utils.exception.CloudRuntimeException;
189189
import com.cloud.utils.net.Ip;
190190
import com.cloud.utils.net.NetUtils;
191-
import com.cloud.vm.DomainRouterVO;
192191
import com.cloud.vm.Nic;
193192
import com.cloud.vm.NicProfile;
194193
import 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
}

‎server/src/com/cloud/network/dao/IPAddressDao.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
5656
List<IPAddressVO> listByPhysicalNetworkId(long physicalNetworkId);
5757

5858
long countFreeIPs();
59-
}
59+
60+
61+
List<IPAddressVO> listByAssociatedVpc(long vpcId, Boolean isSourceNat);
62+
63+
}

0 commit comments

Comments
 (0)