public VirtualMachineProfileImpl(VirtualMachine vm, VirtualMachineTemplate template, ServiceOffering offering, Account owner, Map<Param, Object> params) { _vm = vm; _template = template; _offering = offering; _params = params; _owner = owner; if (_params == null) { _params = new HashMap<Param, Object>(); } if (vm != null) _type = vm.getType(); }
private VirtualMachineGuru getVmGuru(final VirtualMachine vm) { if(vm != null) { return _vmGurus.get(vm.getType()); } return null; }
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 String getEventType() { VirtualMachine.Type vmType = _entityMgr.findById(VirtualMachine.class, getId()).getType(); String eventType = ""; switch (vmType) { case ConsoleProxy: eventType = EventTypes.EVENT_PROXY_DIAGNOSTICS; break; case SecondaryStorageVm: eventType = EventTypes.EVENT_SSVM_DIAGNOSTICS; break; case DomainRouter: eventType = EventTypes.EVENT_ROUTER_DIAGNOSTICS; break; } return eventType; }
@Override public boolean postStateTransitionEvent(final StateMachine2.Transition<VirtualMachine.State, VirtualMachine.Event> transition, final VirtualMachine vo, final boolean status, final Object opaque) { final VirtualMachine.State newState = transition.getToState(); final VirtualMachine.Event event = transition.getEvent(); if (vo.getType() == VirtualMachine.Type.DomainRouter && event == VirtualMachine.Event.FollowAgentPowerOnReport && newState == VirtualMachine.State.Running && isOutOfBandMigrated(opaque)) { s_logger.debug("Virtual router " + vo.getInstanceName() + " is powered-on out-of-band"); } return true; }
@Override public Boolean fenceOff(VirtualMachine vm, Host host) { VirtualMachine.Type type = vm.getType(); if (type != VirtualMachine.Type.ConsoleProxy && type != VirtualMachine.Type.DomainRouter && type != VirtualMachine.Type.SecondaryStorageVm) { if (s_logger.isDebugEnabled()) { s_logger.debug("Don't know how to fence off " + type); } return null; } List<VolumeVO> vols = _volsDao.findByInstance(vm.getId()); for (VolumeVO vol : vols) { if (!vol.isRecreatable()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to fence off volumes that are not recreatable: " + vol); } return null; } if (vol.getPoolType().isShared()) { if (s_logger.isDebugEnabled()) { s_logger.debug("Unable to fence off volumes that are shared: " + vol); } return null; } } return true; } }
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); }
private boolean lockNetworkForUserVm(Network network, VirtualMachineProfile vm) { if (!vm.getVirtualMachine().getType().isUsedBySystem()) { long networkId = network.getId(); network = _networkDao.acquireInLockTable(network.getId(), 1200); if (network == null) { throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId); } return true; } return false; }
@Override public boolean applyUserData(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final DomainRouterVO router) throws ResourceUnavailableException { s_logger.debug("APPLYING USERDATA RULES"); final String typeString = "userdata and password entry"; final Long podId = dest.getPod().getId(); boolean isPodLevelException = false; if (podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { isPodLevelException = true; } final boolean failWhenDisconnect = false; final UserdataPwdRules pwdRules = new UserdataPwdRules(network, nic, profile, dest); return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(pwdRules)); }
@Override public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final DomainRouterVO router) throws ResourceUnavailableException { s_logger.debug("APPLYING DHCP ENTRY RULES"); final String typeString = "dhcp entry"; final Long podId = dest.getPod().getId(); boolean isPodLevelException = false; // for user vm in Basic zone we should try to re-deploy vm in a diff pod // if it fails to deploy in original pod; so throwing exception with Pod // scope if (podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) { isPodLevelException = true; } final boolean failWhenDisconnect = false; final DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, dest); return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules)); }
public VspVm buildVspVm(VirtualMachine vm, Network network) { VspVm.Builder vspVmBuilder = new VspVm.Builder() .uuid(vm.getUuid()) .name(vm.getInstanceName()) .state(getEnumValue(vm.getState(), VspVm.State.Unknown)); boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter); vspVmBuilder.domainRouter(isDomainRouter); if (network.getBroadcastUri() != null) { String domainRouterIp = network.getBroadcastUri().getPath().substring(1); vspVmBuilder.domainRouterIp(domainRouterIp); } return vspVmBuilder.build(); }
@Override public void prepare(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { final List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId()); // we have to implement default nics first - to ensure that default network elements start up first in multiple //nics case // (need for setting DNS on Dhcp to domR's Ip4 address) Collections.sort(nics, new Comparator<NicVO>() { @Override public int compare(final NicVO nic1, final NicVO nic2) { final boolean isDefault1 = nic1.isDefaultNic(); final boolean isDefault2 = nic2.isDefaultNic(); return isDefault1 ^ isDefault2 ? isDefault1 ^ true ? 1 : -1 : 0; } }); for (final NicVO nic : nics) { final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter); if (implemented == null || implemented.first() == null) { s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId()); } final NetworkVO network = implemented.second(); final NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network); vmProfile.addNic(profile); } }
@Override public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) { SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse(); vmResponse.setId(vm.getUuid()); vmResponse.setSystemVmType(vm.getType().toString().toLowerCase()); vmResponse.setName(vm.getHostName()); if (vm.getHostId() != null) { Host host = ApiDBUtils.findHostById(vm.getHostId()); if (host != null) { vmResponse.setHostId(host.getUuid()); } } if (vm.getState() != null) { vmResponse.setState(vm.getState().toString()); } if (vm.getType() == Type.DomainRouter) { VirtualRouter router = (VirtualRouter)vm; if (router.getRole() != null) { vmResponse.setRole(router.getRole().toString()); } } vmResponse.setObjectName("systemvminstance"); return vmResponse; }
@Override public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(network.getDataCenterId()); if (nic != null && nic.getRequestedIPv4() != null) { throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic); } if (nic == null) { nic = new NicProfile(ReservationStrategy.Create, null, null, null, null); } getIp(nic, dc, vm, network); if (nic.getIPv4Address() == null) { nic.setReservationStrategy(ReservationStrategy.Start); } else if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) { nic.setReservationStrategy(ReservationStrategy.Managed); } else { nic.setReservationStrategy(ReservationStrategy.Create); } return nic; }
pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState); if (vo.getType() != VirtualMachine.Type.User) { return true;
final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter); if (implemented == null || implemented.first() == null) { s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId());
if (vm.getType() == VirtualMachine.Type.User) { final String platform = stopAns.getPlatform(); if (platform != null) {
if (vm.getType() == VirtualMachine.Type.User) { UserVmVO userVm = _userVmDao.findById(vm.getId()); vol.setDisplayVolume(userVm.isDisplayVm()); if (vm.getType() == VirtualMachine.Type.User) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null, size, Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());