Skip to content

Commit dc589a4

Browse files
sb-abhish3kshwstppr
authored andcommitted
server: create network offering for specified domain(s) and zone(s)
Signed-off-by: Abhishek Kumar <abhishek.kumar@shapeblue.com>
1 parent e2bb43a commit dc589a4

21 files changed

Lines changed: 1103 additions & 267 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public enum State {
3838
}
3939

4040
public enum Detail {
41-
InternalLbProvider, PublicLbProvider, servicepackageuuid, servicepackagedescription, PromiscuousMode, MacAddressChanges, ForgedTransmits, RelatedNetworkOffering
41+
InternalLbProvider, PublicLbProvider, servicepackageuuid, servicepackagedescription, PromiscuousMode, MacAddressChanges, ForgedTransmits, RelatedNetworkOffering, domainid, zoneid
4242
}
4343

4444
public final static String SystemPublicNetwork = "System-Public-Network";

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

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020
import java.util.Collection;
2121
import java.util.HashMap;
2222
import java.util.Iterator;
23+
import java.util.LinkedHashSet;
2324
import java.util.List;
2425
import java.util.Map;
26+
import java.util.Set;
2527

28+
import org.apache.cloudstack.api.response.DomainResponse;
29+
import org.apache.cloudstack.api.response.ZoneResponse;
30+
import org.apache.commons.collections.CollectionUtils;
2631
import org.apache.log4j.Logger;
2732

2833
import org.apache.cloudstack.api.APICommand;
@@ -58,9 +63,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
5863
private String displayText;
5964

6065
@Parameter(name = ApiConstants.TRAFFIC_TYPE,
61-
type = CommandType.STRING,
62-
required = true,
63-
description = "the traffic type for the network offering. Supported type in current release is GUEST only")
66+
type = CommandType.STRING,
67+
required = true,
68+
description = "the traffic type for the network offering. Supported type in current release is GUEST only")
6469
private String traffictype;
6570

6671
@Parameter(name = ApiConstants.TAGS, type = CommandType.STRING, description = "the tags for the network offering.", length = 4096)
@@ -79,37 +84,37 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
7984
private Boolean conserveMode;
8085

8186
@Parameter(name = ApiConstants.SERVICE_OFFERING_ID,
82-
type = CommandType.UUID,
83-
entityType = ServiceOfferingResponse.class,
84-
description = "the service offering ID used by virtual router provider")
87+
type = CommandType.UUID,
88+
entityType = ServiceOfferingResponse.class,
89+
description = "the service offering ID used by virtual router provider")
8590
private Long serviceOfferingId;
8691

8792
@Parameter(name = ApiConstants.GUEST_IP_TYPE, type = CommandType.STRING, required = true, description = "guest type of the network offering: Shared or Isolated")
8893
private String guestIptype;
8994

9095
@Parameter(name = ApiConstants.SUPPORTED_SERVICES,
91-
type = CommandType.LIST,
92-
required = true,
93-
collectionType = CommandType.STRING,
94-
description = "services supported by the network offering")
96+
type = CommandType.LIST,
97+
required = true,
98+
collectionType = CommandType.STRING,
99+
description = "services supported by the network offering")
95100
private List<String> supportedServices;
96101

97102
@Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST,
98-
type = CommandType.MAP,
99-
description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
103+
type = CommandType.MAP,
104+
description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
100105
private Map serviceProviderList;
101106

102107
@Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
103108
private Map serviceCapabilitystList;
104109

105110
@Parameter(name = ApiConstants.SPECIFY_IP_RANGES,
106-
type = CommandType.BOOLEAN,
107-
description = "true if network offering supports specifying ip ranges; defaulted to false if not specified")
111+
type = CommandType.BOOLEAN,
112+
description = "true if network offering supports specifying ip ranges; defaulted to false if not specified")
108113
private Boolean specifyIpRanges;
109114

110115
@Parameter(name = ApiConstants.IS_PERSISTENT,
111-
type = CommandType.BOOLEAN,
112-
description = "true if network offering supports persistent networks; defaulted to false if not specified")
116+
type = CommandType.BOOLEAN,
117+
description = "true if network offering supports persistent networks; defaulted to false if not specified")
113118
private Boolean isPersistent;
114119

