Search in sources :

Example 36 with VMInstanceVO

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

the class SecurityManagerMBeanImpl method simulateVmStart.

@Override
public void simulateVmStart(Long vmId) {
    //all we need is the vmId
    VMInstanceVO vm = new VMInstanceVO(vmId, 5, "foo", "foo", Type.User, null, HypervisorType.Any, 8, 1, 1, 1, false, false, null);
    _sgMgr.handleVmStarted(vm);
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 37 with VMInstanceVO

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

the class VMEntityManagerImpl method deployVirtualMachine.

@Override
public void deployVirtualMachine(String reservationId, VMEntityVO vmEntityVO, String caller, Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ResourceUnavailableException {
    //grab the VM Id and destination using the reservationId.
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VMReservationVO vmReservation = _reservationDao.findByReservationId(reservationId);
    if (vmReservation != null) {
        DataCenterDeployment reservedPlan = new DataCenterDeployment(vm.getDataCenterId(), vmReservation.getPodId(), vmReservation.getClusterId(), vmReservation.getHostId(), null, null);
        try {
            _itMgr.start(vm.getUuid(), params, reservedPlan, _planningMgr.getDeploymentPlannerByName(vmReservation.getDeploymentPlanner()));
        } catch (Exception ex) {
            // Retry the deployment without using the reservation plan
            DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
            if (reservedPlan.getAvoids() != null) {
                plan.setAvoids(reservedPlan.getAvoids());
            }
            _itMgr.start(vm.getUuid(), params, plan, null);
        }
    } else {
        // no reservation found. Let VirtualMachineManager retry
        _itMgr.start(vm.getUuid(), params, null, null);
    }
}
Also used : VMReservationVO(org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VMInstanceVO(com.cloud.vm.VMInstanceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AffinityConflictException(com.cloud.exception.AffinityConflictException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Example 38 with VMInstanceVO

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

the class VMEntityManagerImpl method destroyVirtualMachine.

@Override
public boolean destroyVirtualMachine(VMEntityVO vmEntityVO, String caller, boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException {
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    _itMgr.destroy(vm.getUuid(), expunge);
    return true;
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 39 with VMInstanceVO

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

the class SolidFireHostListener method getTargets.

private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) {
    List<Map<String, String>> targets = new ArrayList<>();
    StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
    // If you do not pass in null for the second parameter, you only get back applicable ROOT disks.
    List<VolumeVO> volumes = _volumeDao.findByPoolId(storagePoolId, null);
    if (volumes != null) {
        for (VolumeVO volume : volumes) {
            Long instanceId = volume.getInstanceId();
            if (instanceId != null) {
                VMInstanceVO vmInstance = _vmDao.findById(instanceId);
                Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId();
                if (hostIdForVm != null) {
                    HostVO hostForVm = _hostDao.findById(hostIdForVm);
                    if (hostForVm.getClusterId().equals(clusterId)) {
                        Map<String, String> details = new HashMap<>();
                        details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName());
                        details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress());
                        details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort()));
                        targets.add(details);
                    }
                }
            }
        }
    }
    return targets;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) HashMap(java.util.HashMap) Map(java.util.Map) HostVO(com.cloud.host.HostVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO)

Example 40 with VMInstanceVO

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

the class VMSnapshotManagerImpl method deleteAllVMSnapshotsThroughJobQueue.

public Outcome<VirtualMachine> deleteAllVMSnapshotsThroughJobQueue(final Long vmId, final VMSnapshot.Type type) {
    final CallContext context = CallContext.current();
    final User callingUser = context.getCallingUser();
    final Account callingAccount = context.getCallingAccount();
    final VMInstanceVO vm = _vmInstanceDao.findById(vmId);
    VmWorkJobVO workJob = new VmWorkJobVO(context.getContextId());
    workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
    workJob.setCmd(VmWorkDeleteAllVMSnapshots.class.getName());
    workJob.setAccountId(callingAccount.getId());
    workJob.setUserId(callingUser.getId());
    workJob.setStep(VmWorkJobVO.Step.Starting);
    workJob.setVmType(VirtualMachine.Type.Instance);
    workJob.setVmInstanceId(vm.getId());
    workJob.setRelated(AsyncJobExecutionContext.getOriginJobId());
    // save work context info (there are some duplications)
    VmWorkDeleteAllVMSnapshots workInfo = new VmWorkDeleteAllVMSnapshots(callingUser.getId(), callingAccount.getId(), vm.getId(), VMSnapshotManagerImpl.VM_WORK_JOB_HANDLER, type);
    workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
    _jobMgr.submitAsyncJob(workJob, VmWorkConstants.VM_WORK_QUEUE, vm.getId());
    AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(workJob.getId());
    return new VmJobVirtualMachineOutcome(workJob, vmId);
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) VMInstanceVO(com.cloud.vm.VMInstanceVO) CallContext(org.apache.cloudstack.context.CallContext) VmWorkJobVO(org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)

Aggregations

VMInstanceVO (com.cloud.vm.VMInstanceVO)131 ArrayList (java.util.ArrayList)40 HostVO (com.cloud.host.HostVO)34 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Account (com.cloud.user.Account)28 VolumeVO (com.cloud.storage.VolumeVO)24 Test (org.junit.Test)24 HostPodVO (com.cloud.dc.HostPodVO)15 HashMap (java.util.HashMap)14 NetworkVO (com.cloud.network.dao.NetworkVO)13 User (com.cloud.user.User)13 NicVO (com.cloud.vm.NicVO)13 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)13 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)12 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 ActionEvent (com.cloud.event.ActionEvent)11 Random (java.util.Random)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10