Bug 8208 - bare metal provisioning

Add useExternalDhcp option to createPodCmd
This commit is contained in:
Frank 2011-03-14 16:42:59 -07:00
parent bf6a6f0d57
commit ffb900fc86
9 changed files with 37 additions and 10 deletions

View File

@ -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";
}

View File

@ -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;
}
/////////////////////////////////////////////////////

View File

@ -28,4 +28,6 @@ public interface Pod extends Grouping {
String getDescription();
String getName();
boolean getExternalDhcp();
}

View File

@ -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);
/**

View File

@ -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();

View File

@ -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) {

View File

@ -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) {

View File

@ -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();

View File

@ -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`)