@Override public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { if (!nic.isDefaultNic()) { return true; } try { return deleteConfigDriveIso(vm.getVirtualMachine()); } catch (ResourceUnavailableException e) { LOG.error("Failed to delete config drive due to: ", e); return false; } }
protected boolean areAffinityGroupsAssociated(VirtualMachineProfile vmProfile) { VirtualMachine vm = vmProfile.getVirtualMachine(); long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId()); if (vmGroupCount > 0) { return true; } return false; }
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; }
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; }
private Long findAgentId(VirtualMachineProfile profile, DeployDestination dest, DataStore dataStore) throws ResourceUnavailableException { Long agentId; if (dest.getHost() == null) { agentId = (profile.getVirtualMachine().getHostId() == null ? profile.getVirtualMachine().getLastHostId() : profile.getVirtualMachine().getHostId()); } else { agentId = dest.getHost().getId(); } if (!VirtualMachineManager.VmConfigDriveOnPrimaryPool.value()) { agentId = findAgentIdForImageStore(dataStore); } return agentId; }
@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); } } }
@Override public VirtualMachineTO toVmTO(final VirtualMachineProfile profile) { final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(profile.getVirtualMachine().getHypervisorType()); final VirtualMachineTO to = hvGuru.implement(profile); return to; }
@Override public boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException { // saveUserData is called by updateVirtualMachine API which requires VM to be shutdown // Upper layers should save userdata in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } return canHandle(network.getTrafficType()); }
@Override public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { if (vm.getType() != Type.User || vm.getHypervisorType() != HypervisorType.BareMetal) { return false; } DataCenterVO dc = zoneDao.findById(vm.getVirtualMachine().getDataCenterId()); if (dc.getNetworkType() == DataCenter.NetworkType.Advanced) { releaseVlan(network, vm); } return true; }
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 void finalizeStop(VirtualMachineProfile profile, Answer answer) { //release elastic IP here if assigned IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(profile.getId()); if (ip != null && ip.getSystem()) { CallContext ctx = CallContext.current(); try { _rulesMgr.disableStaticNat(ip.getId(), ctx.getCallingAccount(), ctx.getCallingUserId(), true); } catch (Exception ex) { s_logger.warn("Failed to disable static nat and release system ip " + ip + " as a part of vm " + profile.getVirtualMachine() + " stop due to exception ", ex); } } }
@Override public boolean saveSSHKey(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final String sshPublicKey) throws ResourceUnavailableException { // saveSSHKey is called by resetSSHKeyForVirtualMachine API which requires VM to be shutdown // Upper layers should save ssh public key in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } final boolean canHandle = canHandle(network.getTrafficType()); if (canHandle) { storePasswordInVmDetails(vm); } return canHandle; }
@Override public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException { // savePassword is called by resetPasswordForVirtualMachine API which requires VM to be shutdown // Upper layers should save password in db, we do not need to update/create config drive iso at this point // Config drive will be created with updated password when VM starts in future if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) { throw new CloudRuntimeException("VM should to stopped to reset password"); } final boolean canHandle = canHandle(network.getTrafficType()); if (canHandle) { storePasswordInVmDetails(vm); } return canHandle; }
@Override public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); to.setBootloader(vm.getBootLoaderType()); // Determine the VM's OS description GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId()); to.setOs(guestOS.getDisplayName()); return to; }
@Override public VirtualMachineTO implement(VirtualMachineProfile vm) { VirtualMachineTO to = toVirtualMachineTO(vm); to.setBootloader(vm.getBootLoaderType()); GuestOSVO guestOS = guestOsDao.findById(vm.getVirtualMachine() .getGuestOSId()); to.setOs(guestOS.getDisplayName()); return to; }
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao(); userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine()); // 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); // 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); }
public void createPasswordCommand(final VirtualRouter router, final VirtualMachineProfile profile, final NicVO nic, final Commands cmds) { final String password = (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); // password should be set only on default network element if (password != null && nic.isDefaultNic()) { final SavePasswordCommand cmd = new SavePasswordCommand(password, nic.getIPv4Address(), profile.getVirtualMachine().getHostName(), _networkModel.getExecuteInSeqNtwkElmtCmd()); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("password", cmd); } }