Bug 8208 - bare metal provisioning

Add bare metal planner
This commit is contained in:
Frank 2011-03-01 17:47:37 -08:00
parent ec7a6e6863
commit 7fa053370e
13 changed files with 136 additions and 11 deletions

View File

@ -194,6 +194,7 @@ public class ApiConstants {
public static final String HOST_CPU_NUM = "hostcpunum";
public static final String HOST_MEM_CAPACITY = "hostmemcapacity";
public static final String HOST_MAC = "hostmac";
public static final String HOST_TAG = "hosttag";
public static final String PXE_SERVER_TYPE = "pxeservertype";
public static final String LINMIN_USERNAME = "linminusername";
public static final String LINMIN_PASSWORD = "linminpassword";

View File

@ -66,18 +66,21 @@ public class AddHostCmd extends BaseCmd {
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="hypervisor type of the host")
private String hypervisor;
@Parameter(name=ApiConstants.HOST_CPU_CAPACITY, type=CommandType.LONG, description="HZ per CPU of host")
@Parameter(name=ApiConstants.HOST_CPU_CAPACITY, type=CommandType.LONG, description="Only for hypervisor is BareMetal, HZ per CPU of host")
private Long cpuCapacity;
@Parameter(name=ApiConstants.HOST_CPU_NUM, type=CommandType.LONG, description="number of CPU on host")
@Parameter(name=ApiConstants.HOST_CPU_NUM, type=CommandType.LONG, description="Only for hypervisor is BareMetal, number of CPU on host")
private Long cpuNum;
@Parameter(name=ApiConstants.HOST_MEM_CAPACITY, type=CommandType.LONG, description="memory capacity of host")
@Parameter(name=ApiConstants.HOST_MEM_CAPACITY, type=CommandType.LONG, description="Only for hypervisor is BareMetal, memory capacity of host(in MB)")
private Long memCapacity;
@Parameter(name=ApiConstants.HOST_MAC, type=CommandType.STRING, required=true, description="Mac of PXE nic")
@Parameter(name=ApiConstants.HOST_MAC, type=CommandType.STRING, description="Only for hypervisor is BareMetal, Mac of PXE nic")
private String mac;
@Parameter(name=ApiConstants.HOST_TAG, type=CommandType.STRING, description="Only for hypervisor is BareMetal, Tag of host")
private String hostTag;
@ -133,6 +136,10 @@ public class AddHostCmd extends BaseCmd {
return mac;
}
public String getHostTag() {
return hostTag;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -44,6 +44,17 @@ public interface DeploymentPlanner extends Adapter {
*/
boolean check(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude);
/**
* canHandle is called before plan to determine if the plan can do the allocation. Planers should be exclusive so planner writer must
* make sure only one planer->canHandle return true in the planner list
*
* @param vm virtual machine.
* @param plan deployment plan that tells you where it's being deployed to.
* @param avoid avoid these data centers, pods, clusters, or hosts.
* @return true if it's okay to allocate; false or not
*/
boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid);
public static class ExcludeList {
Set<Long> _dcIds;
Set<Long> _podIds;

View File

@ -73,5 +73,4 @@ public interface ServiceOffering {
boolean getUseLocalStorage();
Long getDomainId();
}

View File

@ -78,6 +78,7 @@
</adapters>
<adapters key="com.cloud.deploy.DeploymentPlanner">
<adapter name="First Fit" class="com.cloud.deploy.FirstFitPlanner"/>
<adapter name="BareMetal Fit" class="com.cloud.deploy.BareMetalPlanner"/>
</adapters>
<adapters key="com.cloud.network.element.NetworkElement">
<adapter name="DomainRouter" class="com.cloud.network.element.VirtualRouterElement"/>

View File

@ -754,6 +754,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
Long cpuCapacity = cmd.getCpuCapacity();
Long cpuNum = cmd.getCpuNum();
String mac = cmd.getMac();
String hostTag = cmd.getHostTag();
Map<String, String>bareMetalParams = new HashMap<String, String>();
// this is for standalone option
@ -779,6 +780,9 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory,
bareMetalParams.put("cpuCapacity", cpuCapacity.toString());
bareMetalParams.put("memCapacity", memCapacity.toString());
bareMetalParams.put("mac", mac);
if (hostTag != null) {
bareMetalParams.put("hostTag", hostTag);
}
}

View File

@ -64,15 +64,15 @@ public class LinMinPxeServerManagerImpl extends PxeServerManagerImpl implements
apiPassword = cmd.getLinMinPassword();
apid = cmd.getLinMinApid();
if (apiUsername == null) {
throw new InvalidParameterValueException("No LinMin username specified, without it I can user LinMin API");
throw new InvalidParameterValueException("No LinMin username specified, without it I can not use LinMin API");
}
if (apiPassword == null) {
throw new InvalidParameterValueException("No LinMin password specified, without it I can user LinMin API");
throw new InvalidParameterValueException("No LinMin password specified, without it I can not use LinMin API");
}
if (apid == null) {
throw new InvalidParameterValueException("No LinMin apid specified, without it I can user LinMin API");
throw new InvalidParameterValueException("No LinMin apid specified, without it I can not use LinMin API");
}
String ipAddress = uri.getHost();

View File

@ -0,0 +1,80 @@
package com.cloud.deploy;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
@Local(value=DeploymentPlanner.class)
public class BareMetalPlanner extends FirstFitPlanner implements DeploymentPlanner {
private static final Logger s_logger = Logger.getLogger(BareMetalPlanner.class);
@Override
public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
VirtualMachine vm = vmProfile.getVirtualMachine();
ServiceOffering offering = vmProfile.getServiceOffering();
String hostTag = null;
if (offering.getTags() != null) {
String[] tags = offering.getTags().split(",");
if (tags.length > 0) {
hostTag = tags[0];
}
}
if (hostTag != null) {
List<HostVO> hosts = _hostDao.listBy(Host.Type.Routing, vm.getDataCenterId());
HostVO target = null;
for (HostVO h : hosts) {
_hostDao.loadDetails(h);
if (h.getDetail("hostTag") != null && h.getDetail("hostTag").equalsIgnoreCase(hostTag)) {
target = h;
break;
}
}
if (target == null) {
s_logger.warn("Cannot find host with tag " + hostTag);
return null;
}
int cpu = target.getCpus();
int speed = target.getSpeed().intValue();
Long ramSize = target.getTotalMemory() / (1024L*1024L);
ServiceOfferingVO newOffering = new ServiceOfferingVO(offering.getName(), cpu, ramSize.intValue(), speed, offering.getRateMbps(),
offering.getMulticastRateMbps(), false, offering.getDisplayText(), offering.getUseLocalStorage(), false, offering.getTags(), false);
((VirtualMachineProfileImpl)vmProfile).setServiceOffering(newOffering);
}
DeployDestination dest = super.plan(vmProfile, plan, avoid);
if (hostTag == null && dest != null) {
Host h = dest.getHost();
if (h.getCpus() != offering.getCpu() || h.getTotalMemory() != offering.getRamSize() || h.getSpeed() != offering.getSpeed()) {
throw new CloudRuntimeException(String.format("Bare Metal only allows one VM one host, " +
"the offering capcacity doesn't equal to host capacity(offering: cpu number:%$1s, cpu speed:%$2s," +
"ram size:%3$s; host: cpu number:%$4s, cpu speed:%$5s, ram size:%$6s)", offering.getCpu(), offering.getSpeed(),
offering.getRamSize(), h.getCpus(), h.getSpeed(), h.getTotalMemory()));
}
}
return dest;
}
@Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
return vm.getHypervisorType() == HypervisorType.BareMetal;
}
}

