@Override public long getId() { return _vm.getId(); }
/** * Check Affinity Group */ protected boolean checkAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, VirtualMachine vm, long plannedHostId) { List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId()); groupVMIds.remove(vm.getId()); Set<Long> hostIds = getHostIdSet(groupVMIds); return CollectionUtils.isEmpty(hostIds) || hostIds.contains(plannedHostId); }
protected boolean areAffinityGroupsAssociated(final VirtualMachineProfile vmProfile) { final VirtualMachine vm = vmProfile.getVirtualMachine(); final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId()); if (vmGroupCount > 0) { return true; } return false; }
protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId()); if (vmGroupCount > 0) { return true; } return false; }
private DataStore pickExistingRootVolumeFromDataStore(VirtualMachineProfile profile, DataStore dataStore) { final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(profile.getVirtualMachine().getId(), Volume.Type.ROOT); if (CollectionUtils.isNotEmpty(volumes)) { dataStore = pickDataStoreFromVolumes(volumes); } return dataStore; }
/** * Process Affinity Group for VM deployment */ protected void processAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, DeploymentPlan plan, VirtualMachine vm) { AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId()); s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId()); groupVMIds.remove(vm.getId()); List<Long> preferredHosts = getPreferredHostsFromGroupVMIds(groupVMIds); plan.setPreferredHosts(preferredHosts); }
@Override public void finalizeStop(VirtualMachineProfile profile, Answer answer) { if (answer != null) { DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); processStopOrRebootAnswer(elbVm, answer); } }
@Override public void process(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws AffinityConflictException { VirtualMachine vm = vmProfile.getVirtualMachine(); List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType()); if (CollectionUtils.isNotEmpty(vmGroupMappings)) { for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { processAffinityGroup(vmGroupMapping, plan, vm); } } }
private void generateNetworkUsageForVm(VirtualMachine vm, boolean isDisplay, String eventType){ List<NicVO> nics = _nicDao.listByVmId(vm.getId()); for (NicVO nic : nics) { NetworkVO network = _networkDao.findById(nic.getNetworkId()); long isDefault = (nic.isDefaultNic()) ? 1 : 0; UsageEventUtils.publishUsageEvent(eventType, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, vm.getClass().getName(), vm.getUuid(), isDisplay); } }
private void generateUsageEvent(Long serviceOfferingId, VirtualMachine vm, String eventType){ boolean displayVm = true; if(vm.getType() == VirtualMachine.Type.User){ UserVmVO uservm = _userVmDao.findById(vm.getId()); displayVm = uservm.isDisplayVm(); } _userVmMgr.generateUsageEvent(vm, displayVm, eventType); }
@Override public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) { if (!status) { return false; } State newState = transition.getToState(); if ((newState == State.Expunging) || (newState == State.Error)) { // cleanup all affinity groups associations of the Expunged VM SearchCriteria<AffinityGroupVMMapVO> sc = _affinityGroupVMMapDao.createSearchCriteria(); sc.addAnd("instanceId", SearchCriteria.Op.EQ, vo.getId()); _affinityGroupVMMapDao.expunge(sc); } return true; }
@Override public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque) { if (!status) { return false; } State oldState = transition.getCurrentState(); State newState = transition.getToState(); if ((oldState == State.Starting) && (newState != State.Starting)) { // cleanup all VM reservation entries SearchCriteria<VMReservationVO> sc = _reservationDao.createSearchCriteria(); sc.addAnd("vmId", SearchCriteria.Op.EQ, vo.getId()); _reservationDao.expunge(sc); } return true; } }
@Override public List<NicProfile> getNicProfiles(final VirtualMachine vm) { final List<NicVO> nics = _nicDao.listByVmId(vm.getId()); final List<NicProfile> profiles = new ArrayList<NicProfile>(); if (nics != null) { for (final Nic nic : nics) { final NetworkVO network = _networksDao.findById(nic.getNetworkId()); final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId()); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); guru.updateNicProfile(profile, network); profiles.add(profile); } } return profiles; }
private String getControlNicIpForVM(VirtualMachine vm) { if (vm.getType() == VirtualMachine.Type.ConsoleProxy || vm.getType() == VirtualMachine.Type.SecondaryStorageVm) { NicVO nic = _nicsDao.getControlNicForVM(vm.getId()); return nic.getIPv4Address(); } else if (vm.getType() == VirtualMachine.Type.DomainRouter) { return vm.getPrivateIpAddress(); } else { return null; } } public Command cleanup(final String vmName) {
@Override public boolean check(VirtualMachineProfile vmProfile, DeployDestination plannedDestination) throws AffinityConflictException { if (plannedDestination.getHost() == null) { return true; } long plannedHostId = plannedDestination.getHost().getId(); VirtualMachine vm = vmProfile.getVirtualMachine(); List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType()); if (CollectionUtils.isNotEmpty(vmGroupMappings)) { for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { if (!checkAffinityGroup(vmGroupMapping, vm, plannedHostId)) { return false; } } } return true; }
@Override public Pair<String, Integer> getVncPort(final VirtualMachine vm) { if (vm.getHostId() == null) { s_logger.warn("VM " + vm.getHostName() + " does not have host, return -1 for its VNC port"); return new Pair<String, Integer>(null, -1); } if (s_logger.isTraceEnabled()) { s_logger.trace("Trying to retrieve VNC port from agent about VM " + vm.getHostName()); } final GetVncPortAnswer answer = (GetVncPortAnswer)_agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName())); if (answer != null && answer.getResult()) { return new Pair<String, Integer>(answer.getAddress(), answer.getPort()); } return new Pair<String, Integer>(null, -1); }
@Override public void finalizeExpunge(VirtualMachine vm) { ConsoleProxyVO proxy = _consoleProxyDao.findById(vm.getId()); proxy.setPublicIpAddress(null); proxy.setPublicMacAddress(null); proxy.setPublicNetmask(null); proxy.setPrivateMacAddress(null); proxy.setPrivateIpAddress(null); _consoleProxyDao.update(proxy.getId(), proxy); }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getVirtualMachine().getId()); userVmDao.loadDetails(_userVM); // for basic zone, send vm data/password information only to the router in the same pod NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); return visitor.visit(this); }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); _userVM = userVmDao.findById(_profile.getVirtualMachine().getId()); userVmDao.loadDetails(_userVM); NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao(); _nicVo = nicDao.findById(_nic.getId()); // for basic zone, send vm data/password information only to the router in the same pod VMTemplateDao templateDao = visitor.getVirtualNetworkApplianceFactory().getTemplateDao(); _template = templateDao.findByIdIncludingRemoved(_profile.getTemplateId()); return visitor.visit(this); }
@Override public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException { DomainRouterVO elbVm = _routerDao.findById(profile.getVirtualMachine().getId()); List<NicProfile> nics = profile.getNics(); for (NicProfile nic : nics) { if (nic.getTrafficType() == TrafficType.Public) { elbVm.setPublicIpAddress(nic.getIPv4Address()); elbVm.setPublicNetmask(nic.getIPv4Netmask()); elbVm.setPublicMacAddress(nic.getMacAddress()); } else if (nic.getTrafficType() == TrafficType.Control) { elbVm.setPrivateIpAddress(nic.getIPv4Address()); elbVm.setPrivateMacAddress(nic.getMacAddress()); } } _routerDao.update(elbVm.getId(), elbVm); finalizeCommandsOnStart(cmds, profile); return true; }