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 enum DataCenterNetworkType {
Basic,
Advanced
}
long getId();
String getDns1();
String getDns2();

View File

@ -1,44 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<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/gson-1.3.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/commons-dbcp-1.2.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-pool-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.5.0-1.jar" sourcepath="/thirdparty/xen/XenServerJava"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/vmware-apputils.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-credstore.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-activation.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-axis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-core.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxrpc.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-mailapi.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-saxpath.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-smtp.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-wbem.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<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/log4j-1.2.15.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-pool-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/ehcache-1.5.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.5.0-1.jar" sourcepath="/thirdparty/xen/XenServerJava"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/vmware-apputils.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-credstore.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-activation.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-axis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-core.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxen.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jaxrpc.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-jdom.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-mailapi.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-saxpath.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-smtp.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-wbem.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.license"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xalan.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xerces.readme"/>
<classpathentry kind="lib" path="/thirdparty/vmware-lib-xml-apis.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim.jar"/>
<classpathentry kind="lib" path="/thirdparty/vmware-vim25.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -20,6 +20,8 @@ package com.cloud.dc;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@ -67,17 +69,21 @@ public class DataCenterVO implements DataCenter {
@Column(name="domain")
private String domain = null;
@Column(name="networktype")
@Enumerated(EnumType.STRING)
DataCenterNetworkType networkType;
@Column(name="mac_address", updatable = false, nullable=false)
@TableGenerator(name="mac_address_sq", table="data_center", pkColumnName="id", valueColumnName="mac_address", allocationSize=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) {
this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain, 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, zoneType);
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.description = description;
this.dns1 = dns1;
@ -88,6 +94,7 @@ public class DataCenterVO implements DataCenter {
this.guestNetworkCidr = guestCidr;
this.domain = domain;
this.domainId = domainId;
this.networkType = zoneType;
}
public Long getDomainId() {
@ -183,5 +190,13 @@ public class DataCenterVO implements DataCenter {
public void setDomain(String domain) {
this.domain = domain;
}
public void setNetworkType(DataCenterNetworkType zoneNetworkType) {
this.networkType = zoneNetworkType;
}
public DataCenterNetworkType getNetworkType() {
return networkType;
}
}

View File

@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<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/gson-1.3.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/email.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.5.0-1.jar"/>
<classpathentry kind="lib" path="/thirdparty/ws-commons-util-1.0.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/servlet-api.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/xstream-1.3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<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/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/httpcore-4.0.jar"/>
<classpathentry kind="lib" path="/thirdparty/email.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit-4.8.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/xenserver-5.5.0-1.jar"/>
<classpathentry kind="lib" path="/thirdparty/ws-commons-util-1.0.2.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-client-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/xmlrpc-common-3.1.3.jar"/>
<classpathentry kind="lib" path="/thirdparty/commons-codec-1.4.jar"/>
<classpathentry kind="lib" path="/thirdparty/servlet-api.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/trilead-ssh2-build213.jar"/>
<classpathentry kind="lib" path="/thirdparty/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -160,4 +160,5 @@ public class ApiConstants {
public static final String VNET = "vnet";
public static final String VOLUME_ID = "volumeid";
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.VMInstanceVO;
import com.cloud.vm.VmStats;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
public class ApiResponseHelper {
@ -810,6 +809,7 @@ public class ApiResponseHelper {
zoneResponse.setDomain(dataCenter.getDomain());
zoneResponse.setDomainId(dataCenter.getDomainId());
zoneResponse.setType(dataCenter.getNetworkType().toString());
zoneResponse.setObjectName("zone");
return zoneResponse;
}

View File

@ -31,52 +31,8 @@ public class ResponseObjectTypeAdapter implements JsonSerializer<ResponseObject>
obj.addProperty("errortext", ((ExceptionResponse)responseObj).getErrorText());
return obj;
} else {
// Get the declared fields from the response obj, create a new JSON Object, add props to it.
// 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.
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;
obj.add(responseObj.getObjectName(), ApiGsonHelper.getBuilder().create().toJsonTree(responseObj));
return obj;
}
}

View File

