|
39 | 39 | import javax.inject.Inject; |
40 | 40 | import javax.naming.ConfigurationException; |
41 | 41 |
|
| 42 | +import org.apache.commons.codec.binary.Base64; |
| 43 | +import org.apache.commons.collections.MapUtils; |
| 44 | +import org.apache.commons.lang3.StringUtils; |
| 45 | +import org.apache.log4j.Logger; |
| 46 | + |
42 | 47 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
43 | 48 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
44 | 49 | import org.apache.cloudstack.affinity.AffinityGroupService; |
|
91 | 96 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
92 | 97 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; |
93 | 98 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
94 | | -import org.apache.commons.codec.binary.Base64; |
95 | | -import org.apache.commons.collections.MapUtils; |
96 | | -import org.apache.commons.lang3.StringUtils; |
97 | | -import org.apache.log4j.Logger; |
98 | 99 |
|
99 | 100 | import com.cloud.agent.AgentManager; |
100 | 101 | import com.cloud.agent.api.Answer; |
@@ -688,10 +689,6 @@ public UserVm resetVMPassword(ResetVMPasswordCmd cmd, String password) throws Re |
688 | 689 |
|
689 | 690 | if (result) { |
690 | 691 | userVm.setPassword(password); |
691 | | - // update the password in vm_details table too |
692 | | - // Check if an SSH key pair was selected for the instance and if so |
693 | | - // use it to encrypt & save the vm password |
694 | | - encryptAndStorePassword(userVm, password); |
695 | 692 | } else { |
696 | 693 | throw new CloudRuntimeException("Failed to reset password for the virtual machine "); |
697 | 694 | } |
@@ -736,7 +733,6 @@ private boolean resetVMPasswordInternal(Long vmId, String password) throws Resou |
736 | 733 | } else { |
737 | 734 | final UserVmVO userVm = _vmDao.findById(vmId); |
738 | 735 | _vmDao.loadDetails(userVm); |
739 | | - userVm.setPassword(password); |
740 | 736 | // update the password in vm_details table too |
741 | 737 | // Check if an SSH key pair was selected for the instance and if so |
742 | 738 | // use it to encrypt & save the vm password |
@@ -850,8 +846,9 @@ private boolean resetVMSSHKeyInternal(Long vmId, String sshPublicKey, String pas |
850 | 846 | userVm.setPassword(password); |
851 | 847 | //update the encrypted password in vm_details table too |
852 | 848 | encryptAndStorePassword(userVm, password); |
| 849 | + } else { |
| 850 | + _vmDao.saveDetails(userVm); |
853 | 851 | } |
854 | | - _vmDao.saveDetails(userVm); |
855 | 852 |
|
856 | 853 | if (vmInstance.getState() == State.Stopped) { |
857 | 854 | s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of SSH Key reset"); |
@@ -4461,6 +4458,7 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach |
4461 | 4458 | password = DBEncryptionUtil.decrypt(vm.getDetail("password")); |
4462 | 4459 | } else { |
4463 | 4460 | password = _mgr.generateRandomPassword(); |
| 4461 | + vm.setPassword(password); |
4464 | 4462 | } |
4465 | 4463 | } |
4466 | 4464 |
|
@@ -4499,11 +4497,10 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, Object>> startVirtualMach |
4499 | 4497 | // this value is not being sent to the backend; need only for api |
4500 | 4498 | // display purposes |
4501 | 4499 | if (template.getEnablePassword()) { |
4502 | | - vm.setPassword((String)vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword)); |
4503 | | - vm.setUpdateParameters(false); |
4504 | 4500 | if (vm.getDetail("password") != null) { |
4505 | | - _vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId()); |
| 4501 | + _vmDetailsDao.removeDetail(vm.getId(), "password"); |
4506 | 4502 | } |
| 4503 | + vm.setUpdateParameters(false); |
4507 | 4504 | _vmDao.update(vm.getId(), vm); |
4508 | 4505 | } |
4509 | 4506 | } |
@@ -6180,7 +6177,7 @@ public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) |
6180 | 6177 | vm.setUpdateParameters(false); |
6181 | 6178 | _vmDao.loadDetails(vm); |
6182 | 6179 | if (vm.getDetail("password") != null) { |
6183 | | - _vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId()); |
| 6180 | + _vmDetailsDao.removeDetail(vm.getId(), "password"); |
6184 | 6181 | } |
6185 | 6182 | _vmDao.update(vm.getId(), vm); |
6186 | 6183 | } |
|
0 commit comments