Skip to content

Commit be2b8ed

Browse files
Pearl1594nvazquez
andauthored
NSX: Refactor Network & VPC offering (#8110)
* [NSX] Refactor API wrapper operations * Network offering changes for NSX * fix services and provider combination * address comments: rename param * update nsx_mode parameter --------- Co-authored-by: nvazquez <[email protected]>
1 parent 69ded80 commit be2b8ed

File tree

32 files changed

+777
-182
lines changed

32 files changed

+777
-182
lines changed

api/src/main/java/com/cloud/network/vpc/VpcOffering.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public enum State {
2929
public static final String defaultVPCOfferingName = "Default VPC offering";
3030
public static final String defaultVPCNSOfferingName = "Default VPC offering with Netscaler";
3131
public static final String redundantVPCOfferingName = "Redundant VPC offering";
32-
public static final String DEFAULT_VPC_NSX_OFFERING_NAME = "VPC offering with NSX";
32+
public static final String DEFAULT_VPC_NAT_NSX_OFFERING_NAME = "VPC offering with NSX - NAT Mode";
33+
public static final String DEFAULT_VPC_ROUTE_NSX_OFFERING_NAME = "VPC offering with NSX - Route Mode";
3334

3435
/**
3536
*
@@ -54,6 +55,10 @@ public enum State {
5455
*/
5556
boolean isDefault();
5657

58+
boolean isForNsx();
59+
60+
String getNsxMode();
61+
5762
/**
5863
* @return service offering id used by VPC virtual router
5964
*/

api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public interface VpcProvisioningService {
3636
VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices,
3737
Map<String, List<String>> serviceProviders,
3838
Map serviceCapabilitystList, NetUtils.InternetProtocol internetProtocol,
39-
Long serviceOfferingId, List<Long> domainIds, List<Long> zoneIds, VpcOffering.State state);
39+
Long serviceOfferingId, Boolean forNsx, String mode,
40+
List<Long> domainIds, List<Long> zoneIds, VpcOffering.State state);
4041

4142
Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(ListVPCOfferingsCmd cmd);
4243

api/src/main/java/com/cloud/offering/NetworkOffering.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public enum Detail {
4343
InternalLbProvider, PublicLbProvider, servicepackageuuid, servicepackagedescription, PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RelatedNetworkOffering, domainid, zoneid, pvlanType, internetProtocol
4444
}
4545

46+
public enum NsxMode {
47+
NATTED,
48+
ROUTED
49+
}
50+
4651
public final static String SystemPublicNetwork = "System-Public-Network";
4752
public final static String SystemControlNetwork = "System-Control-Network";
4853
public final static String SystemManagementNetwork = "System-Management-Network";
@@ -52,7 +57,8 @@ public enum Detail {
5257

5358
public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService";
5459
public static final String DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE = "DefaultTungstenSharedNetworkOfferingWithSGService";
55-
public static final String DEFAULT_NSX_OFFERING = "DefaultNSXNetworkOffering";
60+
public static final String DEFAULT_NAT_NSX_OFFERING = "DefaultNATNSXNetworkOffering";
61+
public static final String DEFAULT_ROUTER_NSX_OFFERING = "DefaultRouteNSXNetworkOffering";
5662
public final static String QuickCloudNoServices = "QuickCloudNoServices";
5763
public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService";
5864
public final static String OvsIsolatedNetworkOfferingWithSourceNatService = "OvsIsolatedNetworkOfferingWithSourceNatService";
@@ -93,6 +99,8 @@ public enum Detail {
9399

94100
boolean isForNsx();
95101

102+
String getNsxMode();
103+
96104
TrafficType getTrafficType();
97105

98106
boolean isSpecifyVlan();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ public class ApiConstants {
292292
public static final String MIGRATION_TYPE = "migrationtype";
293293
public static final String MEMORY = "memory";
294294
public static final String MODE = "mode";
295+
public static final String NSX_MODE = "nsxmode";
295296
public static final String NAME = "name";
296297
public static final String METHOD_NAME = "methodname";
297298
public static final String NETWORK_DOMAIN = "networkdomain";

api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Set;
27+
import java.util.stream.Collectors;
2728

29+
import com.cloud.network.Network;
30+
import com.cloud.network.VirtualRouterProvider;
2831
import org.apache.cloudstack.api.response.DomainResponse;
2932
import org.apache.cloudstack.api.response.ZoneResponse;
3033
import org.apache.commons.collections.CollectionUtils;
@@ -47,6 +50,15 @@
4750
import com.cloud.offering.NetworkOffering.Availability;
4851
import com.cloud.user.Account;
4952

53+
import static com.cloud.network.Network.Service.Dhcp;
54+
import static com.cloud.network.Network.Service.Dns;
55+
import static com.cloud.network.Network.Service.Lb;
56+
import static com.cloud.network.Network.Service.StaticNat;
57+
import static com.cloud.network.Network.Service.SourceNat;
58+
import static com.cloud.network.Network.Service.PortForwarding;
59+
import static com.cloud.network.Network.Service.NetworkACL;
60+
import static com.cloud.network.Network.Service.UserData;
61+
5062
@APICommand(name = "createNetworkOffering", description = "Creates a network offering.", responseObject = NetworkOfferingResponse.class, since = "3.0.0",
5163
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
5264
public class CreateNetworkOfferingCmd extends BaseCmd {
@@ -127,6 +139,18 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
127139
description = "true if network offering is meant to be used for VPC, false otherwise.")
128140
private Boolean forVpc;
129141

142+
@Parameter(name = ApiConstants.FOR_NSX,
143+
type = CommandType.BOOLEAN,
144+
description = "true if network offering is meant to be used for NSX, false otherwise.",
145+
since = "4.20.0")
146+
private Boolean forNsx;
147+
148+
@Parameter(name = ApiConstants.NSX_MODE,
149+
type = CommandType.STRING,
150+
description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED",
151+
since = "4.20.0")
152+
private String nsxMode;
153+
130154
@Parameter(name = ApiConstants.FOR_TUNGSTEN,
131155
type = CommandType.BOOLEAN,
132156
description = "true if network offering is meant to be used for Tungsten-Fabric, false otherwise.")
@@ -211,7 +235,24 @@ public Long getServiceOfferingId() {
211235
}
212236

213237
public List<String> getSupportedServices() {
214-
return supportedServices == null ? new ArrayList<String>() : supportedServices;
238+
if (!forNsx) {
239+
return supportedServices == null ? new ArrayList<String>() : supportedServices;
240+
} else {
241+
List<String> services = new ArrayList<>(List.of(
242+
Dhcp.getName(),
243+
Dns.getName(),
244+
StaticNat.getName(),
245+
SourceNat.getName(),
246+
PortForwarding.getName(),
247+
UserData.getName(),
248+
Lb.getName()
249+
));
250+
if (Boolean.TRUE.equals(forVpc)) {
251+
services.add(NetworkACL.getName());
252+
return services;
253+
}
254+
return services;
255+
}
215256
}
216257

217258
public String getGuestIpType() {
@@ -241,6 +282,14 @@ public Boolean getForVpc() {
241282
return forVpc;
242283
}
243284

285+
public Boolean isForNsx() {
286+
return forNsx;
287+
}
288+
289+
public String getNsxMode() {
290+
return nsxMode;
291+
}
292+
244293
public Boolean getForTungsten() {
245294
return forTungsten;
246295
}
@@ -261,9 +310,8 @@ public Integer getMaxconnections() {
261310
}
262311

263312
public Map<String, List<String>> getServiceProviders() {
264-
Map<String, List<String>> serviceProviderMap = null;
265-
if (serviceProviderList != null && !serviceProviderList.isEmpty()) {
266-
serviceProviderMap = new HashMap<String, List<String>>();
313+
Map<String, List<String>> serviceProviderMap = new HashMap<String, List<String>>();
314+
if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) {
267315
Collection servicesCollection = serviceProviderList.values();
268316
Iterator iter = servicesCollection.iterator();
269317
while (iter.hasNext()) {
@@ -279,11 +327,29 @@ public Map<String, List<String>> getServiceProviders() {
279327
providerList.add(provider);
280328
serviceProviderMap.put(service, providerList);
281329
}
330+
} else if (Boolean.TRUE.equals(forNsx)) {
331+
getServiceProviderMapForNsx(serviceProviderMap);
282332
}
283-
284333
return serviceProviderMap;
285334
}
286335

336+
private void getServiceProviderMapForNsx(Map<String, List<String>> serviceProviderMap) {
337+
String routerProvider = Boolean.TRUE.equals(getForVpc()) ? VirtualRouterProvider.Type.VPCVirtualRouter.name() :
338+
VirtualRouterProvider.Type.VirtualRouter.name();
339+
List<String> unsupportedServices = List.of("Vpn", "SecurityGroup", "Connectivity",
340+
"Gateway", "Firewall", "BaremetalPxeService");
341+
List<String> routerSupported = List.of("Dhcp", "Dns", "UserData");
342+
List<String> allServices = Service.listAllServices().stream().map(Service::getName).collect(Collectors.toList());
343+
for (String service : allServices) {
344+
if (unsupportedServices.contains(service))
345+
continue;
346+
if (routerSupported.contains(service))
347+
serviceProviderMap.put(service, List.of(routerProvider));
348+
else
349+
serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName()));
350+
}
351+
}
352+
287353
public Map<Capability, String> getServiceCapabilities(Service service) {
288354
Map<Capability, String> capabilityMap = null;
289355

api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@
2323
import java.util.LinkedHashSet;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.Objects;
2627
import java.util.Set;
28+
import java.util.stream.Collectors;
2729

30+
import com.cloud.exception.InvalidParameterValueException;
31+
import com.cloud.network.Network;
32+
import com.cloud.network.VirtualRouterProvider;
2833
import org.apache.cloudstack.api.response.DomainResponse;
2934
import org.apache.cloudstack.api.response.ZoneResponse;
3035
import org.apache.commons.collections.CollectionUtils;
@@ -45,6 +50,15 @@
4550
import com.cloud.network.vpc.VpcOffering;
4651
import com.cloud.user.Account;
4752

53+
import static com.cloud.network.Network.Service.Dhcp;
54+
import static com.cloud.network.Network.Service.Dns;
55+
import static com.cloud.network.Network.Service.Lb;
56+
import static com.cloud.network.Network.Service.StaticNat;
57+
import static com.cloud.network.Network.Service.SourceNat;
58+
import static com.cloud.network.Network.Service.PortForwarding;
59+
import static com.cloud.network.Network.Service.NetworkACL;
60+
import static com.cloud.network.Network.Service.UserData;
61+
4862
@APICommand(name = "createVPCOffering", description = "Creates VPC offering", responseObject = VpcOfferingResponse.class,
4963
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
5064
public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
@@ -62,7 +76,6 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
6276

6377
@Parameter(name = ApiConstants.SUPPORTED_SERVICES,
6478
type = CommandType.LIST,
65-
required = true,
6679
collectionType = CommandType.STRING,
6780
description = "services supported by the vpc offering")
6881
private List<String> supportedServices;
@@ -101,6 +114,18 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd {
101114
since = "4.13")
102115
private List<Long> zoneIds;
103116

117+
@Parameter(name = ApiConstants.FOR_NSX,
118+
type = CommandType.BOOLEAN,
119+
description = "true if network offering is meant to be used for NSX, false otherwise.",
120+
since = "4.20.0")
121+
private Boolean forNsx;
122+
123+
@Parameter(name = ApiConstants.NSX_MODE,
124+
type = CommandType.STRING,
125+
description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED",
126+
since = "4.20.0")
127+
private String nsxMode;
128+
104129
@Parameter(name = ApiConstants.ENABLE,
105130
type = CommandType.BOOLEAN,
106131
description = "set to true if the offering is to be enabled during creation. Default is false",
@@ -120,21 +145,43 @@ public String getDisplayText() {
120145
}
121146

122147
public List<String> getSupportedServices() {
148+
if (!forNsx && CollectionUtils.isEmpty(supportedServices)) {
149+
throw new InvalidParameterValueException("Supported services needs to be provided");
150+
}
151+
if (forNsx) {
152+
return List.of(
153+
Dhcp.getName(),
154+
Dns.getName(),
155+
Lb.getName(),
156+
StaticNat.getName(),
157+
SourceNat.getName(),
158+
NetworkACL.getName(),
159+
PortForwarding.getName(),
160+
UserData.getName()
161+
);
162+
}
123163
return supportedServices;
124164
}
125165

166+
public Boolean isForNsx() {
167+
return !Objects.isNull(forNsx) && forNsx;
168+
}
169+
170+
public String getNsxMode() {
171+
return nsxMode;
172+
}
173+
126174
public Map<String, List<String>> getServiceProviders() {
127-
Map<String, List<String>> serviceProviderMap = null;
128-
if (serviceProviderList != null && !serviceProviderList.isEmpty()) {
129-
serviceProviderMap = new HashMap<String, List<String>>();
175+
Map<String, List<String>> serviceProviderMap = new HashMap<String, List<String>>();;
176+
if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) {
130177
Collection<? extends Map<String, String>> servicesCollection = serviceProviderList.values();
131178
Iterator<? extends Map<String, String>> iter = servicesCollection.iterator();
132179
while (iter.hasNext()) {
133180
Map<String, String> obj = iter.next();
134181
if (s_logger.isTraceEnabled()) {
135182
s_logger.trace("service provider entry specified: " + obj);
136183
}
137-
HashMap<String, String> services = (HashMap<String, String>)obj;
184+
HashMap<String, String> services = (HashMap<String, String>) obj;
138185
String service = services.get("service");
139186
String provider = services.get("provider");
140187
List<String> providerList = null;
@@ -146,11 +193,28 @@ public Map<String, List<String>> getServiceProviders() {
146193
providerList.add(provider);
147194
serviceProviderMap.put(service, providerList);
148195
}
196+
} else if (Boolean.TRUE.equals(forNsx)) {
197+
getServiceProviderMapForNsx(serviceProviderMap);
149198
}
150199

151200
return serviceProviderMap;
152201
}
153202

203+
private void getServiceProviderMapForNsx(Map<String, List<String>> serviceProviderMap) {
204+
List<String> unsupportedServices = List.of("Vpn", "BaremetalPxeService", "SecurityGroup", "Connectivity",
205+
"Gateway", "Firewall");
206+
List<String> routerSupported = List.of("Dhcp", "Dns", "UserData");
207+
List<String> allServices = Network.Service.listAllServices().stream().map(Network.Service::getName).collect(Collectors.toList());
208+
for (String service : allServices) {
209+
if (unsupportedServices.contains(service))
210+
continue;
211+
if (routerSupported.contains(service))
212+
serviceProviderMap.put(service, List.of(VirtualRouterProvider.Type.VPCVirtualRouter.name()));
213+
else
214+
serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName()));
215+
}
216+
}
217+
154218
public Map<String, List<String>> getServiceCapabilityList() {
155219
return serviceCapabilityList;
156220
}

api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations {
107107
@Param(description = "true if network offering can be used by Tungsten-Fabric networks only")
108108
private Boolean forTungsten;
109109

110+
@SerializedName(ApiConstants.NSX_MODE)
111+
@Param(description = "Mode in which the network will operate. This parameter is only relevant for NSX offerings")
112+
private String nsxMode;
113+
110114
@SerializedName(ApiConstants.IS_PERSISTENT)
111115
@Param(description = "true if network offering supports persistent networks, false otherwise")
112116
private Boolean isPersistent;
@@ -227,6 +231,10 @@ public void setForTungsten(Boolean forTungsten) {
227231
this.forTungsten = forTungsten;
228232
}
229233

234+
public void setNsxMode(String nsxMode) {
235+
this.nsxMode = nsxMode;
236+
}
237+
230238
public void setIsPersistent(Boolean isPersistent) {
231239
this.isPersistent = isPersistent;
232240
}

api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,17 @@ public class VpcOfferingResponse extends BaseResponse {
6363
private Boolean supportsDistributedRouter;
6464

6565
@SerializedName((ApiConstants.SUPPORTS_REGION_LEVEL_VPC))
66-
@Param(description = " indicated if the offering can support region level vpc", since = "4.4")
66+
@Param(description = "indicated if the offering can support region level vpc", since = "4.4")
6767
private Boolean supportsRegionLevelVpc;
6868

69+
@SerializedName(ApiConstants.FOR_NSX)
70+
@Param(description = "true if vpc offering can be used by NSX networks only")
71+
private Boolean forNsx;
72+
73+
@SerializedName(ApiConstants.NSX_MODE)
74+
@Param(description = "Mode in which the network will operate. This parameter is only relevant for NSX offerings")
75+
private String nsxMode;
76+
6977
@SerializedName(ApiConstants.DOMAIN_ID)
7078
@Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.")
7179
private String domainId;
@@ -138,6 +146,14 @@ public void setDomain(String domain) {
138146
this.domain = domain;
139147
}
140148

149+
public void setForNsx(Boolean forNsx) {
150+
this.forNsx = forNsx;
151+
}
152+
153+
public void setNsxMode(String nsxMode) {
154+
this.nsxMode = nsxMode;
155+
}
156+
141157
public String getZoneId() {
142158
return zoneId;
143159
}

0 commit comments

Comments
 (0)