bug 7192: Added networktype parameter for the zone

status 7192: resolved fixed

1) Zone has networktype parameter now, 2 values are supported: Basic and Advanced. "networktype" field is created in data_center table. The parameter is being set at creation time; we don't allow to modify it with updateZone command.
2) Only vlan of Untagged Direct type can be created in Basic network zone; any other vlan except for Untagged Direct can be created in Advanced zone
3) Allow NULL guest vlan range for the zone. Only vlan of Direct type can be created in zone with NULL guest vlan.
4) "Default" zone is Basic by default.
5) Changed "vnet" parameter to "vlan" in updateZone command to be consistent with createZone
This commit is contained in:
alena 2010-11-16 16:43:46 -08:00
parent b577015795
commit dae39942f1
15 changed files with 198 additions and 166 deletions

View File

@ -9,6 +9,10 @@ import com.cloud.org.Grouping;
* *
*/ */
public interface DataCenter extends Grouping { public interface DataCenter extends Grouping {
public enum DataCenterNetworkType {
Basic,
Advanced
}
long getId(); long getId();
String getDns1(); String getDns1();
String getDns2(); String getDns2();

View File

@ -6,7 +6,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/utils"/> <classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/> <classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/> <classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson-1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/> <classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/> <classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-dbcp-1.2.2.jar"/> <classpathentry kind="lib" path="/thirdparty/commons-dbcp-1.2.2.jar"/>
@ -40,5 +39,6 @@
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/> <classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/> <classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/> <classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -20,6 +20,8 @@ package com.cloud.dc;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
@ -68,16 +70,20 @@ public class DataCenterVO implements DataCenter {
@Column(name="domain") @Column(name="domain")
private String domain = null; private String domain = null;
@Column(name="networktype")
@Enumerated(EnumType.STRING)
DataCenterNetworkType networkType;
@Column(name="mac_address", updatable = false, nullable=false) @Column(name="mac_address", updatable = false, nullable=false)
@TableGenerator(name="mac_address_sq", table="data_center", pkColumnName="id", valueColumnName="mac_address", allocationSize=1) @TableGenerator(name="mac_address_sq", table="data_center", pkColumnName="id", valueColumnName="mac_address", allocationSize=1)
private long macAddress = 1; private long macAddress = 1;
public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId) { public DataCenterVO(long id, String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId, DataCenterNetworkType zoneType) {
this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain, domainId); this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain, domainId, zoneType);
this.id = id; this.id = id;
} }
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId) { public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId, DataCenterNetworkType zoneType) {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.dns1 = dns1; this.dns1 = dns1;
@ -88,6 +94,7 @@ public class DataCenterVO implements DataCenter {
this.guestNetworkCidr = guestCidr; this.guestNetworkCidr = guestCidr;
this.domain = domain; this.domain = domain;
this.domainId = domainId; this.domainId = domainId;
this.networkType = zoneType;
} }
public Long getDomainId() { public Long getDomainId() {
@ -184,4 +191,12 @@ public class DataCenterVO implements DataCenter {
this.domain = domain; this.domain = domain;
} }
public void setNetworkType(DataCenterNetworkType zoneNetworkType) {
this.networkType = zoneNetworkType;
}
public DataCenterNetworkType getNetworkType() {
return networkType;
}
} }

View File

@ -8,7 +8,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/core"/> <classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/> <classpathentry kind="lib" path="/thirdparty/cglib-nodep-2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/> <classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson-1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/> <classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/httpcore-4.0.jar"/> <classpathentry kind="lib" path="/thirdparty/httpcore-4.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/email.jar"/> <classpathentry kind="lib" path="/thirdparty/email.jar"/>
@ -22,5 +21,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/api"/> <classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/> <classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/xstream-1.3.1.jar"/> <classpathentry kind="lib" path="/thirdparty/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -160,4 +160,5 @@ public class ApiConstants {
public static final String VNET = "vnet"; public static final String VNET = "vnet";
public static final String VOLUME_ID = "volumeid"; public static final String VOLUME_ID = "volumeid";
public static final String ZONE_ID = "zoneid"; public static final String ZONE_ID = "zoneid";
public static final String NETWORK_TYPE = "networktype";
} }

View File

