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; }
/** * get the list of all Vm id's in the network that are running on the host */ @Override public List<Long> getActiveVmsInNetworkOnHost(long networkId, long hostId, boolean includeVr) { List <Long> vmIds = new ArrayList<>(); List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId, VirtualMachine.State.Running, VirtualMachine.State.Migrating); // Find routers for the network List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId); if (vms != null) { for (UserVmVO vm : vms) { if (vm.getHostId() == hostId) vmIds.add(vm.getId()); } } if (routers.size() != 0 && includeVr) { for (DomainRouterVO router: routers) { if (router.getHostId() == hostId) vmIds.add(router.getId()); } } return vmIds; }
private int getMaxDataVolumesSupported(UserVmVO vm) { Long hostId = vm.getHostId(); if (hostId == null) { hostId = vm.getLastHostId(); } HostVO host = _hostDao.findById(hostId); Integer maxDataVolumesSupported = null; if (host != null) { _hostDao.loadDetails(host); maxDataVolumesSupported = _hypervisorCapabilitiesDao.getMaxDataVolumesLimit(host.getHypervisorType(), host.getDetail("product_version")); } if (maxDataVolumesSupported == null || maxDataVolumesSupported.intValue() <= 0) { maxDataVolumesSupported = 6; // 6 data disks by default if nothing // is specified in // 'hypervisor_capabilities' table } return maxDataVolumesSupported.intValue(); }
private boolean attachISOToVM(long vmId, long isoId, boolean attach) { UserVmVO vm = _userVmDao.findById(vmId); if (vm == null) { return false; } else if (vm.getState() != State.Running) { return true; } // prepare ISO ready to mount on hypervisor resource level TemplateInfo tmplt = prepareIso(isoId, vm.getDataCenterId(), vm.getHostId(), null); if (tmplt == null) { s_logger.error("Failed to prepare ISO ready to mount on hypervisor resource level"); throw new CloudRuntimeException("Failed to prepare ISO ready to mount on hypervisor resource level"); } String vmName = vm.getInstanceName(); HostVO host = _hostDao.findById(vm.getHostId()); if (host == null) { s_logger.warn("Host: " + vm.getHostId() + " does not exist"); return false; } DataTO isoTO = tmplt.getTO(); DiskTO disk = new DiskTO(isoTO, null, null, Volume.Type.ISO); Command cmd = null; if (attach) { cmd = new AttachCommand(disk, vmName); } else { cmd = new DettachCommand(disk, vmName); } Answer a = _agentMgr.easySend(vm.getHostId(), cmd); return (a != null && a.getResult()); }
@Override public void rollbackMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return; } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); try { networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic); } catch (final ResourceUnavailableException e) { s_logger.warn("Timed Out", e); } } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic); } }
@Override public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return; } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); try { networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic); } catch (final ResourceUnavailableException e) { s_logger.warn("Timed Out", e); } } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic); } }
@Override public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) { if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) { return true; } if (vm.getType() == VirtualMachine.Type.DomainRouter) { assert vm instanceof DomainRouterVO; final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine(); final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId()); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); try { networkTopology.setupDhcpForPvlan(false, router, router.getHostId(), nic); } catch (final ResourceUnavailableException e) { s_logger.warn("Timed Out", e); } } else if (vm.getType() == VirtualMachine.Type.User) { assert vm instanceof UserVmVO; final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine(); _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic); } return true; }
if (vm.getState() == State.Running && vm.getHostId() != null) { collectVmDiskStatistics(vm); collectVmNetworkStatistics(vm);
return vm.getHostId();
_itMgr.advanceStart(userVm.getUuid(), new HashMap<VirtualMachineProfile.Param, Object>(), null); vm = _userVMDao.findById(userVm.getId()); hostId = vm.getHostId(); } catch (Exception e) { s_logger.error("Start VM " + userVm.getInstanceName() + " before reverting failed due to " + e.getMessage());
_haMgr.cancelDestroy(vm, vm.getHostId());
if (vol.getVolumeType() == Volume.Type.DATADISK) { DiskOffering doff = _entityMgr.findById(DiskOffering.class, vol.getDiskOfferingId()); _volService.resizeVolumeOnHypervisor(vol.getId(), doff.getDiskSize(), tmpVm.getHostId(), vm.getInstanceName());
boolean sendCommand = vm.getState() == State.Running; AttachAnswer answer = null; Long hostId = vm.getHostId();
checkIfHostOfVMIsInPrepareForMaintenanceState(vmInstance.getHostId(), vmId, "Reboot");
HostSearch.and("host", HostSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostSearch.done(); HostUpSearch.and("host", HostUpSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostUpSearch.and("states", HostUpSearch.entity().getState(), SearchCriteria.Op.NIN); HostUpSearch.done(); HostRunningSearch.and("host", HostRunningSearch.entity().getHostId(), SearchCriteria.Op.EQ); HostRunningSearch.and("state", HostRunningSearch.entity().getState(), SearchCriteria.Op.EQ); HostRunningSearch.done(); StateChangeSearch.and("id", StateChangeSearch.entity().getId(), SearchCriteria.Op.EQ); StateChangeSearch.and("states", StateChangeSearch.entity().getState(), SearchCriteria.Op.EQ); StateChangeSearch.and("host", StateChangeSearch.entity().getHostId(), SearchCriteria.Op.EQ); StateChangeSearch.and("update", StateChangeSearch.entity().getUpdated(), SearchCriteria.Op.EQ); StateChangeSearch.done(); AccountHostSearch.and("hostId", AccountHostSearch.entity().getHostId(), SearchCriteria.Op.EQ); AccountHostSearch.done();
UserVmVO userVmVO = userVmDao.findById(vm.getId()); if (userVmVO != null) { HostVO host = hostDao.findById(userVmVO.getHostId()); if (host != null) { to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId()));