Skip to content

Commit fad0cfc

Browse files
author
Alena Prokharchyk
committed
Added new paramerer "start" to createVPC command. When false is passed in, VPC won't be started (its VPC VR won't get implemented) till the point when the first netwotrk gets implemented in the VPC.
The parameter is optional and true by default to preserve the original behavior Conflicts: api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
1 parent 4517b92 commit fad0cfc

3 files changed

Lines changed: 56 additions & 35 deletions

File tree

‎api/src/org/apache/cloudstack/api/ApiConstants.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ public class ApiConstants {
410410
public static final String EXTERNAL_SWITCH_MGMT_DEVICE_ID = "vsmdeviceid";
411411
public static final String EXTERNAL_SWITCH_MGMT_DEVICE_NAME = "vsmdevicename";
412412
public static final String EXTERNAL_SWITCH_MGMT_DEVICE_STATE = "vsmdevicestate";
413-
// Would we need to have a capacity field for Cisco N1KV VSM? Max hosts managed by it perhaps? May remove this later.
413+
// Would we need to have a capacity field for Cisco N1KV VSM? Max hosts managed by it perhaps? May remove this
414+
// later.
414415
public static final String EXTERNAL_SWITCH_MGMT_DEVICE_CAPACITY = "vsmdevicecapacity";
415416
public static final String CISCO_NEXUS_VSM_NAME = "vsmname";
416417
public static final String VSM_USERNAME = "vsmusername";
@@ -534,6 +535,7 @@ public class ApiConstants {
534535
public static final String FOR_DISPLAY = "fordisplay";
535536
public static final String PASSIVE = "passive";
536537
public static final String VERSION = "version";
538+
public static final String START = "start";
537539

538540
public enum HostDetails {
539541
all, capacity, events, stats, min;

‎api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java‎

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vpc;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiConstants;
2321
import org.apache.cloudstack.api.ApiErrorCode;
@@ -30,6 +28,7 @@
3028
import org.apache.cloudstack.api.response.VpcResponse;
3129
import org.apache.cloudstack.api.response.ZoneResponse;
3230
import org.apache.cloudstack.context.CallContext;
31+
import org.apache.log4j.Logger;
3332

3433
import com.cloud.event.EventTypes;
3534
import com.cloud.exception.ConcurrentOperationException;
@@ -43,47 +42,54 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd {
4342
public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName());
4443
private static final String s_name = "createvpcresponse";
4544

46-
/////////////////////////////////////////////////////
47-
//////////////// API parameters /////////////////////
48-
/////////////////////////////////////////////////////
45+
// ///////////////////////////////////////////////////
46+
// ////////////// API parameters /////////////////////
47+
// ///////////////////////////////////////////////////
4948

50-
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account associated with the VPC. "
51-
+ "Must be used with the domainId parameter.")
49+
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account associated with the VPC. " +
50+
"Must be used with the domainId parameter.")
5251
private String accountName;
5352

54-
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class, description = "the domain ID associated with the VPC. "
55-
+ "If used with the account parameter returns the VPC associated with the account for the specified domain.")
53+
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, entityType = DomainResponse.class,
54+
description = "the domain ID associated with the VPC. " +
55+
"If used with the account parameter returns the VPC associated with the account for the specified domain.")
5656
private Long domainId;
5757

58-
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "create VPC for the project")
58+
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class,
59+
description = "create VPC for the project")
5960
private Long projectId;
6061

61-
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the ID of the availability zone")
62+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class,
63+
required = true, description = "the ID of the availability zone")
6264
private Long zoneId;
6365

6466
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the VPC")
6567
private String vpcName;
6668

67-
@Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of " + "the VPC")
69+
@Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "the display text of " +
70+
"the VPC")
6871
private String displayText;
6972

70-
@Parameter(name = ApiConstants.CIDR, type = CommandType.STRING, required = true, description = "the cidr of the VPC. All VPC "
71-
+ "guest networks' cidrs should be within this CIDR")
73+
@Parameter(name = ApiConstants.CIDR, type = CommandType.STRING, required = true, description = "the cidr of the VPC. All VPC " +
74+
"guest networks' cidrs should be within this CIDR")
7275
private String cidr;
7376

74-
@Parameter(name = ApiConstants.VPC_OFF_ID,
75-
type = CommandType.UUID,
76-
entityType = VpcOfferingResponse.class,
77-
required = true,
78-
description = "the ID of the VPC offering")
77+
@Parameter(name = ApiConstants.VPC_OFF_ID, type = CommandType.UUID, entityType = VpcOfferingResponse.class,
78+
required = true, description = "the ID of the VPC offering")
7979
private Long vpcOffering;
8080

