RodrigoDLopez commented on code in PR #6947:
URL: https://github.com/apache/cloudstack/pull/6947#discussion_r1073862795


##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -5398,11 +5403,19 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, 
Object>> startVirtualMach
             String password = "saved_password";
             if (template.isEnablePassword()) {
                 if (vm.getDetail("password") != null) {
+                    s_logger.debug(String.format("Decrypting VM [%s] current 
password.", vm));
                     password = 
DBEncryptionUtil.decrypt(vm.getDetail("password"));
+                } else if 
(additionalParams.containsKey(VirtualMachineProfile.Param.VmPassword)) {

Review Comment:
   potential NPE here.
   ```suggestion
                   } else if (additionalParams != null && 
additionalParams.containsKey(VirtualMachineProfile.Param.VmPassword)) {
   ```



##########
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java:
##########
@@ -5398,11 +5403,19 @@ public Pair<UserVmVO, Map<VirtualMachineProfile.Param, 
Object>> startVirtualMach
             String password = "saved_password";
             if (template.isEnablePassword()) {
                 if (vm.getDetail("password") != null) {
+                    s_logger.debug(String.format("Decrypting VM [%s] current 
password.", vm));
                     password = 
DBEncryptionUtil.decrypt(vm.getDetail("password"));
+                } else if 
(additionalParams.containsKey(VirtualMachineProfile.Param.VmPassword)) {
+                    s_logger.debug(String.format("A password for VM [%s] was 
informed. Setting VM password to value defined by user.", vm));
+                    password = 
String.valueOf(additionalParams.get(VirtualMachineProfile.Param.VmPassword));
+                    vm.setPassword(password);
                 } else {
+                    s_logger.debug(String.format("Setting VM [%s] password to 
a randomly generated password.", vm));
                     password = _mgr.generateRandomPassword();
                     vm.setPassword(password);
                 }
+            } else if 
(additionalParams.containsKey(VirtualMachineProfile.Param.VmPassword)) {

Review Comment:
   ```suggestion
               } else if (additionalParams != null && 
additionalParams.containsKey(VirtualMachineProfile.Param.VmPassword)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to