use of com.cloud.engine.cloud.entity.api.VirtualMachineEntityImpl in project cosmic by MissionCriticalCloud.
the class CloudOrchestrator method createVirtualMachineFromScratch.
@Override
public void createVirtualMachineFromScratch(final String id, final String owner, final String isoId, final String hostName, final String displayName, final String hypervisor, final String os, final int cpu, final long memory, final Long diskSize, final List<String> computeTags, final List<String> rootDiskTags, final Map<String, NicProfile> networkNicMap, final DeploymentPlan plan) throws InsufficientCapacityException {
final VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
vmEntity.init(id, owner, hostName, displayName, computeTags, rootDiskTags, new ArrayList<>(networkNicMap.keySet()));
// load vm instance and offerings and call virtualMachineManagerImpl
final VMInstanceVO vm = _vmDao.findByUuid(id);
final ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
final DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
rootDiskOfferingInfo.setDiskOffering(computeOffering);
final Long diskOfferingId = vm.getDiskOfferingId();
if (diskOfferingId == null) {
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
}
final DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
}
_volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
}
rootDiskOfferingInfo.setDiskOffering(diskOffering);
rootDiskOfferingInfo.setSize(size);
if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
final Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (userVmDetails != null) {
final String minIops = userVmDetails.get("minIopsDo");
final String maxIops = userVmDetails.get("maxIopsDo");
rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
}
}
final LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<>();
for (final String uuid : networkNicMap.keySet()) {
final NetworkVO network = _networkDao.findByUuid(uuid);
if (network != null) {
networkIpMap.put(network, new ArrayList<>(Arrays.asList(networkNicMap.get(uuid))));
}
}
final HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<>(), networkIpMap, plan, hypervisorType);
}
use of com.cloud.engine.cloud.entity.api.VirtualMachineEntityImpl in project cosmic by MissionCriticalCloud.
the class CloudOrchestrator method createVirtualMachine.
@Override
public void createVirtualMachine(final String id, final String owner, final String templateId, final String hostName, final String displayName, final String hypervisor, final int cpu, final long memory, final Long diskSize, final List<String> computeTags, final List<String> rootDiskTags, final Map<String, NicProfile> networkNicMap, final DeploymentPlan plan, final Long rootDiskSize) throws InsufficientCapacityException {
final LinkedHashMap<NetworkVO, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<>();
for (final String uuid : networkNicMap.keySet()) {
final NetworkVO network = _networkDao.findByUuid(uuid);
if (network != null) {
networkIpMap.put(network, new ArrayList<>(Arrays.asList(networkNicMap.get(uuid))));
}
}
final VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
vmEntity.init(id, owner, hostName, displayName, computeTags, rootDiskTags, new ArrayList<>(networkNicMap.keySet()));
final HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
// load vm instance and offerings and call virtualMachineManagerImpl
final VMInstanceVO vm = _vmDao.findByUuid(id);
// If the template represents an ISO, a disk offering must be passed in, and will be used to create the root disk
// Else, a disk offering is optional, and if present will be used to create the data disk
final DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
final List<DiskOfferingInfo> dataDiskOfferings = new ArrayList<>();
final ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
rootDiskOfferingInfo.setDiskOffering(computeOffering);
rootDiskOfferingInfo.setSize(rootDiskSize);
if (computeOffering.isCustomizedIops() != null && computeOffering.isCustomizedIops()) {
final Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (userVmDetails != null) {
final String minIops = userVmDetails.get("minIops");
final String maxIops = userVmDetails.get("maxIops");
rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
}
}
if (vm.getDiskOfferingId() != null) {
final DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId());
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
}
_volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
}
final DiskOfferingInfo dataDiskOfferingInfo = new DiskOfferingInfo();
dataDiskOfferingInfo.setDiskOffering(diskOffering);
dataDiskOfferingInfo.setSize(size);
if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
final Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (userVmDetails != null) {
final String minIops = userVmDetails.get("minIopsDo");
final String maxIops = userVmDetails.get("maxIopsDo");
dataDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
dataDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
}
}
dataDiskOfferings.add(dataDiskOfferingInfo);
}
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(templateId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, networkIpMap, plan, hypervisorType);
}
Aggregations