private boolean checkHostSuitabilityForExplicitDedication(Long accountId, List<Long> domainIds, long hostId) { boolean suitable = true; List<UserVmVO> allVmsOnHost = getVmsOnHost(hostId); if (accountId != null) { for (UserVmVO vm : allVmsOnHost) { if (vm.getAccountId() != accountId) { s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another account"); throw new CloudRuntimeException("Host " + hostId + " found to be unsuitable for explicit dedication as it is " + "running instances of another account"); } } } else { for (UserVmVO vm : allVmsOnHost) { if (!domainIds.contains(vm.getDomainId())) { s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another domain"); throw new CloudRuntimeException("Host " + hostId + " found to be unsuitable for explicit dedication as it is " + "running instances of another domain"); } } } return suitable; }
/** * Create, persist and return vm snapshot for userVmVo with given parameters. * Persistence and support for custom service offerings are done on the same transaction * @param userVmVo user vm * @param vmId vm id * @param vsDescription vm description * @param vmSnapshotName vm snapshot name * @param vsDisplayName vm snapshot display name * @param vmSnapshotType vm snapshot type * @return vm snapshot * @throws CloudRuntimeException if vm snapshot couldn't be persisted */ protected VMSnapshot createAndPersistVMSnapshot(UserVmVO userVmVo, String vsDescription, String vmSnapshotName, String vsDisplayName, VMSnapshot.Type vmSnapshotType) { final Long vmId = userVmVo.getId(); final Long serviceOfferingId = userVmVo.getServiceOfferingId(); final VMSnapshotVO vmSnapshotVo = new VMSnapshotVO(userVmVo.getAccountId(), userVmVo.getDomainId(), vmId, vsDescription, vmSnapshotName, vsDisplayName, serviceOfferingId, vmSnapshotType, null); return Transaction.execute(new TransactionCallbackWithException<VMSnapshot, CloudRuntimeException>() { @Override public VMSnapshot doInTransaction(TransactionStatus status) { VMSnapshot vmSnapshot = _vmSnapshotDao.persist(vmSnapshotVo); if (vmSnapshot == null) { throw new CloudRuntimeException("Failed to create snapshot for vm: " + vmId); } addSupportForCustomServiceOffering(vmId, serviceOfferingId, vmSnapshot.getId()); return vmSnapshot; } }); }
if ((vmInstanceCheck != null) && !_domainDao.isChildDomain(account.getDomainId(), vmInstanceCheck.getDomainId())) { throw new PermissionDeniedException(msg + ". Permission denied.");
if (vmId != null) { UserVmVO vmInstance = _userVmDao.findById(vmId); domainRecord = _domainDao.findById(vmInstance.getDomainId()); if (domainRecord == null) { s_logger.error("Could not find the domainId for vmId:" + vmId);