115120
@Parameter(name = ApiConstants.FOR_VPC,
@@ -118,26 +123,41 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
118123
private Boolean forVpc;
119124

120125
@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, since = "4.2.0", description = "Network offering details in key/value pairs."
121-
+ " Supported keys are internallbprovider/publiclbprovider with service provider as a value, and"
122-
+ " promiscuousmode/macaddresschanges/forgedtransmits with true/false as value to accept/reject the security settings if available for a nic/portgroup")
126+
+ " Supported keys are internallbprovider/publiclbprovider with service provider as a value, and"
127+
+ " promiscuousmode/macaddresschanges/forgedtransmits with true/false as value to accept/reject the security settings if available for a nic/portgroup")
123128
protected Map details;
124129

125130
@Parameter(name = ApiConstants.EGRESS_DEFAULT_POLICY,
126-
type = CommandType.BOOLEAN,
127-
description = "true if guest network default egress policy is allow; false if default egress policy is deny")
131+
type = CommandType.BOOLEAN,
132+
description = "true if guest network default egress policy is allow; false if default egress policy is deny")
128133
private Boolean egressDefaultPolicy;
129134

130135
@Parameter(name = ApiConstants.KEEPALIVE_ENABLED,
131-
type = CommandType.BOOLEAN,
132-
required = false,
133-
description = "if true keepalive will be turned on in the loadbalancer. At the time of writing this has only an effect on haproxy; the mode http and httpclose options are unset in the haproxy conf file.")
136+
type = CommandType.BOOLEAN,
137+
required = false,
138+
description = "if true keepalive will be turned on in the loadbalancer. At the time of writing this has only an effect on haproxy; the mode http and httpclose options are unset in the haproxy conf file.")
134139
private Boolean keepAliveEnabled;
135140

136141
@Parameter(name = ApiConstants.MAX_CONNECTIONS,
137-
type = CommandType.INTEGER,
138-
description = "maximum number of concurrent connections supported by the network offering")
142+
type = CommandType.INTEGER,
143+
description = "maximum number of concurrent connections supported by the network offering")
139144
private Integer maxConnections;
140145

