Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ public class ApiConstants {
public static final String ACL_NAME = "aclname";
public static final String NUMBER = "number";
public static final String IS_DYNAMICALLY_SCALABLE = "isdynamicallyscalable";
public static final String ROUTED_MODE_ENABLED = "routedmodeenabled";
public static final String ROUTING = "isrouting";
public static final String ROUTING_MODE = "routingmode";
public static final String MAX_CONNECTIONS = "maxconnections";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public class ZoneResponse extends BaseResponseWithAnnotations implements SetReso
@Param(description = "AS Number Range")
private String asnRange;

@SerializedName(ApiConstants.ROUTED_MODE_ENABLED)
@Param(description = "true, if routed network/vpc is enabled", since = "4.20.1")
private boolean routedModeEnabled = false;


public ZoneResponse() {
tags = new LinkedHashSet<ResourceTagResponse>();
}
Expand Down Expand Up @@ -412,4 +417,12 @@ public void setAsnRange(String asnRange) {
public String getAsnRange() {
return asnRange;
}

public boolean isRoutedModeEnabled() {
return routedModeEnabled;
}

public void setRoutedModeEnabled(boolean routedModeEnabled) {
this.routedModeEnabled = routedModeEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@

public interface RoutedIpv4Manager extends PluggableService, Configurable {

ConfigKey<Boolean> RoutedNetworkVpcEnabled = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Boolean.class,
"routed.network.vpc.enabled",
"true",
"If true, the Routed network and VPC are enabled in the zone.",
true,
ConfigKey.Scope.Zone);

ConfigKey<Integer> RoutedNetworkIPv4MaxCidrSize = new ConfigKey<>(ConfigKey.CATEGORY_NETWORK, Integer.class,
"routed.network.ipv4.max.cidr.size", "30", "The maximum value of the cidr size for isolated networks in ROUTED mode",
true, ConfigKey.Scope.Account);
Expand Down Expand Up @@ -196,4 +203,6 @@ public interface RoutedIpv4Manager extends PluggableService, Configurable {
void removeBgpPeersByAccountId(long accountId);

void removeBgpPeersByDomainId(long domainId);

Boolean isRoutedNetworkVpcEnabled(long zoneId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.cloudstack.api.response.ResourceTagResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.network.RoutedIpv4Manager;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -141,6 +142,8 @@ public ZoneResponse newDataCenterResponse(ResponseView view, DataCenterJoinVO da
String asRange = asNumberRange.stream().map(range -> range.getStartASNumber() + "-" + range.getEndASNumber()).collect(Collectors.joining(", "));
zoneResponse.setAsnRange(asRange);

zoneResponse.setRoutedModeEnabled(RoutedIpv4Manager.RoutedNetworkVpcEnabled.valueIn(dataCenter.getId()));

zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
zoneResponse.setHasAnnotation(annotationDao.hasAnnotations(dataCenter.getUuid(), AnnotationService.EntityType.ZONE.name(),
_accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
Expand Down
12 changes: 8 additions & 4 deletions server/src/main/java/com/cloud/network/NetworkServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ private void checkSharedNetworkCidrOverlap(Long zoneId, long physicalNetworkId,
}
}

void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, NetworkOffering networkOffering, long accountId) {
void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, NetworkOffering networkOffering, long accountId, long zoneId) {
if (!GuestType.Isolated.equals(networkOffering.getGuestType())) {
if (cidrSize != null) {
throw new InvalidParameterValueException("network cidr size is only applicable on Isolated networks");
Expand All @@ -1394,6 +1394,10 @@ void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, Netw
if (ObjectUtils.allNotNull(cidr, cidrSize)) {
throw new InvalidParameterValueException("network cidr and cidr size are mutually exclusive");
}
if (NetworkOffering.NetworkMode.ROUTED.equals(networkOffering.getNetworkMode())
&& !routedIpv4Manager.isRoutedNetworkVpcEnabled(zoneId)) {
throw new InvalidParameterValueException("Routed network is not enabled in this zone");
}
if (NetworkOffering.NetworkMode.ROUTED.equals(networkOffering.getNetworkMode())
&& routedIpv4Manager.isVirtualRouterGateway(networkOffering)) {
if (cidr != null) {
Expand All @@ -1405,11 +1409,11 @@ void validateNetworkCidrSize(Account caller, Integer cidrSize, String cidr, Netw
if (cidrSize == null) {
throw new InvalidParameterValueException("network cidr or cidr size is required for Isolated networks with ROUTED mode");
}
Integer maxCidrSize = routedIpv4Manager.RoutedNetworkIPv4MaxCidrSize.valueIn(accountId);
Integer maxCidrSize = RoutedIpv4Manager.RoutedNetworkIPv4MaxCidrSize.valueIn(accountId);
if (cidrSize > maxCidrSize) {
throw new InvalidParameterValueException("network cidr size cannot be bigger than maximum cidr size " + maxCidrSize);
}
Integer minCidrSize = routedIpv4Manager.RoutedNetworkIPv4MinCidrSize.valueIn(accountId);
Integer minCidrSize = RoutedIpv4Manager.RoutedNetworkIPv4MinCidrSize.valueIn(accountId);
if (cidrSize < minCidrSize) {
throw new InvalidParameterValueException("network cidr size cannot be smaller than minimum cidr size " + minCidrSize);
}
Expand Down Expand Up @@ -1655,7 +1659,7 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
throw new InvalidParameterValueException("AS number is required for the network but not passed.");
}

validateNetworkCidrSize(caller, networkCidrSize, cidr, ntwkOff, owner.getAccountId());
validateNetworkCidrSize(caller, networkCidrSize, cidr, ntwkOff, owner.getAccountId(), zone.getId());

validateSharedNetworkRouterIPs(gateway, startIP, endIP, netmask, routerIPv4, routerIPv6, startIPv6, endIPv6, ip6Cidr, ntwkOff);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwner
}

// Validate VPC cidr/cidrsize
validateVpcCidrSize(caller, owner.getAccountId(), vpcOff, cidr, cidrSize);
validateVpcCidrSize(caller, owner.getAccountId(), vpcOff, cidr, cidrSize, zoneId);

// Validate BGP peers
if (CollectionUtils.isNotEmpty(bgpPeerIds)) {
Expand Down Expand Up @@ -1247,13 +1247,17 @@ public Vpc createVpc(final long zoneId, final long vpcOffId, final long vpcOwner
return newVpc;
}

private void validateVpcCidrSize(Account caller, long accountId, VpcOffering vpcOffering, String cidr, Integer cidrSize) {
private void validateVpcCidrSize(Account caller, long accountId, VpcOffering vpcOffering, String cidr, Integer cidrSize, long zoneId) {
if (ObjectUtils.allNull(cidr, cidrSize)) {
throw new InvalidParameterValueException("VPC cidr or cidr size must be specified");
}
if (ObjectUtils.allNotNull(cidr, cidrSize)) {
throw new InvalidParameterValueException("VPC cidr and cidr size are mutually exclusive");
}
if (NetworkOffering.NetworkMode.ROUTED.equals(vpcOffering.getNetworkMode())
&& !routedIpv4Manager.RoutedNetworkVpcEnabled.valueIn(zoneId)) {
throw new InvalidParameterValueException("Routed VPC is not enabled in this zone");
}
if (routedIpv4Manager.isVpcVirtualRouterGateway(vpcOffering)) {
if (cidr != null) {
if (!_accountMgr.isRootAdmin(caller.getId())) {
Expand Down
11 changes: 0 additions & 11 deletions server/src/main/java/com/cloud/server/ManagementServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@
import org.apache.cloudstack.api.command.admin.alert.GenerateAlertCmd;
import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
import org.apache.cloudstack.api.command.admin.autoscale.DeleteCounterCmd;
import org.apache.cloudstack.api.command.admin.bgp.CreateASNRangeCmd;
import org.apache.cloudstack.api.command.admin.bgp.DeleteASNRangeCmd;
import org.apache.cloudstack.api.command.admin.bgp.ListASNRangesCmd;
import org.apache.cloudstack.api.command.user.bgp.ListASNumbersCmd;
import org.apache.cloudstack.api.command.admin.bgp.ReleaseASNumberCmd;
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
Expand Down Expand Up @@ -4017,12 +4012,6 @@ public List<Class<?>> getCommands() {
cmdList.add(RemoveSecondaryStorageSelectorCmd.class);
cmdList.add(ListAffectedVmsForStorageScopeChangeCmd.class);

cmdList.add(CreateASNRangeCmd.class);
cmdList.add(ListASNRangesCmd.class);
cmdList.add(DeleteASNRangeCmd.class);
cmdList.add(ListASNumbersCmd.class);
cmdList.add(ReleaseASNumberCmd.class);

// Out-of-band management APIs for admins
cmdList.add(EnableOutOfBandManagementForHostCmd.class);
cmdList.add(DisableOutOfBandManagementForHostCmd.class);
Expand Down
Loading