Search in sources :

Example 36 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.

the class StartSystemVMCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    VirtualMachine instance = _mgr.startSystemVM(getId());
    if (instance != null) {
        SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to start system vm");
    }
}
Also used : SystemVmResponse(com.cloud.api.response.SystemVmResponse) ServerApiException(com.cloud.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 37 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project CloudStack-archive by CloudStack-extras.

the class StopSystemVmCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ConcurrentOperationException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    VirtualMachine result = _mgr.stopSystemVM(this);
    if (result != null) {
        SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Fail to stop system vm");
    }
}
Also used : SystemVmResponse(com.cloud.api.response.SystemVmResponse) ServerApiException(com.cloud.api.ServerApiException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 38 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testDeallocate.

@Test
public void testDeallocate() throws Exception {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
    final DomainVO domain = mock(DomainVO.class);
    when(domain.getUuid()).thenReturn("aaaaaa");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
    final NicVO nic = mock(NicVO.class);
    when(nic.getId()).thenReturn(NETWORK_ID);
    when(nic.getIPv4Address()).thenReturn("10.10.10.10");
    when(nic.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    when(_nicDao.findById(NETWORK_ID)).thenReturn(nic);
    final NicProfile nicProfile = mock(NicProfile.class);
    when(nicProfile.getId()).thenReturn(NETWORK_ID);
    when(nicProfile.getIPv4Address()).thenReturn("10.10.10.10");
    when(nicProfile.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    final VirtualMachine vm = mock(VirtualMachine.class);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(vm.getState()).thenReturn(VirtualMachine.State.Expunging);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    when(vmProfile.getUuid()).thenReturn("aaaaaa");
    when(vmProfile.getInstanceName()).thenReturn("Test-VM");
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    _nuageVspGuestNetworkGuru.deallocate(network, nicProfile, vmProfile);
}
Also used : DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 39 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class BareMetalPlanner method plan.

@Override
public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
    VirtualMachine vm = vmProfile.getVirtualMachine();
    ServiceOffering offering = vmProfile.getServiceOffering();
    String hostTag = null;
    String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
    if (vm.getLastHostId() != null && haVmTag == null) {
        HostVO h = _hostDao.findById(vm.getLastHostId());
        DataCenter dc = _dcDao.findById(h.getDataCenterId());
        Pod pod = _podDao.findById(h.getPodId());
        Cluster c = _clusterDao.findById(h.getClusterId());
        s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId());
        return new DeployDestination(dc, pod, c, h);
    }
    if (haVmTag != null) {
        hostTag = haVmTag;
    } else if (offering.getHostTag() != null) {
        String[] tags = offering.getHostTag().split(",");
        if (tags.length > 0) {
            hostTag = tags[0];
        }
    }
    List<ClusterVO> clusters = _clusterDao.listByDcHyType(vm.getDataCenterId(), HypervisorType.BareMetal.toString());
    int cpu_requested;
    long ram_requested;
    HostVO target = null;
    List<HostVO> hosts;
    for (ClusterVO cluster : clusters) {
        hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
        if (hostTag != 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 + " use capacity from service offering");
        cpu_requested = offering.getCpu() * offering.getSpeed();
        ram_requested = offering.getRamSize() * 1024L * 1024L;
    } else {
        cpu_requested = target.getCpus() * target.getSpeed().intValue();
        ram_requested = target.getTotalMemory();
    }
    for (ClusterVO cluster : clusters) {
        if (haVmTag == null) {
            hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
        } else {
            s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId());
            return null;
        }
        for (HostVO h : hosts) {
            long cluster_id = h.getClusterId();
            ClusterDetailsVO cluster_detail_cpu = _clusterDetailsDao.findDetail(cluster_id, "cpuOvercommitRatio");
            ClusterDetailsVO cluster_detail_ram = _clusterDetailsDao.findDetail(cluster_id, "memoryOvercommitRatio");
            Float cpuOvercommitRatio = Float.parseFloat(cluster_detail_cpu.getValue());
            Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue());
            if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) {
                s_logger.debug("Find host " + h.getId() + " has enough capacity");
                DataCenter dc = _dcDao.findById(h.getDataCenterId());
                Pod pod = _podDao.findById(h.getPodId());
                return new DeployDestination(dc, pod, cluster, h);
            }
        }
    }
    s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, ram_requested));
    return null;
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) Pod(com.cloud.dc.Pod) ServiceOffering(com.cloud.offering.ServiceOffering) Cluster(com.cloud.org.Cluster) HostVO(com.cloud.host.HostVO) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 40 with VirtualMachine

use of com.cloud.vm.VirtualMachine in project cloudstack by apache.

the class DeploymentPlanningManagerImpl method finalizeReservation.

@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoids, final DeploymentPlanner planner) throws InsufficientServerCapacityException, AffinityConflictException {
    final VirtualMachine vm = vmProfile.getVirtualMachine();
    final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
    return Transaction.execute(new TransactionCallback<String>() {

        @Override
        public String doInTransaction(TransactionStatus status) {
            boolean saveReservation = true;
            if (vmGroupCount > 0) {
                List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
                SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
                criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
                _affinityGroupDao.lockRows(criteria, null, true);
                for (AffinityGroupProcessor processor : _affinityProcessors) {
                    if (!processor.check(vmProfile, plannedDestination)) {
                        saveReservation = false;
                        break;
                    }
                }
            }
            if (saveReservation) {
                VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getDataCenter().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
                if (planner != null) {
                    vmReservation.setDeploymentPlanner(planner.getName());
                }
                Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();
                if (vm.getHypervisorType() != HypervisorType.BareMetal) {
                    for (Volume vo : plannedDestination.getStorageForDisks().keySet()) {
                        volumeReservationMap.put(vo.getId(), plannedDestination.getStorageForDisks().get(vo).getId());
                    }
                    vmReservation.setVolumeReservation(volumeReservationMap);
                }
                _reservationDao.persist(vmReservation);
                return vmReservation.getUuid();
            }
            return null;
        }
    });
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) SearchCriteria(com.cloud.utils.db.SearchCriteria) VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) Volume(com.cloud.storage.Volume) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) AffinityGroupProcessor(org.apache.cloudstack.affinity.AffinityGroupProcessor) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine) DB(com.cloud.utils.db.DB)

Aggregations

VirtualMachine (com.cloud.vm.VirtualMachine)65 ArrayList (java.util.ArrayList)17 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 HostVO (com.cloud.host.HostVO)15 DataCenter (com.cloud.dc.DataCenter)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)10 ServiceOffering (com.cloud.offering.ServiceOffering)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 Test (org.junit.Test)9 Host (com.cloud.host.Host)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ServerApiException (com.cloud.api.ServerApiException)7 NicProfile (com.cloud.vm.NicProfile)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 SystemVmResponse (org.apache.cloudstack.api.response.SystemVmResponse)7 SystemVmResponse (com.cloud.api.response.SystemVmResponse)6 ManagementServerException (com.cloud.exception.ManagementServerException)6