diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 7dfe92db9cf..ba701394dc1 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -212,5 +212,6 @@ public class ApiConstants { public static final String PRIVATE_MAC_ADDRESS = "privatemacaddress"; public static final String PRIVATE_NETMASK = "privatenetmask"; public static final String PRIVATE_NETWORK_ID = "privatenetworkid"; + public static final String USE_EXTERNAL_DHCP = "useexternaldhcp"; } diff --git a/api/src/com/cloud/api/commands/CreatePodCmd.java b/api/src/com/cloud/api/commands/CreatePodCmd.java index 6fb8055eff0..ec3716cdd35 100644 --- a/api/src/com/cloud/api/commands/CreatePodCmd.java +++ b/api/src/com/cloud/api/commands/CreatePodCmd.java @@ -56,6 +56,9 @@ public class CreatePodCmd extends BaseCmd { @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID in which the Pod will be created ") private Long zoneId; + + @Parameter(name=ApiConstants.USE_EXTERNAL_DHCP, type=CommandType.BOOLEAN, description="whether use external dhcp server, true/false, default is false ") + private Boolean useExternalDhcp; ///////////////////////////////////////////////////// @@ -85,6 +88,10 @@ public class CreatePodCmd extends BaseCmd { public Long getZoneId() { return zoneId; } + + public Boolean getUseExternalDhcp() { + return useExternalDhcp; + } ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/dc/Pod.java b/api/src/com/cloud/dc/Pod.java index cff4edad93e..7bc5dacb076 100644 --- a/api/src/com/cloud/dc/Pod.java +++ b/api/src/com/cloud/dc/Pod.java @@ -28,4 +28,6 @@ public interface Pod extends Grouping { String getDescription(); String getName(); + + boolean getExternalDhcp(); } diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 194526cfd6d..5e53c3a9e81 100644 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -93,9 +93,10 @@ public interface ConfigurationManager extends ConfigurationService, Manager { * @param cidr * @param startIp * @param endIp + * @param useExternalDhcp * @return Pod */ - HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp); + HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, Boolean useExternalDhcp); /** diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index a8bbafa6b2f..b2ae905059f 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -684,12 +684,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Long zoneId = cmd.getZoneId(); String cidr = NetUtils.ipAndNetMaskToCidr(gateway, netmask); Long userId = UserContext.current().getCallerUserId(); + Boolean useExternalDhcp = cmd.getUseExternalDhcp(); + useExternalDhcp = (useExternalDhcp == null ? false : useExternalDhcp); - return createPod(userId.longValue(), name, zoneId, gateway, cidr, startIp, endIp); + return createPod(userId.longValue(), name, zoneId, gateway, cidr, startIp, endIp, useExternalDhcp); } @Override @DB - public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp) { + public HostPodVO createPod(long userId, String podName, long zoneId, String gateway, String cidr, String startIp, String endIp, Boolean useExternalDhcp) { // Check if the zone is valid if (!validZone(zoneId)) { @@ -717,7 +719,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura throw new InvalidParameterValueException("Start ip is required parameter"); } - HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange); + HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange, useExternalDhcp); Transaction txn = Transaction.currentTxn(); txn.start(); diff --git a/server/src/com/cloud/dc/HostPodVO.java b/server/src/com/cloud/dc/HostPodVO.java index b0ca1f4dd30..3066441e74f 100644 --- a/server/src/com/cloud/dc/HostPodVO.java +++ b/server/src/com/cloud/dc/HostPodVO.java @@ -50,15 +50,19 @@ public class HostPodVO implements Pod { private int cidrSize; @Column(name = "description") - private String description; + private String description; + + @Column(name = "external_dhcp") + private Boolean externalDhcp; - public HostPodVO(String name, long dcId, String gateway, String cidrAddress, int cidrSize, String description) { + public HostPodVO(String name, long dcId, String gateway, String cidrAddress, int cidrSize, String description, Boolean externalDhcp) { this.name = name; this.dataCenterId = dcId; this.gateway = gateway; this.cidrAddress = cidrAddress; this.cidrSize = cidrSize; - this.description = description; + this.description = description; + this.externalDhcp = externalDhcp; } /* @@ -133,6 +137,10 @@ public class HostPodVO implements Pod { return NumbersUtil.hash(id); } + public boolean getExternalDhcp() { + return externalDhcp; + } + @Override public boolean equals(Object obj) { if (obj instanceof HostPodVO) { diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index 8d2c23ad436..18c7c41bcf8 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -28,6 +28,8 @@ import org.apache.log4j.Logger; import com.cloud.configuration.ConfigurationManager; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.dao.HostPodDao; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -49,6 +51,7 @@ import com.cloud.offering.NetworkOffering; import com.cloud.uservm.UserVm; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; import com.cloud.vm.ReservationContext; @@ -73,14 +76,16 @@ public class DhcpElement extends AdapterBase implements NetworkElement, Password @Inject UserVmDao _userVmDao; @Inject DomainRouterDao _routerDao; @Inject ConfigurationManager _configMgr; - + @Inject HostPodDao _podDao; + private boolean canHandle(GuestIpType ipType, DeployDestination dest, TrafficType trafficType) { DataCenter dc = dest.getDataCenter(); String provider = dc.getGatewayProvider(); if (provider != null && provider.equalsIgnoreCase(Provider.JuniperSRX.getName()) && ipType == GuestIpType.Virtual) { return true; - } else if (dc.getDhcpProvider().equalsIgnoreCase(Provider.ExternalDhcpServer.getName())){ + } else if (dest.getPod().getExternalDhcp()){ + //This pod is using external DHCP server return false; } else { if (dc.getNetworkType() == NetworkType.Basic) { diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index d98bc084b69..abcad1be28d 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -639,7 +639,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { ipRange = ""; } - HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange); + HostPodVO pod = new HostPodVO(podName, zoneId, gateway, cidrAddress, cidrSize, ipRange, false); Transaction txn = Transaction.currentTxn(); try { txn.start(); diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 815b8ba9db8..333bd57b0c1 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -520,6 +520,7 @@ CREATE TABLE `cloud`.`host_pod_ref` ( `cidr_size` bigint unsigned NOT NULL COMMENT 'CIDR size for the pod', `description` varchar(255) COMMENT 'store private ip range in startIP-endIP format', `enabled` tinyint NOT NULL DEFAULT 1 COMMENT 'Is this Pod enabled for activity', + `external_dhcp` tinyint NOT NULL DEFAULT 0 COMMENT 'Is this Pod using external DHCP', PRIMARY KEY (`id`), UNIQUE KEY (`name`, `data_center_id`), INDEX `i_host_pod_ref__data_center_id`(`data_center_id`)