@ -101,7 +101,6 @@ import com.cloud.vm.SystemVm;
import com.cloud.vm.UserVmVO; import com.cloud.vm.UserVmVO;
import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VmStats; import com.cloud.vm.VmStats;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
public class ApiResponseHelper { public class ApiResponseHelper {
@ -810,6 +809,7 @@ public class ApiResponseHelper {
zoneResponse.setDomain(dataCenter.getDomain()); zoneResponse.setDomain(dataCenter.getDomain());
zoneResponse.setDomainId(dataCenter.getDomainId()); zoneResponse.setDomainId(dataCenter.getDomainId());
zoneResponse.setType(dataCenter.getNetworkType().toString());
zoneResponse.setObjectName("zone"); zoneResponse.setObjectName("zone");
return zoneResponse; return zoneResponse;
} }

View File

@ -31,52 +31,8 @@ public class ResponseObjectTypeAdapter implements JsonSerializer<ResponseObject>
obj.addProperty("errortext", ((ExceptionResponse)responseObj).getErrorText()); obj.addProperty("errortext", ((ExceptionResponse)responseObj).getErrorText());
return obj; return obj;
} else { } else {
// Get the declared fields from the response obj, create a new JSON Object, add props to it. obj.add(responseObj.getObjectName(), ApiGsonHelper.getBuilder().create().toJsonTree(responseObj));
// Once that object is done, create a new JSON Object with the response name and the JSON Obj as the name/value pair. Return that as the serialized element. return obj;
Field[] fields = responseObj.getClass().getDeclaredFields();
for (Field field : fields) {
if ((field.getModifiers() & Modifier.TRANSIENT) != 0) {
continue; // skip transient fields
}
SerializedName serializedName = field.getAnnotation(SerializedName.class);
if (serializedName == null) {
continue; // skip fields w/o serialized name
}
String propName = field.getName();
Method method = getGetMethod(responseObj, propName);
if (method != null) {
try {
Object fieldValue = method.invoke(responseObj);
if (fieldValue != null) {
if (fieldValue instanceof ResponseObject) {
ResponseObject subObj = (ResponseObject)fieldValue;
obj.add(serializedName.value(), serialize(subObj, subObj.getClass(), ctx));
} else {
if (fieldValue instanceof Number) {
obj.addProperty(serializedName.value(), (Number)fieldValue);
} else if (fieldValue instanceof Character) {
obj.addProperty(serializedName.value(), (Character)fieldValue);
} else if (fieldValue instanceof Boolean) {
obj.addProperty(serializedName.value(), (Boolean)fieldValue);
} else {
obj.addProperty(serializedName.value(), fieldValue.toString());
}
}
}
} catch (IllegalArgumentException e) {
s_logger.error("Illegal argument exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (IllegalAccessException e) {
s_logger.error("Illegal access exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
} catch (InvocationTargetException e) {
s_logger.error("Invocation target exception when calling ResponseObject " + responseObj.getClass().getName() + " get method for property: " + propName);
}
}
}
JsonObject response = new JsonObject();
response.add(responseObj.getObjectName(), obj);
return response;
} }
} }

View File

@ -58,8 +58,7 @@ public class CreateZoneCmd extends BaseCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Zone") @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Zone")
private String zoneName; private String zoneName;
//FIXME - this parameter is called "vnet" in updateZone. Have to figure out which one is right @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VLAN for the Zone")
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VNET for the Zone")
private String vlan; private String vlan;
@Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone") @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone")
@ -68,6 +67,9 @@ public class CreateZoneCmd extends BaseCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public zones") @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public zones")
private Long domainId; private Long domainId;
@Parameter(name=ApiConstants.NETWORK_TYPE, type=CommandType.STRING, required=true, description="network type of the zone, can be Basic or Advanced")
private String networkType;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// /////////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -108,6 +110,10 @@ public class CreateZoneCmd extends BaseCmd {
return domainId; return domainId;
} }
public String getNetworkType(){
return networkType;
}
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////// API Implementation/////////////////// /////////////// API Implementation///////////////////

View File

@ -61,8 +61,8 @@ public class UpdateZoneCmd extends BaseCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the Zone") @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the Zone")
private String zoneName; private String zoneName;
@Parameter(name=ApiConstants.VNET, type=CommandType.STRING, description="the VNET for the Zone") @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VLAN for the Zone")
private String vnet; private String vlan;
// @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone") // @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone")
// private String domain; // private String domain;
@ -102,8 +102,8 @@ public class UpdateZoneCmd extends BaseCmd {
return zoneName; return zoneName;
} }
public String getVnet() { public String getVlan() {
return vnet; return vlan;
} }
// public String getDomain() { // public String getDomain() {

