mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 3386: first part of the checkin, wherein we have an optional param domainId for create and modify zones. If this domain exists in the system, then the zone is tagged with this domain id, so that subsequent calls are checked for sanity against this domain.
This commit is contained in:
parent
ee818c23e1
commit
2b9ab00cc2
@ -58,23 +58,26 @@ public class DataCenterVO implements DataCenter {
|
||||
|
||||
@Column(name="vnet")
|
||||
private String vnet = null;
|
||||
|
||||
@Column(name="guest_network_cidr")
|
||||
|
||||
@Column(name="guest_network_cidr")
|
||||
private String guestNetworkCidr = null;
|
||||
|
||||
@Column(name="domain_id")
|
||||
private Long domainId = null;
|
||||
|
||||
@Column(name="domain")
|
||||
private String domain = null;
|
||||
|
||||
|
||||
@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) {
|
||||
this(name, description, dns1, dns2, dns3, dns4, vnet, guestCidr, domain);
|
||||
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);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain) {
|
||||
public DataCenterVO(String name, String description, String dns1, String dns2, String dns3, String dns4, String vnet, String guestCidr, String domain, Long domainId) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.dns1 = dns1;
|
||||
@ -84,7 +87,16 @@ public class DataCenterVO implements DataCenter {
|
||||
this.vnet = vnet;
|
||||
this.guestNetworkCidr = guestCidr;
|
||||
this.domain = domain;
|
||||
}
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
|
||||
@ -21,6 +21,7 @@ package com.cloud.api.commands;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
@ -36,7 +37,6 @@ public class CreateZoneCmd extends BaseCmd {
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name="dns1", type=CommandType.STRING, required=true, description="the first DNS for the Zone")
|
||||
private String dns1;
|
||||
|
||||
@ -62,7 +62,8 @@ public class CreateZoneCmd extends BaseCmd {
|
||||
@Parameter(name="domain", type=CommandType.STRING, description="Domain name for the Vms in the zone")
|
||||
private String domain;
|
||||
|
||||
|
||||
@Parameter(name="domainid", type=CommandType.LONG, description="the ID of the containing domain, null for public zones")
|
||||
private Long domainId;
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -99,6 +100,10 @@ public class CreateZoneCmd extends BaseCmd {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public Long getDomainId(){
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -123,6 +128,7 @@ public class CreateZoneCmd extends BaseCmd {
|
||||
response.setGuestCidrAddress(zone.getGuestNetworkCidr());
|
||||
response.setDomain(zone.getDomain());
|
||||
response.setResponseName(getName());
|
||||
response.setDomainId(zone.getDomainId());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package com.cloud.api.commands;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
@ -65,6 +66,8 @@ public class UpdateZoneCmd extends BaseCmd {
|
||||
@Parameter(name="domain", type=CommandType.STRING, description="Domain name for the Vms in the zone")
|
||||
private String domain;
|
||||
|
||||
@Parameter(name="domainid", type=CommandType.LONG, description="the ID of the containing domain, null for public zones")
|
||||
private Long domainId;
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -105,6 +108,13 @@ public class UpdateZoneCmd extends BaseCmd {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -59,6 +59,9 @@ public class ZoneResponse extends BaseResponse {
|
||||
@SerializedName("domain") @Param(description="Domain name for the Vms in the zone")
|
||||
private String domain;
|
||||
|
||||
@SerializedName("domainid") @Param(description="the ID of the containing domain, null for public zones")
|
||||
private Long domainId;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -154,4 +157,13 @@ public class ZoneResponse extends BaseResponse {
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public Long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public void setDomainId(Long domainId) {
|
||||
this.domainId = domainId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ public interface ConfigurationManager extends Manager {
|
||||
* @throws InvalidParameterValueException
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain) throws InvalidParameterValueException, InternalErrorException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Edits a zone in the database. Will not allow you to edit DNS values if there are VMs in the specified zone.
|
||||
|
||||
@ -64,6 +64,7 @@ import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.dc.dao.PodVlanMapDao;
|
||||
import com.cloud.dc.dao.VlanDao;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.event.EventUtils;
|
||||
import com.cloud.event.EventVO;
|
||||
@ -116,6 +117,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
@Inject PodVlanMapDao _podVlanMapDao;
|
||||
@Inject DataCenterDao _zoneDao;
|
||||
@Inject DomainRouterDao _domrDao;
|
||||
@Inject DomainDao _domainDao;
|
||||
@Inject ServiceOfferingDao _serviceOfferingDao;
|
||||
@Inject DiskOfferingDao _diskOfferingDao;
|
||||
@Inject VlanDao _vlanDao;
|
||||
@ -722,7 +724,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
|
||||
}
|
||||
|
||||
private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates) throws InvalidParameterValueException {
|
||||
private void checkZoneParameters(String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, boolean checkForDuplicates, Long domainId) throws InvalidParameterValueException {
|
||||
if (checkForDuplicates) {
|
||||
// Check if a zone with the specified name already exists
|
||||
if (validZone(zoneName)) {
|
||||
@ -730,6 +732,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
//check if valid domain
|
||||
if(domainId != null){
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
|
||||
if(domain == null)
|
||||
throw new InvalidParameterValueException("Please specify a valid domain id");
|
||||
}
|
||||
|
||||
// Check IP validity for DNS addresses
|
||||
|
||||
if (dns1 != null && !NetUtils.isValidIp(dns1)) {
|
||||
@ -813,7 +823,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
String guestCidr = cmd.getGuestCidrAddress();
|
||||
String domain = cmd.getDomain();
|
||||
Long userId = UserContext.current().getUserId();
|
||||
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
||||
if (userId == null) {
|
||||
userId = Long.valueOf(User.UID_SYSTEM);
|
||||
}
|
||||
@ -867,7 +878,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
domain = zone.getDomain();
|
||||
|
||||
boolean checkForDuplicates = !zoneName.equals(oldZoneName);
|
||||
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates);
|
||||
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, checkForDuplicates, domainId);
|
||||
|
||||
zone.setName(zoneName);
|
||||
zone.setDns1(dns1);
|
||||
@ -942,7 +953,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
public DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain) throws InvalidParameterValueException, InternalErrorException {
|
||||
public 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 {
|
||||
int vnetStart, vnetEnd;
|
||||
if (vnetRange != null) {
|
||||
String[] tokens = vnetRange.split("-");
|
||||
@ -973,10 +984,10 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
checkZoneParameters(zoneName, dns1, dns2, internalDns1, internalDns2, true);
|
||||
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);
|
||||
DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId);
|
||||
zone = _zoneDao.persist(zone);
|
||||
|
||||
// Add vnet entries for the new zone
|
||||
@ -999,12 +1010,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager {
|
||||
String vnetRange = cmd.getVlan();
|
||||
String guestCidr = cmd.getGuestCidrAddress();
|
||||
String domain = cmd.getDomain();
|
||||
|
||||
Long domainId = cmd.getDomainId();
|
||||
|
||||
if (userId == null) {
|
||||
userId = User.UID_SYSTEM;
|
||||
}
|
||||
|
||||
return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain);
|
||||
return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -48,6 +48,7 @@ import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
@ -75,6 +76,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
private final HostPodDao _podDao;
|
||||
private final DiskOfferingDao _diskOfferingDao;
|
||||
private final ServiceOfferingDao _serviceOfferingDao;
|
||||
private final DomainDao _domainDao;
|
||||
|
||||
public ConfigurationServerImpl() {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(Name);
|
||||
@ -84,6 +86,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
_podDao = locator.getDao(HostPodDao.class);
|
||||
_diskOfferingDao = locator.getDao(DiskOfferingDao.class);
|
||||
_serviceOfferingDao = locator.getDao(ServiceOfferingDao.class);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
}
|
||||
|
||||
public void persistDefaultValues() throws InvalidParameterValueException, InternalErrorException {
|
||||
@ -190,7 +193,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);
|
||||
DataCenterVO zone = createZone(User.UID_SYSTEM, "Default", dns, null, dns, null, "1000-2000","10.1.1.0/24", null, null);
|
||||
|
||||
// Create a default pod
|
||||
String networkType = _configDao.getValue("network.type");
|
||||
@ -527,7 +530,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) 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) throws InvalidParameterValueException, InternalErrorException {
|
||||
int vnetStart, vnetEnd;
|
||||
if (vnetRange != null) {
|
||||
String[] tokens = vnetRange.split("-");
|
||||
@ -558,8 +561,14 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
||||
throw new InvalidParameterValueException("Please enter a valid guest cidr");
|
||||
}
|
||||
|
||||
if(domainId!=null){
|
||||
DomainVO domainVo = _domainDao.findById(domainId);
|
||||
|
||||
if(domainVo == null)
|
||||
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);
|
||||
DataCenterVO zone = new DataCenterVO(zoneName, null, dns1, dns2, internalDns1, internalDns2, vnetRange, guestCidr, domain, domainId);
|
||||
zone = _zoneDao.persist(zone);
|
||||
|
||||
// Add vnet entries for the new zone
|
||||
|
||||
@ -351,6 +351,7 @@ CREATE TABLE `cloud`.`data_center` (
|
||||
`mac_address` bigint unsigned NOT NULL DEFAULT '1' COMMENT 'Next available mac address for the ethernet card interacting with public internet',
|
||||
`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)',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user