@ -57,9 +57,8 @@ public class CreateZoneCmd extends BaseCmd {
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Zone")
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 VNET for the Zone")
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VLAN for the Zone")
private String vlan;
@Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone")
@ -67,6 +66,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")
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 ///////////////////////
@ -108,6 +110,10 @@ public class CreateZoneCmd extends BaseCmd {
return domainId;
}
public String getNetworkType(){
return networkType;
}
/////////////////////////////////////////////////////
/////////////// 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")
private String zoneName;
@Parameter(name=ApiConstants.VNET, type=CommandType.STRING, description="the VNET for the Zone")
private String vnet;
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VLAN for the Zone")
private String vlan;
// @Parameter(name=ApiConstants.DOMAIN, type=CommandType.STRING, description="Domain name for the Vms in the zone")
// private String domain;
@ -102,8 +102,8 @@ public class UpdateZoneCmd extends BaseCmd {
return zoneName;
}
public String getVnet() {
return vnet;
public String getVlan() {
return vlan;
}
// 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")
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() {
return id;
}
@ -166,5 +169,13 @@ public class ZoneResponse extends BaseResponse {
public void setDomainId(Long 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 com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.exception.ConcurrentOperationException;
@ -97,11 +98,12 @@ public interface ConfigurationManager extends Manager {
* @param internalDns2
* @param vnetRange
* @param guestCidr
* @param zoneType
* @return
* @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.

View File

@ -52,6 +52,7 @@ import com.cloud.configuration.ResourceCount.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.AccountVlanMapVO;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.DataCenterIpAddressVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
@ -858,7 +859,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String dns2 = cmd.getDns2();
String internalDns1 = cmd.getInternalDns1();
String internalDns2 = cmd.getInternalDns2();
String vnetRange = cmd.getVnet();
String vnetRange = cmd.getVlan();
String guestCidr = cmd.getGuestCidrAddress();
// String domain = cmd.getDomain();
Long userId = UserContext.current().getUserId();
@ -992,12 +993,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
@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) {
int vnetStart = -1;
int vnetEnd = -1;
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 = 0;
int vnetEnd = 0;
if (vnetRange != null) {
String[] tokens = vnetRange.split("-");
try {
vnetStart = Integer.parseInt(tokens[0]);
if (tokens.length == 1) {
@ -1008,14 +1008,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} catch (NumberFormatException e) {
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
//hence the method below is generic to check for common params
if ((guestCidr != null) && !NetUtils.isValidCIDR(guestCidr)) {
@ -1025,15 +1019,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true, domainId);
// 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);
// Add vnet entries for the new zone
if (vnetStart != -1 && vnetEnd != -1) {
// Add vnet entries for the new zone if zone type is Advanced
if (vnetRange != null) {
_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;
}
@ -1050,6 +1048,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String guestCidr = cmd.getGuestCidrAddress();
String domain = cmd.getDomain();//we are not passing domain right now, always null
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;
if (userId == null) {
@ -1059,7 +1068,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if(domainId != null){
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
@ -1378,10 +1392,27 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@Override
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();
if (userId == null) {
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
Boolean forVirtualNetwork = cmd.isForVirtualNetwork();
@ -1394,6 +1425,23 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (vlanId == null) {
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
String accountName = cmd.getAccountName();
@ -1407,12 +1455,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
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
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());
}
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
// if(domainId != null && !_domainDao.isChildDomain(zone.getDomainId(), domainId)){
@ -1491,11 +1531,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
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
List<AccountVlanMapVO> accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved();
for (AccountVlanMapVO accountVlanMap : accountVlanMaps) {

View File

@ -45,6 +45,7 @@ import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.DataCenter.DataCenterNetworkType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.domain.DomainVO;
@ -194,7 +195,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
if (dns == null) {
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
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;
if (vnetRange != null) {
String[] tokens = vnetRange.split("-");
@ -569,7 +570,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
throw new InvalidParameterValueException("Please specify a valid domain id");
}
// 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);
// Add vnet entries for the new zone

View File

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

View File

@ -370,6 +370,7 @@ CREATE TABLE `cloud`.`data_center` (
`guest_network_cidr` varchar(18),
`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)',
`networktype` varchar(255) NOT NULL COMMENT 'Network type of the zone',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;