mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
IPv6: CLOUDSTACK-1107: Add support for createVlanIpRange to extend existed network
This commit is contained in:
parent
1cf85aa87a
commit
0c5c08b78b
@ -24,6 +24,7 @@ import java.util.Set;
|
||||
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
@ -252,4 +253,6 @@ public interface NetworkModel {
|
||||
boolean isIP6AddressAvailableInNetwork(long networkId);
|
||||
|
||||
boolean isIP6AddressAvailableInVlan(long vlanId);
|
||||
|
||||
void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException;
|
||||
}
|
||||
@ -75,7 +75,7 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
description="optional parameter. Have to be specified for Direct Untagged vlan only.")
|
||||
private Long podId;
|
||||
|
||||
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the beginning IP address in the VLAN IP range")
|
||||
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the VLAN IP range")
|
||||
private String startIp;
|
||||
|
||||
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the VLAN. If not specified," +
|
||||
@ -94,6 +94,19 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
description="the physical network id")
|
||||
private Long physicalNetworkId;
|
||||
|
||||
@Parameter(name=ApiConstants.START_IPV6, type=CommandType.STRING, description="the beginning IPv6 address in the IPv6 network range")
|
||||
private String startIpv6;
|
||||
|
||||
@Parameter(name=ApiConstants.END_IPV6, type=CommandType.STRING, description="the ending IPv6 address in the IPv6 network range")
|
||||
private String endIpv6;
|
||||
|
||||
@Parameter(name=ApiConstants.IP6_GATEWAY, type=CommandType.STRING, description="the gateway of the IPv6 network. Required " +
|
||||
"for Shared networks and Isolated networks when it belongs to VPC")
|
||||
private String ip6Gateway;
|
||||
|
||||
@Parameter(name=ApiConstants.IP6_CIDR, type=CommandType.STRING, description="the CIDR of IPv6 network, must be at least /64")
|
||||
private String ip6Cidr;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -141,6 +154,35 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
public Long getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public String getStartIpv6() {
|
||||
if (startIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return startIpv6.toLowerCase();
|
||||
}
|
||||
|
||||
public String getEndIpv6() {
|
||||
if (endIpv6 == null) {
|
||||
return null;
|
||||
}
|
||||
return endIpv6.toLowerCase();
|
||||
}
|
||||
|
||||
public String getIp6Gateway() {
|
||||
if (ip6Gateway == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Gateway.toLowerCase();
|
||||
}
|
||||
|
||||
public String getIp6Cidr() {
|
||||
if (ip6Cidr == null) {
|
||||
return null;
|
||||
}
|
||||
return ip6Cidr.toLowerCase();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -153,7 +195,6 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
|
||||
return physicalNetworkId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
|
||||
@ -2073,13 +2073,34 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
String accountName = cmd.getAccountName();
|
||||
Long projectId = cmd.getProjectId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
String startIPv6 = cmd.getStartIpv6();
|
||||
String endIPv6 = cmd.getEndIpv6();
|
||||
String ip6Gateway = cmd.getIp6Gateway();
|
||||
String ip6Cidr = cmd.getIp6Cidr();
|
||||
|
||||
Account vlanOwner = null;
|
||||
|
||||
// if end ip is not specified, default it to startIp
|
||||
if (endIP == null && startIP != null) {
|
||||
endIP = startIP;
|
||||
boolean ipv4 = (startIP != null);
|
||||
boolean ipv6 = (startIPv6 != null);
|
||||
|
||||
if (!ipv4 && !ipv6) {
|
||||
throw new InvalidParameterValueException("StartIP or StartIPv6 is missing in the parameters!");
|
||||
}
|
||||
|
||||
|
||||
if (ipv4) {
|
||||
// if end ip is not specified, default it to startIp
|
||||
if (endIP == null && startIP != null) {
|
||||
endIP = startIP;
|
||||
}
|
||||
}
|
||||
|
||||
if (ipv6) {
|
||||
// if end ip is not specified, default it to startIp
|
||||
if (endIPv6 == null && startIPv6 != null) {
|
||||
endIPv6 = startIPv6;
|
||||
}
|
||||
}
|
||||
|
||||
if (projectId != null) {
|
||||
if (accountName != null) {
|
||||
throw new InvalidParameterValueException("Account and projectId are mutually exclusive");
|
||||
@ -2109,6 +2130,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
zoneId = network.getDataCenterId();
|
||||
physicalNetworkId = network.getPhysicalNetworkId();
|
||||
}
|
||||
} else if (ipv6) {
|
||||
throw new InvalidParameterValueException("Only support IPv6 on extending existed network");
|
||||
}
|
||||
|
||||
// Verify that zone exists
|
||||
@ -2117,6 +2140,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
throw new InvalidParameterValueException("Unable to find zone by id " + zoneId);
|
||||
}
|
||||
|
||||
if (ipv6) {
|
||||
if (network.getGuestType() != GuestType.Shared || zone.isSecurityGroupEnabled()) {
|
||||
throw new InvalidParameterValueException("Only support IPv6 on extending existed share network without SG");
|
||||
}
|
||||
}
|
||||
// verify that physical network exists
|
||||
PhysicalNetworkVO pNtwk = null;
|
||||
if (physicalNetworkId != null) {
|
||||
@ -2163,7 +2191,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
if (zone.isSecurityGroupEnabled() && zone.getNetworkType() != DataCenter.NetworkType.Basic && forVirtualNetwork) {
|
||||
throw new InvalidParameterValueException("Can't add virtual ip range into a zone with security group enabled");
|
||||
}
|
||||
|
||||
|
||||
// If networkId is not specified, and vlan is Virtual or Direct Untagged, try to locate default networks
|
||||
if (forVirtualNetwork) {
|
||||
if (network == null) {
|
||||
@ -2196,11 +2224,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
throw new InvalidParameterValueException("Network " + network + " doesn't support adding ip ranges");
|
||||
}
|
||||
|
||||
// if end ip is not specified, default it to startIp
|
||||
if (endIP == null && startIP != null) {
|
||||
endIP = startIP;
|
||||
}
|
||||
|
||||
if ( zone.getNetworkType() == DataCenter.NetworkType.Advanced ) {
|
||||
if (network.getTrafficType() == TrafficType.Guest) {
|
||||
if (network.getGuestType() != GuestType.Shared) {
|
||||
@ -2216,19 +2239,38 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" +
|
||||
+ network.getId() + ", only one vlan is allowed on guest network");
|
||||
}
|
||||
vlanGateway = vlan.getVlanGateway();
|
||||
vlanNetmask = vlan.getVlanNetmask();
|
||||
if (ipv4) {
|
||||
vlanGateway = vlan.getVlanGateway();
|
||||
vlanNetmask = vlan.getVlanNetmask();
|
||||
// Check if ip addresses are in network range
|
||||
if (!NetUtils.sameSubnet(startIP, vlanGateway, vlanNetmask)) {
|
||||
throw new InvalidParameterValueException("Start ip is not in vlan range!");
|
||||
}
|
||||
if (!NetUtils.sameSubnet(endIP, vlanGateway, vlanNetmask)) {
|
||||
throw new InvalidParameterValueException("End ip is not in vlan range!");
|
||||
}
|
||||
}
|
||||
if (ipv6) {
|
||||
if (ip6Gateway != null && !ip6Gateway.equals(network.getIp6Gateway())) {
|
||||
throw new InvalidParameterValueException("The input gateway " + ip6Gateway + " is not same as network gateway " + network.getIp6Gateway());
|
||||
}
|
||||
if (ip6Cidr != null && !ip6Cidr.equals(network.getIp6Cidr())) {
|
||||
throw new InvalidParameterValueException("The input cidr " + ip6Cidr + " is not same as network ciddr " + network.getIp6Cidr());
|
||||
}
|
||||
ip6Gateway = network.getIp6Gateway();
|
||||
ip6Cidr = network.getIp6Cidr();
|
||||
_networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
}
|
||||
}
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
|
||||
}
|
||||
}
|
||||
|
||||
if (vlanGateway == null || vlanNetmask == null || zoneId == null) {
|
||||
if (zoneId == null || (ipv4 && (vlanGateway == null || vlanNetmask == null)) || (ipv6 && (ip6Gateway == null || ip6Cidr == null))) {
|
||||
throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
|
||||
}
|
||||
|
||||
|
||||
// if it's an account specific range, associate ip address list to the account
|
||||
boolean associateIpRangeToAccount = false;
|
||||
|
||||
@ -2245,12 +2287,14 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
||||
}
|
||||
|
||||
// Check if the IP range overlaps with the private ip
|
||||
checkOverlapPrivateIpRange(zoneId, startIP, endIP);
|
||||
if (ipv4) {
|
||||
checkOverlapPrivateIpRange(zoneId, startIP, endIP);
|
||||
}
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP,
|
||||
endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, null, null, null, null);
|
||||
endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner, startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
|
||||
if (associateIpRangeToAccount) {
|
||||
_networkMgr.associateIpAddressListToAccount(userId, vlanOwner.getId(), zoneId, vlan.getId(), null);
|
||||
|
||||
@ -1876,4 +1876,40 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||
return offering.isInline();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIp6Parameters(String startIPv6, String endIPv6,
|
||||
String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException {
|
||||
if (!NetUtils.isValidIpv6(startIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the startIPv6 parameter");
|
||||
}
|
||||
if (!NetUtils.isValidIpv6(endIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the endIPv6 parameter");
|
||||
}
|
||||
|
||||
if (!(ip6Gateway != null && ip6Cidr != null)) {
|
||||
throw new InvalidParameterValueException("ip6Gateway and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
|
||||
}
|
||||
|
||||
if (!NetUtils.isValidIpv6(ip6Gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid ip6Gateway");
|
||||
}
|
||||
if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("Invalid ip6cidr");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated network!");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network!");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("ip6Gateway is not in ip6cidr indicated network!");
|
||||
}
|
||||
|
||||
int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);
|
||||
// Ipv6 cidr limit should be at least /64
|
||||
if (cidrSize < 64) {
|
||||
throw new InvalidParameterValueException("The cidr size of IPv6 network must be no less than 64 bits!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,43 +761,11 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
}
|
||||
|
||||
if (ipv6) {
|
||||
if (!NetUtils.isValidIpv6(startIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the startIPv6 parameter");
|
||||
}
|
||||
if (endIPv6 == null) {
|
||||
endIPv6 = startIPv6;
|
||||
} else if (!NetUtils.isValidIpv6(endIPv6)) {
|
||||
throw new InvalidParameterValueException("Invalid format for the endIPv6 parameter");
|
||||
}
|
||||
_networkModel.checkIp6Parameters(startIPv6, endIPv6, ip6Gateway, ip6Cidr);
|
||||
|
||||
if (!(ip6Gateway != null && ip6Cidr != null)) {
|
||||
throw new InvalidParameterValueException("ip6Gateway and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
|
||||
}
|
||||
|
||||
if (!NetUtils.isValidIpv6(ip6Gateway)) {
|
||||
throw new InvalidParameterValueException("Invalid ip6Gateway");
|
||||
}
|
||||
if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("Invalid ip6cidr");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated network!");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network!");
|
||||
}
|
||||
if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
|
||||
throw new InvalidParameterValueException("ip6Gateway is not in ip6cidr indicated network!");
|
||||
}
|
||||
|
||||
int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);
|
||||
// Ipv6 cidr limit should be at least /64
|
||||
if (cidrSize < 64) {
|
||||
throw new InvalidParameterValueException("The cidr size of IPv6 network must be no less than 64 bits!");
|
||||
}
|
||||
}
|
||||
|
||||
if (ipv6) {
|
||||
if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
|
||||
throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
|
||||
}
|
||||
@ -2942,10 +2910,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Network getNetwork(String networkUuid) {
|
||||
return _networksDao.findByUuid(networkUuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
@ -820,4 +821,12 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIp6Parameters(String startIPv6, String endIPv6,
|
||||
String ip6Gateway, String ip6Cidr)
|
||||
throws InvalidParameterValueException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,7 @@ import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.dc.Vlan;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
@ -835,4 +836,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr)
|
||||
throws InvalidParameterValueException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user