View File

@ -20,6 +20,7 @@ import com.cloud.dc.Pod;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
@ -27,6 +28,7 @@ import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.DetailsDao;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.storage.GuestOSCategoryVO;
@ -43,7 +45,7 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value=DeploymentPlanner.class)
public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
private static final Logger s_logger = Logger.getLogger(FirstFitPlanner.class);
@Inject private HostDao _hostDao;
@Inject protected HostDao _hostDao;
@Inject private CapacityDao _capacityDao;
@Inject private DataCenterDao _dcDao;
@Inject private HostPodDao _podDao;
@ -286,4 +288,9 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentPlanner {
GuestOSCategoryVO guestOSCategory = _guestOSCategoryDao.findById(guestOSCategoryId);
return guestOSCategory.getName();
}
@Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
return vm.getHypervisorType() != HypervisorType.BareMetal;
}
}

View File

@ -26,12 +26,14 @@ import com.cloud.dc.Pod;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.org.Cluster;
import com.cloud.utils.component.Inject;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value=DeploymentPlanner.class)
@ -68,4 +70,10 @@ public class SimplePlanner extends PlannerBase implements DeploymentPlanner {
protected SimplePlanner() {
super();
}
//TODO: set it to true if you want to use it
@Override
public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
return false;
}
}

View File

@ -139,5 +139,4 @@ public class ServiceOfferingVO extends DiskOfferingVO implements ServiceOffering
public int getMulticastRateMbps() {
return multicastRateMbps;
}
}

View File

@ -560,7 +560,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, null, params);
DeployDestination dest = null;
for (DeploymentPlanner planner : _planners) {
dest = planner.plan(vmProfile, plan, avoids);
if (planner.canHandle(vmProfile, plan, avoids)) {
dest = planner.plan(vmProfile, plan, avoids);
} else {
continue;
}
if (dest != null) {
avoids.addHost(dest.getHost().getId());
journal.record("Deployment found ", vmProfile, dest);

View File

@ -229,4 +229,8 @@ public class VirtualMachineProfileImpl<T extends VMInstanceVO> implements Virtua
public Map<Param, Object> getParameters() {
return _params;
}
public void setServiceOffering(ServiceOfferingVO offering) {
_offering = offering;
}
}