Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions api/src/main/java/com/cloud/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,8 @@ public void setIp6Address(String ip6Address) {
String getExternalId();

PVlanType getPvlanType();

String getRouterIp();

String getRouterIpv6();
}
10 changes: 10 additions & 0 deletions api/src/main/java/com/cloud/network/NetworkProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,14 @@ public PVlanType getPvlanType() {
return null;
}

@Override
public String getRouterIp() {
return null;
}

@Override
public String getRouterIpv6() {
return null;
}

}
2 changes: 2 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ public class ApiConstants {
public static final String ROUTER_HEALTH_CHECKS = "healthchecks";
public static final String ROUTER_CHECK_NAME = "checkname";
public static final String ROUTER_CHECK_TYPE = "checktype";
public static final String ROUTER_IP = "routerip";
public static final String ROUTER_IPV6 = "routeripv6";
public static final String LAST_UPDATED = "lastupdated";
public static final String PERFORM_FRESH_CHECKS = "performfreshchecks";
public static final String CACHE_MODE = "cachemode";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command.admin.network;

import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.log4j.Logger;

import org.apache.cloudstack.api.APICommand;
Expand All @@ -42,6 +43,14 @@ public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCm
@Parameter(name=ApiConstants.HIDE_IP_ADDRESS_USAGE, type=CommandType.BOOLEAN, description="when true ip address usage for the network will not be exported by the listUsageRecords API")
private Boolean hideIpAddressUsage;

@Parameter(name = ApiConstants.ROUTER_IP, type = CommandType.STRING, description = "IPV4 address to be assigned to a router in a shared network", since = "4.16",
validations = {ApiArgValidator.NotNullOrEmpty})
private String routerIp;

@Parameter(name = ApiConstants.ROUTER_IPV6, type = CommandType.STRING, description = "IPV6 address to be assigned to a router in a shared network", since = "4.16",
validations = {ApiArgValidator.NotNullOrEmpty})
private String routerIpv6;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand All @@ -63,4 +72,12 @@ public Boolean getHideIpAddressUsage() {
}
return false;
}

public String getRouterIp() {
return routerIp;
}

public String getRouterIpv6() {
return routerIpv6;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationC

Network createGuestNetwork(long networkOfferingId, String name, String displayText, String gateway, String cidr, String vlanId, boolean bypassVlanOverlapCheck, String networkDomain, Account owner,
Long domainId, PhysicalNetwork physicalNetwork, long zoneId, ACLType aclType, Boolean subdomainAccess, Long vpcId, String ip6Gateway, String ip6Cidr,
Boolean displayNetworkEnabled, String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;
Boolean displayNetworkEnabled, String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, String routerIp, String routerIpv6) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException;

UserDataServiceProvider getPasswordResetProvider(Network network);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ protected NetworkOrchestrator() {
setStateMachine();
}

private void updateRouterIpInNetworkDetails(Long networkId, String routerIp, String routerIpv6) {
if (isNotBlank(routerIp)) {
networkDetailsDao.addDetail(networkId, ApiConstants.ROUTER_IP, routerIp, true);
}
if (isNotBlank(routerIpv6)) {
networkDetailsDao.addDetail(networkId, ApiConstants.ROUTER_IPV6, routerIpv6, true);
}
}

@Override
public List<? extends Network> setupNetwork(final Account owner, final NetworkOffering offering, final DeploymentPlan plan, final String name, final String displayText, final boolean isDefault)
throws ConcurrentOperationException {
Expand Down Expand Up @@ -722,6 +731,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
networkDetailsDao.persist(detailVO);
}

updateRouterIpInNetworkDetails(networkPersisted.getId(), network.getRouterIp(), network.getRouterIpv6());

if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions){
final NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO)predefined).getVlanIdAsUUID());
Expand Down Expand Up @@ -2314,26 +2325,26 @@ public Network createPrivateNetwork(final long networkOfferingId, final String n
// create network for private gateway
return createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId,
bypassVlanOverlapCheck, null, owner, null, pNtwk, pNtwk.getDataCenterId(), ACLType.Account, null,
vpcId, null, null, true, null, null, null, true);
vpcId, null, null, true, null, null, null, true, null, null);
}

@Override
@DB
public Network createGuestNetwork(final long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId,
boolean bypassVlanOverlapCheck, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk,
final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, String routerIp, String routerIpv6) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
// create Isolated/Shared/L2 network
return createGuestNetwork(networkOfferingId, name, displayText, gateway, cidr, vlanId, bypassVlanOverlapCheck,
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, ip6Gateway, ip6Cidr,
isDisplayNetworkEnabled, isolatedPvlan, isolatedPvlanType, externalId, false);
isDisplayNetworkEnabled, isolatedPvlan, isolatedPvlanType, externalId, false, routerIp, routerIpv6);
}