View File

@ -63,6 +63,9 @@ public class ZoneResponse extends BaseResponse {
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the containing domain, null for public zones") @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the ID of the containing domain, null for public zones")
private Long domainId; private Long domainId;
@SerializedName(ApiConstants.NETWORK_TYPE) @Param(description="the network type of the zone; can be Basic or Advanced")
private String networkType;
public Long getId() { public Long getId() {
return id; return id;
} }
@ -167,4 +170,12 @@ public class ZoneResponse extends BaseResponse {
this.domainId = domainId; this.domainId = domainId;
} }
public String getNetworkType() {
return networkType;
}
public void setType(String networkType) {
this.networkType = networkType;
}
} }

View File

@ -20,6 +20,7 @@ package com.cloud.configuration;
import java.util.List; import java.util.List;
import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
@ -97,11 +98,12 @@ public interface ConfigurationManager extends Manager {
* @param internalDns2 * @param internalDns2
* @param vnetRange * @param vnetRange
* @param guestCidr * @param guestCidr
* @param zoneType
* @return * @return
* @throws * @throws
* @throws * @throws
*/ */
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId); DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, DataCenterNetworkType zoneType);
/** /**
* Associates an ip address list to an account. The list of ip addresses are all addresses associated with the given vlan id. * Associates an ip address list to an account. The list of ip addresses are all addresses associated with the given vlan id.

View File

@ -52,6 +52,7 @@ import com.cloud.configuration.ResourceCount.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.AccountVlanMapVO;
import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.DataCenterIpAddressVO; import com.cloud.dc.DataCenterIpAddressVO;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
@ -858,7 +859,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String dns2 = cmd.getDns2(); String dns2 = cmd.getDns2();
String internalDns1 = cmd.getInternalDns1(); String internalDns1 = cmd.getInternalDns1();
String internalDns2 = cmd.getInternalDns2(); String internalDns2 = cmd.getInternalDns2();
String vnetRange = cmd.getVnet(); String vnetRange = cmd.getVlan();
String guestCidr = cmd.getGuestCidrAddress(); String guestCidr = cmd.getGuestCidrAddress();
// String domain = cmd.getDomain(); // String domain = cmd.getDomain();
Long userId = UserContext.current().getUserId(); Long userId = UserContext.current().getUserId();
@ -992,12 +993,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} }
@Override @DB @Override @DB
public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId) { public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, DataCenterNetworkType zoneType) {
int vnetStart = -1; int vnetStart = 0;
int vnetEnd = -1; int vnetEnd = 0;
if (vnetRange != null) { if (vnetRange != null) {
String[] tokens = vnetRange.split("-"); String[] tokens = vnetRange.split("-");
try { try {
vnetStart = Integer.parseInt(tokens[0]); vnetStart = Integer.parseInt(tokens[0]);
if (tokens.length == 1) { if (tokens.length == 1) {
@ -1008,12 +1008,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new InvalidParameterValueException("Please specify valid integers for the vlan range."); throw new InvalidParameterValueException("Please specify valid integers for the vlan range.");
} }
} else {
String networkType = _configDao.getValue("network.type");
if (networkType != null && networkType.equals("vnet")) {
vnetStart = 1000;
vnetEnd = 2000;
}
} }
//checking the following params outside checkzoneparams method as we do not use these params for updatezone //checking the following params outside checkzoneparams method as we do not use these params for updatezone
@ -1025,15 +1019,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId); checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId);
// Create the new zone in the database // Create the new zone in the database
DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId); DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId, zoneType);
zone = _zoneDao.persist(zone); zone = _zoneDao.persist(zone);
// Add vnet entries for the new zone // Add vnet entries for the new zone if zone type is Advanced
if (vnetStart != -1 && vnetEnd != -1) { if (vnetRange != null) {
_zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd); _zoneDao.addVnet(zone.getId(), vnetStart, vnetEnd);
} }
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_CREATE, "Successfully created new zone with name: " + zoneName + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "vnetRange=" + vnetRange, "guestCidr=" + guestCidr);
if (vnetRange != null) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_CREATE, "Successfully created new zone with name: " + zoneName + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "vnetRange=" + vnetRange, "guestCidr=" + guestCidr);
} else {
saveConfigurationEvent(userId, null, EventTypes.EVENT_ZONE_CREATE, "Successfully created new zone with name: " + zoneName + ".", "dcId=" + zone.getId(), "dns1=" + dns1, "dns2=" + dns2, "internalDns1=" + internalDns1, "internalDns2=" + internalDns2, "guestCidr=" + guestCidr);
}
return zone; return zone;
} }
@ -1050,6 +1048,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String guestCidr = cmd.getGuestCidrAddress(); String guestCidr = cmd.getGuestCidrAddress();
String domain = cmd.getDomain();//we are not passing domain right now, always null String domain = cmd.getDomain();//we are not passing domain right now, always null
Long domainId = cmd.getDomainId(); Long domainId = cmd.getDomainId();
String type = cmd.getNetworkType();
Boolean isBasic = false;
if (!(type.equalsIgnoreCase(DataCenterNetworkType.Basic.toString())) && !(type.equalsIgnoreCase(DataCenterNetworkType.Advanced.toString()))) {
throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported");
} else if (type.endsWith(DataCenterNetworkType.Basic.toString())) {
isBasic = true;
}
DataCenterNetworkType zoneType = isBasic ? DataCenterNetworkType.Basic : DataCenterNetworkType.Advanced;
DomainVO domainVO = null; DomainVO domainVO = null;
if (userId == null) { if (userId == null) {
@ -1059,7 +1068,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if(domainId != null){ if(domainId != null){
domainVO = _domainDao.findById(domainId); domainVO = _domainDao.findById(domainId);
} }
return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domainVO != null ? domainVO.getName() : null, domainId);
//Verify zone type
if (zoneType == DataCenterNetworkType.Basic && vnetRange != null) {
vnetRange = null;
}
return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType);
} }
@Override @Override
@ -1378,11 +1392,28 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@Override @Override
public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException { public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException {
Long zoneId = cmd.getZoneId();
Long podId = cmd.getPodId();
String startIP = cmd.getStartIp();
String endIP = cmd.getEndIp();
String vlanGateway = cmd.getGateway();
String vlanNetmask = cmd.getNetmask();
Long userId = UserContext.current().getUserId(); Long userId = UserContext.current().getUserId();
if (userId == null) { if (userId == null) {
userId = Long.valueOf(User.UID_SYSTEM); userId = Long.valueOf(User.UID_SYSTEM);
} }
// Check that the pod ID is valid
if (podId != null && ((_podDao.findById(podId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid pod.");
}
if (podId != null && _podDao.findById(podId).getDataCenterId() != zoneId) {
throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId);
}
// If forVirtualNetworks isn't specified, default it to true // If forVirtualNetworks isn't specified, default it to true
Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); Boolean forVirtualNetwork = cmd.isForVirtualNetwork();
if (forVirtualNetwork == null) { if (forVirtualNetwork == null) {
@ -1395,6 +1426,23 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
vlanId = Vlan.UNTAGGED; vlanId = Vlan.UNTAGGED;
} }
DataCenterVO zone;
if (zoneId == null || ((zone = _zoneDao.findById(zoneId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid zone.");
}
//Allow adding untagged direct vlan only for Basic zone
if (zone.getNetworkType() == DataCenterNetworkType.Advanced && vlanId.equals(Vlan.UNTAGGED) && !forVirtualNetwork) {
throw new InvalidParameterValueException("Direct untagged network is not supported for the zone " + zone.getId() + " of type " + zone.getNetworkType());
} else if (zone.getNetworkType() == DataCenterNetworkType.Basic && !(vlanId.equals(Vlan.UNTAGGED) && !forVirtualNetwork)) {
throw new InvalidParameterValueException("Only direct untagged network is supported in the zone " + zone.getId() + " of type " + zone.getNetworkType());
}
//don't allow to create a virtual vlan when zone's vnet is NULL
if (zone.getVnet() == null && forVirtualNetwork) {
throw new InvalidParameterValueException("Can't add virtual network to the zone id=" + zone.getId() + " as zone doesn't have guest vlan configured");
}
// If an account name and domain ID are specified, look up the account // If an account name and domain ID are specified, look up the account
String accountName = cmd.getAccountName(); String accountName = cmd.getAccountName();
Long domainId = cmd.getDomainId(); Long domainId = cmd.getDomainId();
@ -1407,12 +1455,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} }
VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached; VlanType vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
Long zoneId = cmd.getZoneId();
Long podId = cmd.getPodId();
String startIP = cmd.getStartIp();
String endIP = cmd.getEndIp();
String vlanGateway = cmd.getGateway();
String vlanNetmask = cmd.getNetmask();
//check for hypervisor type to be xenserver //check for hypervisor type to be xenserver
String hypervisorType = _configDao.getValue("hypervisor.type"); String hypervisorType = _configDao.getValue("hypervisor.type");
@ -1439,10 +1482,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
+",whilst you are trying to associate it with vlan type "+vlanType.toString()); +",whilst you are trying to associate it with vlan type "+vlanType.toString());
} }
DataCenterVO zone;
if (zoneId == null || ((zone = _zoneDao.findById(zoneId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid zone.");
}
// //check if the account's domain is a child of the zone's domain, for adding vlan ip ranges // //check if the account's domain is a child of the zone's domain, for adding vlan ip ranges
// if(domainId != null && !_domainDao.isChildDomain(zone.getDomainId(), domainId)){ // if(domainId != null && !_domainDao.isChildDomain(zone.getDomainId(), domainId)){
@ -1491,10 +1531,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged."); throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged.");
} }
// Check that the pod ID is valid
if (podId != null && ((_podDao.findById(podId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid pod.");
}
// Make sure there aren't any account VLANs in this zone // Make sure there aren't any account VLANs in this zone
List<AccountVlanMapVO> accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved(); List<AccountVlanMapVO> accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved();

View File

@ -45,6 +45,7 @@ import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO; import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO; import com.cloud.dc.HostPodVO;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.HostPodDao;
import com.cloud.domain.DomainVO; import com.cloud.domain.DomainVO;
@ -194,7 +195,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
if (dns == null) { if (dns == null) {
dns = "4.2.2.2"; dns = "4.2.2.2";
} }
DataCenterVO zone = createZone(User.UID_SYSTEM, "Default", dns, null, dns, null, "1000-2000","10.1.1.0/24", null, null); DataCenterVO zone = createZone(User.UID_SYSTEM, "Default", dns, null, dns, null, null,"10.1.1.0/24", null, null, DataCenterNetworkType.Basic);
// Create a default pod // Create a default pod
String networkType = _configDao.getValue("network.type"); String networkType = _configDao.getValue("network.type");
@ -531,7 +532,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
} }
} }
private DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId) throws InvalidParameterValueException, InternalErrorException { private DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, DataCenterNetworkType zoneType) throws InvalidParameterValueException, InternalErrorException {
int vnetStart, vnetEnd; int vnetStart, vnetEnd;
if (vnetRange != null) { if (vnetRange != null) {
String[] tokens = vnetRange.split("-"); String[] tokens = vnetRange.split("-");
@ -569,7 +570,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
throw new InvalidParameterValueException("Please specify a valid domain id"); throw new InvalidParameterValueException("Please specify a valid domain id");
} }
// Create the new zone in the database // Create the new zone in the database
DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId); DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId, zoneType);
zone = _zoneDao.persist(zone); zone = _zoneDao.persist(zone);
// Add vnet entries for the new zone // Add vnet entries for the new zone

View File

@ -1408,7 +1408,6 @@ public class ManagementServerImpl implements ManagementServer {
return singleZone; return singleZone;
} }
} }
return dcs; return dcs;
} }

View File

@ -370,6 +370,7 @@ CREATE TABLE `cloud`.`data_center` (
`guest_network_cidr` varchar(18), `guest_network_cidr` varchar(18),
`domain` varchar(100) COMMENT 'Network domain name of the Vms of the zone', `domain` varchar(100) COMMENT 'Network domain name of the Vms of the zone',
`domain_id` bigint unsigned COMMENT 'domain id for the parent domain to this zone (null signifies public zone)', `domain_id` bigint unsigned COMMENT 'domain id for the parent domain to this zone (null signifies public zone)',
`networktype` varchar(255) NOT NULL COMMENT 'Network type of the zone',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;