Search in sources :

Example 36 with UserVmVO

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

the class ImplicitPlannerTest method initializeForTest.

private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan) {
    DataCenterVO mockDc = mock(DataCenterVO.class);
    VMInstanceVO vm = mock(VMInstanceVO.class);
    UserVmVO userVm = mock(UserVmVO.class);
    ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
    AccountVO account = mock(AccountVO.class);
    when(account.getId()).thenReturn(accountId);
    when(account.getAccountId()).thenReturn(accountId);
    when(vmProfile.getOwner()).thenReturn(account);
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    when(vmProfile.getId()).thenReturn(12L);
    when(vmDao.findById(12L)).thenReturn(userVm);
    when(userVm.getAccountId()).thenReturn(accountId);
    when(vm.getDataCenterId()).thenReturn(dataCenterId);
    when(dcDao.findById(1L)).thenReturn(mockDc);
    when(plan.getDataCenterId()).thenReturn(dataCenterId);
    when(plan.getClusterId()).thenReturn(null);
    when(plan.getPodId()).thenReturn(null);
    when(configDao.getValue(anyString())).thenReturn("false").thenReturn("CPU");
    // Mock offering details.
    when(vmProfile.getServiceOffering()).thenReturn(offering);
    when(offering.getId()).thenReturn(offeringId);
    when(vmProfile.getServiceOfferingId()).thenReturn(offeringId);
    when(offering.getCpu()).thenReturn(noOfCpusInOffering);
    when(offering.getSpeed()).thenReturn(cpuSpeedInOffering);
    when(offering.getRamSize()).thenReturn(ramInOffering);
    List<Long> clustersWithEnoughCapacity = new ArrayList<Long>();
    clustersWithEnoughCapacity.add(1L);
    clustersWithEnoughCapacity.add(2L);
    clustersWithEnoughCapacity.add(3L);
    when(capacityDao.listClustersInZoneOrPodByHostCapacities(dataCenterId, noOfCpusInOffering * cpuSpeedInOffering, ramInOffering * 1024L * 1024L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersWithEnoughCapacity);
    Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
    clusterCapacityMap.put(1L, 2048D);
    clusterCapacityMap.put(2L, 2048D);
    clusterCapacityMap.put(3L, 2048D);
    Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
    when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
    List<Long> disabledClusters = new ArrayList<Long>();
    List<Long> clustersWithDisabledPods = new ArrayList<Long>();
    when(clusterDao.listDisabledClusters(dataCenterId, null)).thenReturn(disabledClusters);
    when(clusterDao.listClustersWithDisabledPods(dataCenterId)).thenReturn(clustersWithDisabledPods);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) AccountVO(com.cloud.user.AccountVO) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.cloud.utils.Pair)

Example 37 with UserVmVO

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

the class ManagementServerImpl method getVMPassword.

@Override
public String getVMPassword(final GetVMPasswordCmd cmd) {
    final Account caller = getCaller();
    final UserVmVO vm = _userVmDao.findById(cmd.getId());
    if (vm == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("No VM with specified id found.");
        ex.addProxyObject(cmd.getId().toString(), "vmId");
        throw ex;
    }
    // make permission check
    _accountMgr.checkAccess(caller, null, true, vm);
    _userVmDao.loadDetails(vm);
    final String password = vm.getDetail("Encrypted.Password");
    if (password == null || password.equals("")) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("No password for VM with specified id found. " + "If VM is created from password enabled template and SSH keypair is assigned to VM then only password can be retrieved.");
        ex.addProxyObject(vm.getUuid(), "vmId");
        throw ex;
    }
    return password;
}
Also used : Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 38 with UserVmVO

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

the class VolumeApiServiceImpl method createVolumeFromSnapshot.

protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId, Long vmId) throws StorageUnavailableException {
    VolumeInfo createdVolume = null;
    SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
    snapshot.getVolumeId();
    UserVmVO vm = null;
    if (vmId != null) {
        vm = _userVmDao.findById(vmId);
    }
    // sync old snapshots to region store if necessary
    createdVolume = _volumeMgr.createVolumeFromSnapshot(volume, snapshot, vm);
    VolumeVO volumeVo = _volsDao.findById(createdVolume.getId());
    UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(), createdVolume.getDiskOfferingId(), null, createdVolume.getSize(), Volume.class.getName(), createdVolume.getUuid(), volumeVo.isDisplayVolume());
    return volumeVo;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VmWorkDetachVolume(com.cloud.vm.VmWorkDetachVolume) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkResizeVolume(com.cloud.vm.VmWorkResizeVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) VmWorkExtractVolume(com.cloud.vm.VmWorkExtractVolume) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Example 39 with UserVmVO

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

the class UserVmDaoImplTest method testPersist.

