Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit 13ee8d1

Browse files
Likitha ShettyMurali Reddy
authored andcommitted
Persistent Networks support
Signed-off-by: Murali Reddy <murali.reddy@citrix.com>
1 parent 482ea4a commit 13ee8d1

20 files changed

Lines changed: 213 additions & 68 deletions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,7 @@ public enum State {
110110
boolean getSpecifyIpRanges();
111111

112112
boolean isInline();
113+
114+
boolean getIsPersistent();
115+
113116
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public class ApiConstants {
103103
public static final String IS_EXTRACTABLE = "isextractable";
104104
public static final String IS_FEATURED = "isfeatured";
105105
public static final String IS_PUBLIC = "ispublic";
106+
public static final String IS_PERSISTENT = "ispersistent";
106107
public static final String IS_READY = "isready";
107108
public static final String IS_RECURSIVE = "isrecursive";
108109
public static final String ISO_FILTER = "isofilter";

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
8888
@Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to false if not specified")
8989
private Boolean specifyIpRanges;
9090

91+
@Parameter(name=ApiConstants.IS_PERSISTENT, type=CommandType.BOOLEAN, description="true if network offering supports persistent networks; defaulted to false if not specified")
92+
private Boolean isPersistent;
93+
9194
/////////////////////////////////////////////////////
9295
/////////////////// Accessors ///////////////////////
9396
/////////////////////////////////////////////////////
@@ -147,6 +150,10 @@ public Boolean getConserveMode() {
147150
return conserveMode;
148151
}
149152

153+
public Boolean getIsPersistent() {
154+
return isPersistent == null ? false : isPersistent;
155+
}
156+
150157
public Map<String, List<String>> getServiceProviders() {
151158
Map<String, List<String>> serviceProviderMap = null;
152159
if (serviceProviderList != null && !serviceProviderList.isEmpty()) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public class NetworkOfferingResponse extends BaseResponse {
8080
@SerializedName(ApiConstants.FOR_VPC) @Param(description="true if network offering can be used by VPC networks only")
8181
private Boolean forVpc;
8282

83+
@SerializedName(ApiConstants.IS_PERSISTENT) @Param(description="true if network offering supports persistent networks, false otherwise")
84+
private Boolean isPersistent;
8385

8486
public void setId(String id) {
8587
this.id = id;
@@ -149,4 +151,9 @@ public void setSpecifyIpRanges(Boolean specifyIpRanges) {
149151
public void setForVpc(Boolean forVpc) {
150152
this.forVpc = forVpc;
151153
}
154+
155+
public void setIsPersistent(Boolean isPersistent) {
156+
this.isPersistent = isPersistent;
157+
}
158+
152159
}

api/src/org/apache/cloudstack/api/response/NetworkResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
141141
@SerializedName(ApiConstants.CAN_USE_FOR_DEPLOY) @Param(description="list networks available for vm deployment")
142142
private Boolean canUseForDeploy;
143143

144+
@SerializedName(ApiConstants.IS_PERSISTENT) @Param(description="list networks that are persistent")
145+
private Boolean isPersistent;
146+
144147
@SerializedName(ApiConstants.TAGS) @Param(description="the list of resource tags associated with network", responseObject = ResourceTagResponse.class)
145148
private List<ResourceTagResponse> tags;
146149

@@ -301,6 +304,10 @@ public void setCanUseForDeploy(Boolean canUseForDeploy) {
301304
this.canUseForDeploy = canUseForDeploy;
302305
}
303306

307+
public void setIsPersistent(Boolean isPersistent) {
308+
this.isPersistent = isPersistent;
309+
}
310+
304311
public void setTags(List<ResourceTagResponse> tags) {
305312
this.tags = tags;
306313
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,7 @@ public NetworkOfferingResponse createNetworkOfferingResponse(NetworkOffering off
19011901
response.setConserveMode(offering.isConserveMode());
19021902
response.setSpecifyIpRanges(offering.getSpecifyIpRanges());
19031903
response.setAvailability(offering.getAvailability().toString());
1904+
response.setIsPersistent(offering.getIsPersistent());
19041905
response.setNetworkRate(ApiDBUtils.getNetworkRate(offering.getId()));
19051906
Long so = null;
19061907
if (offering.getServiceOfferingId() != null) {
@@ -2053,6 +2054,7 @@ public NetworkResponse createNetworkResponse(Network network) {
20532054
response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
20542055
response.setIsSystem(networkOffering.isSystemOnly());
20552056
response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
2057+
response.setIsPersistent(networkOffering.getIsPersistent());
20562058
}
20572059

20582060
if (network.getAclType() != null) {

server/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
173173
* @param trafficType
174174
* @param tags
175175
* @param specifyVlan
176+
* @param isPersistent
176177
* ;
177178
* @param networkRate
178179
* TODO
@@ -196,7 +197,7 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
196197

197198
NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate, Map<Service, Set<Provider>> serviceProviderMap,
198199
boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap,
199-
boolean specifyIpRanges);
200+
boolean specifyIpRanges, boolean isPersistent);
200201

201202
Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
202203

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,7 @@ public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) {
29952995
Availability availability = null;
29962996
Network.GuestType guestType = null;
29972997
boolean specifyIpRanges = cmd.getSpecifyIpRanges();
2998+
boolean isPersistent = cmd.getIsPersistent();
29982999

29993000
// Verify traffic type
30003001
for (TrafficType tType : TrafficType.values()) {
@@ -3165,7 +3166,7 @@ public NetworkOffering createNetworkOffering(CreateNetworkOfferingCmd cmd) {
31653166
}
31663167

31673168
return createNetworkOffering(name, displayText, trafficType, tags, specifyVlan, availability, networkRate, serviceProviderMap, false, guestType, false,
3168-
serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges);
3169+
serviceOfferingId, conserveMode, serviceCapabilityMap, specifyIpRanges, isPersistent);
31693170
}
31703171

31713172
void validateLoadBalancerServiceCapabilities(Map<Capability, String> lbServiceCapabilityMap) {
@@ -3253,7 +3254,7 @@ void validateStaticNatServiceCapablities(Map<Capability, String> staticNatServic
32533254
@DB
32543255
public NetworkOfferingVO createNetworkOffering(String name, String displayText, TrafficType trafficType, String tags, boolean specifyVlan, Availability availability, Integer networkRate,
32553256
Map<Service, Set<Provider>> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId,
3256-
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges) {
3257+
boolean conserveMode, Map<Service, Map<Capability, String>> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent) {
32573258

32583259
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
32593260
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
@@ -3274,6 +3275,11 @@ public NetworkOfferingVO createNetworkOffering(String name, String displayText,
32743275
+ type + " and service " + Service.SourceNat.getName() + " is supported");
32753276
}
32763277

3278+
// isPersistent should always be false for Shared network Offerings
3279+
if (isPersistent && type == GuestType.Shared) {
3280+
throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type);
3281+
}
3282+
32773283
// validate availability value
32783284
if (availability == NetworkOffering.Availability.Required) {
32793285
boolean canOffBeRequired = (type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat));
@@ -3352,7 +3358,7 @@ public NetworkOfferingVO createNetworkOffering(String name, String displayText,
33523358

33533359
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan,
33543360
networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb,
3355-
sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline);
3361+
sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent);
33563362

33573363
if (serviceOfferingId != null) {
33583364
offering.setServiceOfferingId(serviceOfferingId);

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

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
import com.cloud.org.Grouping;
7878
import com.cloud.user.*;
7979
import com.cloud.user.dao.AccountDao;
80+
import com.cloud.user.dao.UserDao;
81+
import com.cloud.utils.Journal;
8082
import com.cloud.utils.NumbersUtil;
8183
import com.cloud.utils.Pair;
8284
import com.cloud.utils.component.Adapters;
@@ -127,6 +129,8 @@ public class NetworkManagerImpl implements NetworkManager, Manager, Listener {
127129
@Inject
128130
DomainDao _domainDao = null;
129131
@Inject
132+
UserDao _userDao = null;
133+
@Inject
130134
ConfigurationDao _configDao;
131135
@Inject
132136
UserVmDao _userVmDao = null;
@@ -856,14 +860,14 @@ public boolean configure(final String name, final Map<String, Object> params) th
856860
NetworkOfferingVO offering = null;
857861
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
858862
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null,
859-
true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true);
863+
true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false);
860864
offering.setState(NetworkOffering.State.Enabled);
861865
_networkOfferingDao.update(offering.getId(), offering);
862866
}
863867

864868
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
865869
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null,
866-
defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true);
870+
defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false);
867871
offering.setState(NetworkOffering.State.Enabled);
868872
_networkOfferingDao.update(offering.getId(), offering);
869873
}
@@ -886,7 +890,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
886890
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService,
887891
"Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest,
888892
null, false, Availability.Required, null, defaultINetworkOfferingProvidersForVpcNetwork,
889-
true, Network.GuestType.Isolated, false, null, true, null, false);
893+
true, Network.GuestType.Isolated, false, null, true, null, false, false);
890894
offering.setState(NetworkOffering.State.Enabled);
891895
_networkOfferingDao.update(offering.getId(), offering);
892896
}
@@ -895,7 +899,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
895899
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks,
896900
"Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest,
897901
null, false, Availability.Optional, null, defaultVPCOffProviders,
898-
true, Network.GuestType.Isolated, false, null, false, null, false);
902+
true, Network.GuestType.Isolated, false, null, false, null, false, false);
899903
offering.setState(NetworkOffering.State.Enabled);
900904
_networkOfferingDao.update(offering.getId(), offering);
901905
}
@@ -906,7 +910,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
906910
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB,
907911
"Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest,
908912
null, false, Availability.Optional, null, defaultVPCOffProviders,
909-
true, Network.GuestType.Isolated, false, null, false, null, false);
913+
true, Network.GuestType.Isolated, false, null, false, null, false, false);
910914
offering.setState(NetworkOffering.State.Enabled);
911915
_networkOfferingDao.update(offering.getId(), offering);
912916
}
@@ -915,7 +919,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
915919
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering,
916920
"Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true,
917921
Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated,
918-
false, null, true, null, true);
922+
false, null, true, null, true, false);
919923
offering.setState(NetworkOffering.State.Enabled);
920924
_networkOfferingDao.update(offering.getId(), offering);
921925
}
@@ -944,7 +948,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
944948

