Search in sources :

Example 1 with VirtualMachineEntityImpl

use of org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachineFromScratch.

@Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    //load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    rootDiskOfferingInfo.setDiskOffering(computeOffering);
    Long diskOfferingId = vm.getDiskOfferingId();
    if (diskOfferingId == null) {
        throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
    }
    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()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIopsDo");
            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);
        }
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
        }
    }
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 2 with VirtualMachineEntityImpl

use of org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachineFromScratch.

@Override
public VirtualMachineEntity createVirtualMachineFromScratch(String id, String owner, String isoId, String hostName, String displayName, String hypervisor, String os, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan, Map<String, Map<Integer, String>> extraDhcpOptionMap, Long diskOfferingId) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks, vmEntityManager);
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    // load vm instance and offerings and call virtualMachineManagerImpl
    VMInstanceVO vm = _vmDao.findByUuid(id);
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    if (diskOfferingId == null) {
        throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
    }
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    if (diskOffering == null) {
        throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
    }
    rootDiskOfferingInfo.setDiskOffering(diskOffering);
    Long size = null;
    if (!diskOffering.isComputeOnly() && 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()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIopsDo");
            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);
        }
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<Network, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, networkNicMap.get(uuid));
        }
    }
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<DiskOfferingInfo>(), networkIpMap, plan, hypervisorType, extraDhcpOptionMap, null);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 3 with VirtualMachineEntityImpl

use of org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachine.

@Override
public VirtualMachineEntity createVirtualMachine(String id, String owner, String templateId, String hostName, String displayName, String hypervisor, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, NicProfile> networkNicMap, DeploymentPlan plan, Long rootDiskSize) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks,
    // vmEntityManager);
    LinkedHashMap<NetworkVO, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, new ArrayList<NicProfile>(Arrays.asList(networkNicMap.get(uuid))));
        }
    }
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    //load vm instance and offerings and call virtualMachineManagerImpl
    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
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    List<DiskOfferingInfo> dataDiskOfferings = new ArrayList<DiskOfferingInfo>();
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    rootDiskOfferingInfo.setDiskOffering(computeOffering);
    rootDiskOfferingInfo.setSize(rootDiskSize);
    if (computeOffering.isCustomizedIops() != null && computeOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIops");
            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) {
        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);
        }
        DiskOfferingInfo dataDiskOfferingInfo = new DiskOfferingInfo();
        dataDiskOfferingInfo.setDiskOffering(diskOffering);
        dataDiskOfferingInfo.setSize(size);
        if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
            Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
            if (userVmDetails != null) {
                String minIops = userVmDetails.get("minIopsDo");
                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);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Example 4 with VirtualMachineEntityImpl

use of org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl in project cloudstack by apache.

the class CloudOrchestrator method createVirtualMachine.

@Override
public VirtualMachineEntity createVirtualMachine(String id, String owner, String templateId, String hostName, String displayName, String hypervisor, int cpu, int speed, long memory, Long diskSize, List<String> computeTags, List<String> rootDiskTags, Map<String, List<NicProfile>> networkNicMap, DeploymentPlan plan, Long rootDiskSize, Map<String, Map<Integer, String>> extraDhcpOptionMap, Map<Long, DiskOffering> dataDiskTemplateToDiskOfferingMap, Long dataDiskOfferingId, Long rootDiskOfferingId) throws InsufficientCapacityException {
    // VirtualMachineEntityImpl vmEntity = new VirtualMachineEntityImpl(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, networks,
    // vmEntityManager);
    LinkedHashMap<NetworkVO, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
    for (String uuid : networkNicMap.keySet()) {
        NetworkVO network = _networkDao.findByUuid(uuid);
        if (network != null) {
            networkIpMap.put(network, networkNicMap.get(uuid));
        }
    }
    VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
    vmEntity.init(id, owner, hostName, displayName, cpu, speed, memory, computeTags, rootDiskTags, new ArrayList<String>(networkNicMap.keySet()));
    HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
    // load vm instance and offerings and call virtualMachineManagerImpl
    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
    DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
    List<DiskOfferingInfo> dataDiskOfferings = new ArrayList<DiskOfferingInfo>();
    ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
    DiskOfferingVO rootDiskOffering = _diskOfferingDao.findById(rootDiskOfferingId);
    if (rootDiskOffering == null) {
        throw new InvalidParameterValueException("Unable to find root disk offering " + rootDiskOfferingId);
    }
    rootDiskOfferingInfo.setDiskOffering(rootDiskOffering);
    rootDiskOfferingInfo.setSize(rootDiskSize);
    if (rootDiskOffering.isCustomizedIops() != null && rootDiskOffering.isCustomizedIops()) {
        Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
        if (userVmDetails != null) {
            String minIops = userVmDetails.get("minIops");
            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 (dataDiskOfferingId != null) {
        DiskOfferingVO diskOffering = _diskOfferingDao.findById(dataDiskOfferingId);
        if (diskOffering == null) {
            throw new InvalidParameterValueException("Unable to find data disk offering " + dataDiskOfferingId);
        }
        if (!diskOffering.isComputeOnly()) {
            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);
            }
            DiskOfferingInfo dataDiskOfferingInfo = new DiskOfferingInfo();
            dataDiskOfferingInfo.setDiskOffering(diskOffering);
            dataDiskOfferingInfo.setSize(size);
            if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
                Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
                if (userVmDetails != null) {
                    String minIops = userVmDetails.get("minIopsDo");
                    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);
        }
    }
    if (dataDiskTemplateToDiskOfferingMap != null && !dataDiskTemplateToDiskOfferingMap.isEmpty()) {
        for (Entry<Long, DiskOffering> datadiskTemplateToDiskOffering : dataDiskTemplateToDiskOfferingMap.entrySet()) {
            DiskOffering dataDiskOffering = datadiskTemplateToDiskOffering.getValue();
            if (dataDiskOffering == null) {
                throw new InvalidParameterValueException("Unable to find disk offering " + dataDiskOfferingId);
            }
            if (dataDiskOffering.getDiskSize() == 0) {
                // Custom disk offering is not supported for volumes created from datadisk templates
                throw new InvalidParameterValueException("Disk offering " + dataDiskOffering + " requires size parameter.");
            }
        }
    }
    _itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(templateId)), computeOffering, rootDiskOfferingInfo, dataDiskOfferings, networkIpMap, plan, hypervisorType, extraDhcpOptionMap, dataDiskTemplateToDiskOfferingMap);
    return vmEntity;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) DiskOffering(com.cloud.offering.DiskOffering) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) VirtualMachineEntityImpl(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl) LinkedHashMap(java.util.LinkedHashMap) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) List(java.util.List) DiskOfferingInfo(com.cloud.offering.DiskOfferingInfo)

Aggregations

InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)4 NetworkVO (com.cloud.network.dao.NetworkVO)4 DiskOfferingInfo (com.cloud.offering.DiskOfferingInfo)4 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)4 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)4 NicProfile (com.cloud.vm.NicProfile)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 VirtualMachineEntityImpl (org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntityImpl)4 Network (com.cloud.network.Network)2 DiskOffering (com.cloud.offering.DiskOffering)1