81-
@Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING, description = "VPC network domain. All networks inside the VPC will belong to this domain")
81+
@Parameter(name = ApiConstants.NETWORK_DOMAIN, type = CommandType.STRING,
82+
description = "VPC network domain. All networks inside the VPC will belong to this domain")
8283
private String networkDomain;
8384

84-
/////////////////////////////////////////////////////
85-
/////////////////// Accessors ///////////////////////
86-
/////////////////////////////////////////////////////
85+
@Parameter(name = ApiConstants.START, type = CommandType.BOOLEAN,
86+
description = "If set to false, the VPC won't start (VPC VR will not get allocated) until its first network gets implemented. " +
87+
"True by default.", since = "4.3")
88+
private Boolean start;
89+
90+
// ///////////////////////////////////////////////////
91+
// ///////////////// Accessors ///////////////////////
92+
// ///////////////////////////////////////////////////
8793

8894
public String getAccountName() {
8995
return accountName;
@@ -117,6 +123,13 @@ public String getNetworkDomain() {
117123
return networkDomain;
118124
}
119125

126+
public boolean isStart() {
127+
if (start != null) {
128+
return start;
129+
}
130+
return true;
131+
}
132+
120133
@Override
121134
public void create() throws ResourceAllocationException {
122135
Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), getNetworkDomain());
@@ -131,10 +144,14 @@ public void create() throws ResourceAllocationException {
131144
@Override
132145
public void execute() {
133146
Vpc vpc = null;
147+
boolean success = true;
134148
try {
135-
if (_vpcService.startVpc(getEntityId(), true)) {
136-
vpc = _entityMgr.findById(Vpc.class, getEntityId());
149+
if (isStart()) {
150+
success = _vpcService.startVpc(getEntityId(), true);
151+
} else {
152+
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
137153
}
154+
vpc = _entityMgr.findById(Vpc.class, getEntityId());
138155
} catch (ResourceUnavailableException ex) {
139156
s_logger.warn("Exception: ", ex);
140157
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
@@ -147,7 +164,7 @@ public void execute() {
147164
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
148165
}
149166

150-
if (vpc != null) {
167+
if (vpc != null && success) {
151168
VpcResponse response = _responseGenerator.createVpcResponse(vpc);
152169
response.setResponseName(getCommandName());
153170
setResponseObject(response);

‎engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4848
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
4949
import org.apache.cloudstack.region.PortableIpDao;
50+
import org.apache.log4j.Logger;
5051

5152
import com.cloud.agent.AgentManager;
5253
import com.cloud.agent.Listener;
@@ -147,6 +148,7 @@
147148
import com.cloud.network.rules.StaticNatRuleImpl;
148149
import com.cloud.network.rules.dao.PortForwardingRulesDao;
149150
import com.cloud.network.vpc.NetworkACLManager;
151+
import com.cloud.network.vpc.Vpc;
150152
import com.cloud.network.vpc.VpcManager;
151153
import com.cloud.network.vpc.dao.PrivateIpDao;
152154
import com.cloud.network.vpn.RemoteAccessVpnService;
@@ -1031,22 +1033,22 @@ public void implementNetworkElementsAndResources(DeployDestination dest, Reserva
10311033
(network.getGuestType() == Network.GuestType.Isolated || (network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced))) {
10321034

10331035
List<IPAddressVO> ips = null;
1036+
Account owner = _entityMgr.findById(Account.class, network.getAccountId());
10341037
if (network.getVpcId() != null) {
10351038
ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
10361039
if (ips.isEmpty()) {
1037-
throw new CloudRuntimeException("Vpc is not implemented; there is no source nat ip");
1040+
Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId());
1041+
s_logger.debug("Creating a source nat ip for vpc " + vpc);
1042+
_vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
10381043
}
10391044
} else {
10401045
ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
1041-
}
1042-
1043-
if (ips.isEmpty()) {
1044-
s_logger.debug("Creating a source nat ip for network " + network);
1045-
Account owner = _entityMgr.findById(Account.class, network.getAccountId());
1046-
_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
1046+
if (ips.isEmpty()) {
1047+
s_logger.debug("Creating a source nat ip for network " + network);
1048+
_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
1049+
}
10471050
}
10481051
}
1049-
10501052
// get providers to implement
10511053
List<Provider> providersToImplement = getNetworkProviders(network.getId());
10521054
for (NetworkElement element : _networkElements) {

0 commit comments

Comments
 (0)