945949
if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
946950
offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true,
947-
Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true);
951+
Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false);
948952
offering.setState(NetworkOffering.State.Enabled);
949953
offering.setDedicatedLB(false);
950954
_networkOfferingDao.update(offering.getId(), offering);
@@ -1999,8 +2003,6 @@ public Network createGuestNetwork(long networkOfferingId, String name, String di
19992003
return network;
20002004
}
20012005

2002-
2003-
20042006
@Override
20052007
@DB
20062008
public boolean shutdownNetwork(long networkId, ReservationContext context, boolean cleanupElements) {
@@ -2533,14 +2535,13 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
25332535
}
25342536

25352537
// create new Virtual network (Isolated with SourceNAT) for the user if it doesn't exist
2538+
List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
2539+
if (requiredOfferings.size() < 1) {
2540+
throw new CloudRuntimeException("Unable to find network offering with availability=" +
2541+
Availability.Required + " to automatically create the network as part of createVlanIpRange");
2542+
}
25362543
if (createNetwork) {
2537-
List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
2538-
if (requiredOfferings.size() < 1) {
2539-
throw new CloudRuntimeException("Unable to find network offering with availability=" +
2540-
Availability.Required + " to automatically create the network as part of createVlanIpRange");
2541-
}
25422544
if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
2543-
25442545
long physicalNetworkId = _networkModel.findPhysicalNetworkId(zoneId, requiredOfferings.get(0).getTags(), requiredOfferings.get(0).getTrafficType());
25452546
// Validate physical network
25462547
PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
@@ -2595,6 +2596,31 @@ public boolean associateIpAddressListToAccount(long userId, long accountId, long
25952596
}
25962597

25972598
txn.commit();
2599+
2600+
// if the network offering has persistent set to true, implement the network
2601+
if ( createNetwork && requiredOfferings.get(0).getIsPersistent() ) {
2602+
DataCenter zone = _dcDao.findById(zoneId);
2603+
DeployDestination dest = new DeployDestination(zone, null, null, null);
2604+
Account callerAccount = UserContext.current().getCaller();
2605+
UserVO callerUser = _userDao.findById(UserContext.current().getCallerUserId());
2606+
Journal journal = new Journal.LogJournal("Implementing " + guestNetwork, s_logger);
2607+
ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), journal, callerUser, callerAccount);
2608+
s_logger.debug("Implementing network " + guestNetwork + " as a part of network provision for persistent network");
2609+
try {
2610+
Pair<NetworkGuru, NetworkVO> implementedNetwork = implementNetwork(guestNetwork.getId(), dest, context);
2611+
if (implementedNetwork.first() == null) {
2612+
s_logger.warn("Failed to implement the network " + guestNetwork);
2613+
}
2614+
guestNetwork = implementedNetwork.second();
2615+
} catch (Exception ex) {
2616+
s_logger.warn("Failed to implement network " + guestNetwork + " elements and resources as a part of" +
2617+
" network provision due to ", ex);
2618+
CloudRuntimeException e = new CloudRuntimeException("Failed to implement network (with specified id)" +
2619+
" elements and resources as a part of network provision for persistent network");
2620+
e.addProxyObject(guestNetwork, guestNetwork.getId(), "networkId");
2621+
throw e;
2622+
}
2623+
}
25982624
return true;
25992625
}
26002626

0 commit comments

Comments
 (0)