146+
@Parameter(name = ApiConstants.DOMAIN_ID,
147+
type = CommandType.LIST,
148+
collectionType = CommandType.UUID,
149+
entityType = DomainResponse.class,
150+
description = "the ID of the containing domain(s), null for public offerings")
151+
private List<Long> domainIds;
152+
153+
@Parameter(name = ApiConstants.ZONE_ID,
154+
type = CommandType.LIST,
155+
collectionType = CommandType.UUID,
156+
entityType = ZoneResponse.class,
157+
description = "the ID of the containing zone(s), null for public offerings",
158+
since = "4.13")
159+
private List<Long> zoneIds;
160+
141161
/////////////////////////////////////////////////////
142162
/////////////////// Accessors ///////////////////////
143163
/////////////////////////////////////////////////////
@@ -227,7 +247,7 @@ public Map<String, List<String>> getServiceProviders() {
227247
Collection servicesCollection = serviceProviderList.values();
228248
Iterator iter = servicesCollection.iterator();
229249
while (iter.hasNext()) {
230-
HashMap<String, String> services = (HashMap<String, String>)iter.next();
250+
HashMap<String, String> services = (HashMap<String, String>) iter.next();
231251
String service = services.get("service");
232252
String provider = services.get("provider");
233253
List<String> providerList = null;
@@ -252,7 +272,7 @@ public Map<Capability, String> getServiceCapabilities(Service service) {
252272
Collection serviceCapabilityCollection = serviceCapabilitystList.values();
253273
Iterator iter = serviceCapabilityCollection.iterator();
254274
while (iter.hasNext()) {
255-
HashMap<String, String> svcCapabilityMap = (HashMap<String, String>)iter.next();
275+
HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
256276
Capability capability = null;
257277
String svc = svcCapabilityMap.get("service");
258278
String capabilityName = svcCapabilityMap.get("capabilitytype");
@@ -283,11 +303,10 @@ public Map<String, String> getDetails() {
283303
}
284304

285305
Collection paramsCollection = details.values();
286-
Object objlist[]= paramsCollection.toArray();
287-
Map<String, String> params = (Map<String, String>)(objlist[0]);
288-
for(int i=1; i< objlist.length; i++)
289-
{
290-
params.putAll((Map<String, String>)(objlist[i]));
306+
Object objlist[] = paramsCollection.toArray();
307+
Map<String, String> params = (Map<String, String>) (objlist[0]);
308+
for (int i = 1; i < objlist.length; i++) {
309+
params.putAll((Map<String, String>) (objlist[i]));
291310
}
292311

293312
return params;
@@ -297,7 +316,25 @@ public String getServicePackageId() {
297316
Map<String, String> data = getDetails();
298317
if (data == null)
299318
return null;
300-
return data.get(NetworkOffering.Detail.servicepackageuuid+ "");
319+
return data.get(NetworkOffering.Detail.servicepackageuuid + "");
320+
}
321+
322+
public List<Long> getDomainIds() {
323+
if (CollectionUtils.isNotEmpty(domainIds)) {
324+
Set<Long> set = new LinkedHashSet<>(domainIds);
325+
domainIds.clear();
326+
domainIds.addAll(set);
327+
}
328+
return domainIds;
329+
}
330+
331+
public List<Long> getZoneIds() {
332+
if (CollectionUtils.isNotEmpty(zoneIds)) {
333+
Set<Long> set = new LinkedHashSet<>(zoneIds);
334+
zoneIds.clear();
335+
zoneIds.addAll(set);
336+
}
337+
return zoneIds;
301338
}
302339

303340
/////////////////////////////////////////////////////

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

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.network;
1818

19+
import java.util.LinkedHashSet;
20+
import java.util.List;
21+
import java.util.Set;
22+
23+
import org.apache.cloudstack.api.response.DomainResponse;
24+
import org.apache.cloudstack.api.response.ZoneResponse;
25+
import org.apache.commons.collections.CollectionUtils;
1926
import org.apache.log4j.Logger;
2027

2128
import org.apache.cloudstack.api.APICommand;
@@ -49,7 +56,7 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
4956
private String displayText;
5057

5158
@Parameter(name = ApiConstants.AVAILABILITY, type = CommandType.STRING, description = "the availability of network offering."
52-
+ " Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering")
59+
+ " Default value is Required for Guest Virtual network offering; Optional for Guest Direct network offering")
5360
private String availability;
5461

5562
@Parameter(name = ApiConstants.SORT_KEY, type = CommandType.INTEGER, description = "sort key of the network offering, integer")
@@ -59,19 +66,34 @@ public class UpdateNetworkOfferingCmd extends BaseCmd {
5966
private String state;
6067

6168
@Parameter(name = ApiConstants.KEEPALIVE_ENABLED,
62-
type = CommandType.BOOLEAN,
63-
required = false,
64-
description = "if true keepalive will be turned on in the loadbalancer. At the time of writing this has only an effect on haproxy; the mode http and httpclose options are unset in the haproxy conf file.")
69+
type = CommandType.BOOLEAN,
70+
required = false,
71+
description = "if true keepalive will be turned on in the loadbalancer. At the time of writing this has only an effect on haproxy; the mode http and httpclose options are unset in the haproxy conf file.")
6572
private Boolean keepAliveEnabled;
6673

6774
@Parameter(name = ApiConstants.MAX_CONNECTIONS,
68-
type = CommandType.INTEGER,
69-
description = "maximum number of concurrent connections supported by the network offering")
75+
type = CommandType.INTEGER,
76+
description = "maximum number of concurrent connections supported by the network offering")
7077
private Integer maxConnections;
7178

7279
@Parameter(name = ApiConstants.TAGS, type = CommandType.STRING, description = "the tags for the network offering.", length = 4096)
7380
private String tags;
7481

82+
@Parameter(name = ApiConstants.DOMAIN_ID,
83+
type = CommandType.LIST,
84+
collectionType = CommandType.UUID,
85+
entityType = DomainResponse.class,
86+
description = "the ID of the containing domain(s), null for public offerings")
87+
private List<Long> domainIds;
88+
89+
@Parameter(name = ApiConstants.ZONE_ID,
90+
type = CommandType.LIST,
91+
collectionType = CommandType.UUID,
92+
entityType = ZoneResponse.class,
93+
description = "the ID of the containing zone(s), null for public offerings",
94+
since = "4.13")
95+
private List<Long> zoneIds;
96+
7597
/////////////////////////////////////////////////////
7698
/////////////////// Accessors ///////////////////////
7799
/////////////////////////////////////////////////////
@@ -112,6 +134,24 @@ public String getTags() {
112134
return tags;
113135
}
114136

137+
public List<Long> getDomainIds() {
138+
if (CollectionUtils.isNotEmpty(domainIds)) {
139+
Set<Long> set = new LinkedHashSet<>(domainIds);
140+
domainIds.clear();
141+
domainIds.addAll(set);
142+
}
143+
return domainIds;
144+
}
145+
146+
public List<Long> getZoneIds() {
147+
if (CollectionUtils.isNotEmpty(zoneIds)) {
148+
Set<Long> set = new LinkedHashSet<>(zoneIds);
149+
zoneIds.clear();
150+
zoneIds.addAll(set);
151+
}
152+
return zoneIds;
153+
}
154+
115155
/////////////////////////////////////////////////////
116156
/////////////// API Implementation///////////////////
117157
/////////////////////////////////////////////////////

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23-
import com.google.gson.annotations.SerializedName;
24-
2523
import org.apache.cloudstack.api.ApiConstants;
2624
import org.apache.cloudstack.api.BaseResponse;
2725
import org.apache.cloudstack.api.EntityReference;
2826

2927
import com.cloud.offering.NetworkOffering;
3028
import com.cloud.serializer.Param;
29+
import com.google.gson.annotations.SerializedName;
3130

3231
@EntityReference(value = NetworkOffering.class)
3332
@SuppressWarnings("unused")
@@ -124,6 +123,22 @@ public class NetworkOfferingResponse extends BaseResponse {
124123
@Param(description = "true if network offering supports public access for guest networks", since = "4.10.0")
125124
private Boolean supportsPublicAccess;
126125

126+
@SerializedName(ApiConstants.DOMAIN_ID)
127+
@Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.")
128+
private String domainId;
129+
130+
@SerializedName(ApiConstants.DOMAIN)
131+
@Param(description = "the domain name(s) this disk offering belongs to. Ignore this information as it is not currently applicable.")
132+
private String domain;
133+
134+
@SerializedName(ApiConstants.ZONE_ID)
135+
@Param(description = "the zone ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.", since = "4.13.0")
136+
private String zoneId;
137+
138+
@SerializedName(ApiConstants.ZONE)
139+
@Param(description = "the zone name(s) this disk offering belongs to. Ignore this information as it is not currently applicable.", since = "4.13.0")
140+
private String zone;
141+
127142
public void setId(String id) {
128143
this.id = id;
129144
}
@@ -215,4 +230,36 @@ public void setSupportsStrechedL2Subnet(Boolean supportsStrechedL2Subnet) {
215230
public void setSupportsPublicAccess(Boolean supportsPublicAccess) {
216231
this.supportsPublicAccess = supportsPublicAccess;
217232
}
233+
234+
public String getDomainId() {
235+
return domainId;
236+
}
237+
238+
public void setDomainId(String domainId) {
239+
this.domainId = domainId;
240+
}
241+
242+
public String getDomain() {
243+
return domain;
244+
}
245+
246+
public void setDomain(String domain) {
247+
this.domain = domain;
248+
}
249+
250+
public String getZoneId() {
251+
return zoneId;
252+
}
253+
254+
public void setZoneId(String zoneId) {
255+
this.zoneId = zoneId;
256+
}
257+
258+
public String getZone() {
259+
return zone;
260+
}
261+
262+
public void setZone(String zone) {
263+
this.zone = zone;
264+
}
218265
}

engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.configuration;
1818

19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
2122

@@ -205,13 +206,15 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
205206
* ;
206207
* @param details TODO
207208
* @param forVpc
209+
* @param domainIds
210+
* @param zoneIds
208211
* @return network offering object
209212
*/
210213

211214
NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability,
212-
Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId,
213-
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent,
214-
Map<NetworkOffering.Detail, String> details, boolean egressDefaultPolicy, Integer maxconn, boolean enableKeepAlive, Boolean forVpc);
215+
Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId,
216+
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent,
217+
Map<NetworkOffering.Detail, String> details, boolean egressDefaultPolicy, Integer maxconn, boolean enableKeepAlive, Boolean forVpc, List<Long> domainIds, List<Long> zoneIds);
215218

216219
Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, boolean forSystemVms, Long podId, String startIP, String endIP,
217220
String vlanGateway, String vlanNetmask, String vlanId, boolean bypassVlanOverlapCheck, Domain domain, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr)

0 commit comments

Comments
 (0)