public void testPersist() {
    UserVmDao dao = ComponentLocator.inject(UserVmDaoImpl.class);
    dao.expunge(1000l);
    UserVmVO vo = new UserVmVO(1000l, "instancename", "displayname", 1, HypervisorType.XenServer, 1, true, true, 1, 1, 1, "userdata", "name");
    dao.persist(vo);
    vo = dao.findById(1000l);
    assert (vo.getType() == VirtualMachine.Type.User) : "Incorrect type " + vo.getType();
}
Also used : UserVmVO(com.cloud.vm.UserVmVO)

Example 40 with UserVmVO

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

the class QueryManagerImpl method searchForAffinityGroupsInternal.

public Pair<List<AffinityGroupJoinVO>, Integer> searchForAffinityGroupsInternal(ListAffinityGroupsCmd cmd) {
    final Long affinityGroupId = cmd.getId();
    final String affinityGroupName = cmd.getAffinityGroupName();
    final String affinityGroupType = cmd.getAffinityGroupType();
    final Long vmId = cmd.getVirtualMachineId();
    final String accountName = cmd.getAccountName();
    Long domainId = cmd.getDomainId();
    final Long projectId = cmd.getProjectId();
    Boolean isRecursive = cmd.isRecursive();
    final Boolean listAll = cmd.listAll();
    final Long startIndex = cmd.getStartIndex();
    final Long pageSize = cmd.getPageSizeVal();
    final String keyword = cmd.getKeyword();
    Account caller = CallContext.current().getCallingAccount();
    if (vmId != null) {
        UserVmVO userVM = _userVmDao.findById(vmId);
        if (userVM == null) {
            throw new InvalidParameterValueException("Unable to list affinity groups for virtual machine instance " + vmId + "; instance not found.");
        }
        _accountMgr.checkAccess(caller, null, true, userVM);
        return listAffinityGroupsByVM(vmId.longValue(), startIndex, pageSize);
    }
    List<Long> permittedAccounts = new ArrayList<Long>();
    Ternary<Long, Boolean, ListProjectResourcesCriteria> ternary = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, affinityGroupId, accountName, projectId, permittedAccounts, ternary, listAll, false);
    domainId = ternary.first();
    isRecursive = ternary.second();
    ListProjectResourcesCriteria listProjectResourcesCriteria = ternary.third();
    Filter searchFilter = new Filter(AffinityGroupJoinVO.class, ID_FIELD, true, startIndex, pageSize);
    SearchCriteria<AffinityGroupJoinVO> sc = buildAffinityGroupSearchCriteria(domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
    Pair<List<AffinityGroupJoinVO>, Integer> uniqueGroupsPair = _affinityGroupJoinDao.searchAndCount(sc, searchFilter);
    // search group details by ids
    List<AffinityGroupJoinVO> affinityGroups = new ArrayList<AffinityGroupJoinVO>();
    Integer count = uniqueGroupsPair.second();
    if (count.intValue() != 0) {
        List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
        Long[] vrIds = new Long[uniqueGroups.size()];
        int i = 0;
        for (AffinityGroupJoinVO v : uniqueGroups) {
            vrIds[i++] = v.getId();
        }
        affinityGroups = _affinityGroupJoinDao.searchByIds(vrIds);
    }
    if (!permittedAccounts.isEmpty()) {
        // add domain level affinity groups
        if (domainId != null) {
            SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
            affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
        } else {
            for (Long permAcctId : permittedAccounts) {
                Account permittedAcct = _accountDao.findById(permAcctId);
                SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
                affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId()));
            }
        }
    } else if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
        // list all domain level affinity groups for the domain admin case
        SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword);
        affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
    }
    return new Pair<List<AffinityGroupJoinVO>, Integer>(affinityGroups, affinityGroups.size());
}
Also used : Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) SearchCriteria(com.cloud.utils.db.SearchCriteria) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) AffinityGroupJoinVO(com.cloud.api.query.vo.AffinityGroupJoinVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Aggregations

UserVmVO (com.cloud.vm.UserVmVO)88 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)30 Account (com.cloud.user.Account)23 ArrayList (java.util.ArrayList)21 HostVO (com.cloud.host.HostVO)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)13 DataCenterVO (com.cloud.dc.DataCenterVO)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 VolumeVO (com.cloud.storage.VolumeVO)10 NicVO (com.cloud.vm.NicVO)10 VMInstanceVO (com.cloud.vm.VMInstanceVO)10 ActionEvent (com.cloud.event.ActionEvent)9 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)9 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)9 DomainRouterVO (com.cloud.vm.DomainRouterVO)9 Commands (com.cloud.agent.manager.Commands)8 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)8 VirtualRouter (com.cloud.network.router.VirtualRouter)8