@Override public void persistDeviceBusInfo(UserVmVO vm, String rootDiskController) { String existingVmRootDiskController = vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER); if (StringUtils.isEmpty(existingVmRootDiskController) && !StringUtils.isEmpty(rootDiskController)) { vm.setDetail(VmDetailConstants.ROOT_DISK_CONTROLLER, rootDiskController); _vmDao.saveDetails(vm); if (s_logger.isDebugEnabled()) { s_logger.debug("Persisted device bus information rootDiskController=" + rootDiskController + " for vm: " + vm.getDisplayName()); } } }
private void encryptAndStorePassword(UserVmVO vm, String password) { String sshPublicKey = vm.getDetail("SSH.PublicKey"); if (sshPublicKey != null && !sshPublicKey.equals("") && password != null && !password.equals("saved_password")) { if (!sshPublicKey.startsWith("ssh-rsa")) { s_logger.warn("Only RSA public keys can be used to encrypt a vm password."); return; } String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password); if (encryptedPasswd == null) { throw new CloudRuntimeException("Error encrypting password"); } vm.setDetail("Encrypted.Password", encryptedPasswd); _vmDao.saveDetails(vm); } }
public void createVmDataCommandForVMs(final DomainRouterVO router, final Commands cmds, final long guestNetworkId) { final List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(guestNetworkId, VirtualMachine.State.Running, VirtualMachine.State.Migrating, VirtualMachine.State.Stopping); final DataCenterVO dc = _dcDao.findById(router.getDataCenterId()); for (final UserVmVO vm : vms) { boolean createVmData = true; if (dc.getNetworkType() == NetworkType.Basic && router.getPodIdToDeployIn().longValue() != vm.getPodIdToDeployIn().longValue()) { createVmData = false; } if (createVmData) { final NicVO nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId()); if (nic != null) { s_logger.debug("Creating user data entry for vm " + vm + " on domR " + router); _userVmDao.loadDetails(vm); createVmDataCommand(router, vm, nic, vm.getDetail("SSH.PublicKey"), cmds); } } } }
@Override public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException { final VirtualRouter router = userdata.getRouter(); final Commands commands = new Commands(Command.OnError.Stop); final VirtualMachineProfile profile = userdata.getProfile(); final NicVO nicVo = userdata.getNicVo(); final UserVmVO userVM = userdata.getUserVM(); _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands); _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, userVM.getDetail("SSH.PublicKey"), commands); return _networkGeneralHelper.sendCommandsToRouter(router, commands); }
@Override public String getVMPassword(final GetVMPasswordCmd cmd) { final Account caller = getCaller(); final UserVmVO vm = _userVmDao.findById(cmd.getId()); if (vm == null) { final InvalidParameterValueException ex = new InvalidParameterValueException("No VM with specified id found."); ex.addProxyObject(cmd.getId().toString(), "vmId"); throw ex; } // make permission check _accountMgr.checkAccess(caller, null, true, vm); _userVmDao.loadDetails(vm); final String password = vm.getDetail("Encrypted.Password"); if (password == null || password.equals("")) { final InvalidParameterValueException ex = new InvalidParameterValueException( "No password for VM with specified id found. " + "If VM is created from password enabled template and SSH keypair is assigned to VM then only password can be retrieved."); ex.addProxyObject(vm.getUuid(), "vmId"); throw ex; } return password; }
@Override public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException { final VirtualRouter router = userdata.getRouter(); final Commands commands = new Commands(Command.OnError.Stop); final VirtualMachineProfile profile = userdata.getProfile(); final NicVO nicVo = userdata.getNicVo(); final UserVmVO userVM = userdata.getUserVM(); final DeployDestination destination = userdata.getDestination(); if (router.getPodIdToDeployIn().longValue() == destination.getPod().getId()) { _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands); _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, userVM.getDetail("SSH.PublicKey"), commands); return _networkGeneralHelper.sendCommandsToRouter(router, commands); } return true; }
String controllerSetting = _configDao.getValue("vmware.root.disk.controller"); if (vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER) == null) { vm.setDetail(VmDetailConstants.ROOT_DISK_CONTROLLER, controllerSetting); if (vm.getDetail(VmDetailConstants.DATA_DISK_CONTROLLER) == null) { if (controllerSetting.equalsIgnoreCase("scsi")) { vm.setDetail(VmDetailConstants.DATA_DISK_CONTROLLER, "scsi");
controllerInfo.put(VmDetailConstants.ROOT_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.ROOT_DISK_CONTROLLER)); controllerInfo.put(VmDetailConstants.DATA_DISK_CONTROLLER, vm.getDetail(VmDetailConstants.DATA_DISK_CONTROLLER)); cmd.setControllerInfo(controllerInfo); s_logger.debug("Attach volume id:" + volumeToAttach.getId() + " on VM id:" + vm.getId() + " has controller info:" + controllerInfo);
String password = (String)vm.getParameter(VirtualMachineProfile.Param.VmPassword); String userData = uservm.getUserData(); String sshPublicKey = uservm.getDetail("SSH.PublicKey");
if (vm.getDetail("password") != null) { params = new HashMap<VirtualMachineProfile.Param, Object>(); params.put(VirtualMachineProfile.Param.VmPassword, password); vm.setUpdateParameters(false); _vmDao.loadDetails(vm); if (vm.getDetail("password") != null) { userVmDetailsDao.removeDetail(vm.getId(), "password");
vm.getUuid(), defaultNic.getMacAddress(), userVm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); String vmName = vm.getInstanceName(); String configDriveIsoRootFolder = "/tmp";
@Override public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) { UserVmVO vm = _vmDao.findById(profile.getId()); Map<String, String> details = userVmDetailsDao.listDetailsKeyPairs(vm.getId()); vm.setDetails(details); // add userdata info into vm profile Nic defaultNic = _networkModel.getDefaultNic(vm.getId()); if(defaultNic != null) { Network network = _networkModel.getNetwork(defaultNic.getNetworkId()); if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows"); List<String[]> vmData = _networkModel.generateVmData(vm.getUserData(), serviceOffering, vm.getDataCenterId(), vm.getInstanceName(), vm.getHostName(), vm.getId(), vm.getUuid(), defaultNic.getIPv4Address(), vm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); String vmName = vm.getInstanceName(); String configDriveIsoRootFolder = "/tmp"; String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso"; profile.setVmData(vmData); profile.setConfigDriveLabel(VirtualMachineManager.VmConfigDriveLabel.value()); profile.setConfigDriveIsoRootFolder(configDriveIsoRootFolder); profile.setConfigDriveIsoFile(isoFile); } } _templateMgr.prepareIsoForVmProfile(profile, dest); return true; }