@DB
private Network createGuestNetwork(final long networkOfferingId, final String name, final String displayText, final String gateway, final String cidr, String vlanId,
boolean bypassVlanOverlapCheck, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk,
final long zoneId, final ACLType aclType, Boolean subdomainAccess, final Long vpcId, final String ip6Gateway, final String ip6Cidr,
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, final Boolean isPrivateNetwork) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
final Boolean isDisplayNetworkEnabled, final String isolatedPvlan, Network.PVlanType isolatedPvlanType, String externalId, final Boolean isPrivateNetwork, String routerIp, String routerIpv6) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {

final NetworkOfferingVO ntwkOff = _networkOfferingDao.findById(networkOfferingId);
final DataCenterVO zone = _dcDao.findById(zoneId);
Expand Down Expand Up @@ -2594,6 +2605,14 @@ public Network doInTransaction(final TransactionStatus status) {
userNetwork.setExternalId(externalId);
}

if (isNotBlank(routerIp)) {
userNetwork.setRouterIp(routerIp);
}

if (isNotBlank(routerIpv6)) {
userNetwork.setRouterIpv6(routerIpv6);
}

if (vlanIdFinal != null) {
if (isolatedPvlan == null) {
URI uri = null;
Expand Down Expand Up @@ -2633,7 +2652,6 @@ public Network doInTransaction(final TransactionStatus status) {

final List<? extends Network> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId, aclType, subdomainAccessFinal, vpcId,
isDisplayNetworkEnabled);

Network network = null;
if (networks == null || networks.isEmpty()) {
throw new CloudRuntimeException("Fail to create a network");
Expand Down
22 changes: 22 additions & 0 deletions engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public class NetworkVO implements Network {
@Column(name = "external_id")
String externalId;

@Transient
String routerIp;

@Transient
String routerIpv6;

@Transient
transient String vlanIdAsUUID;

Expand Down Expand Up @@ -672,4 +678,20 @@ public PVlanType getPvlanType() {
public void setPvlanType(PVlanType pvlanType) {
this.pVlanType = pvlanType;
}

public String getRouterIp() {
return routerIp;
}

public void setRouterIp(String routerIp) {
this.routerIp = routerIp;
}

public String getRouterIpv6() {
return routerIpv6;
}

public void setRouterIpv6(String routerIpv6) {
this.routerIpv6 = routerIpv6;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ private Network getKubernetesClusterNetworkIfMissing(final String clusterName, f

try {
network = networkMgr.createGuestNetwork(networkOffering.getId(), clusterName + "-network", owner.getAccountName() + "-network",
null, null, null, false, null, owner, null, physicalNetwork, zone.getId(), ControlledEntity.ACLType.Account, null, null, null, null, true, null, null, null);
null, null, null, false, null, owner, null, physicalNetwork, zone.getId(), ControlledEntity.ACLType.Account, null, null, null, null, true, null, null, null, null, null);
} catch (ConcurrentOperationException | InsufficientCapacityException | ResourceAllocationException e) {
logAndThrow(Level.ERROR, String.format("Unable to create network for the Kubernetes cluster: %s", clusterName));
}
Expand Down
12 changes: 9 additions & 3 deletions server/src/main/java/com/cloud/network/IpAddressManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.response.AcquirePodIpCmdResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
Expand Down Expand Up @@ -850,10 +851,16 @@ public IPAddressVO doInTransaction(TransactionStatus status) throws Insufficient
errorMessage.append(", network id=" + guestNetworkId);
}
sc.setJoinParameters("vlan", "type", vlanUse);

String routerIpAddress = null;
if (network != null) {
NetworkDetailVO routerIpDetail = _networkDetailsDao.findDetail(network.getId(), ApiConstants.ROUTER_IP);
routerIpAddress = routerIpDetail != null ? routerIpDetail.getValue() : null;
}
if (requestedIp != null) {
sc.addAnd("address", SearchCriteria.Op.EQ, requestedIp);
errorMessage.append(": requested ip " + requestedIp + " is not available");
} else if (routerIpAddress != null) {
sc.addAnd("address", Op.NEQ, routerIpAddress);
}

boolean ascOrder = ! forSystemVms;
Expand Down Expand Up @@ -1729,7 +1736,7 @@ public Ternary<Boolean, List<NetworkOfferingVO>, Network> doInTransaction(Transa
s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId()
+ " as a part of createVlanIpRange process");
guestNetwork = _networkMgr.createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName()
+ "-network", null, null, null, false, null, owner, null, physicalNetwork, zoneId, ACLType.Account, null, null, null, null, true, null, null, null);
+ "-network", null, null, null, false, null, owner, null, physicalNetwork, zoneId, ACLType.Account, null, null, null, null, true, null, null, null, null, null);
if (guestNetwork == null) {
s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId);
throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT "
Expand Down Expand Up @@ -2104,7 +2111,6 @@ public void allocateDirectIp(final NicProfile nic, final DataCenter dc, final Vi
public void doInTransactionWithoutResult(TransactionStatus status) throws InsufficientAddressCapacityException {
//This method allocates direct ip for the Shared network in Advance zones
boolean ipv4 = false;

if (network.getGateway() != null) {
if (nic.getIPv4Address() == null) {
PublicIp ip = null;
Expand Down
Loading