cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject git commit: updated refs/heads/4.1 to 5aee73b
Date Thu, 19 Sep 2013 13:36:21 GMT
Updated Branches:
  refs/heads/4.1 c94feae9b -> 5aee73b1a


CLOUDSTACK-1325: add password in response of RestoreVM
(cherry picked from commit a5723992a0eeea9fc383c656b0d61dfc9e541ff9)

Signed-off-by: Wei Zhou <w.zhou@leaseweb.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5aee73b1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5aee73b1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5aee73b1

Branch: refs/heads/4.1
Commit: 5aee73b1a59f02c7853892d13afc58ad01f40c88
Parents: c94feae
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Mon May 27 21:32:56 2013 +0200
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Thu Sep 19 15:29:39 2013 +0200

----------------------------------------------------------------------
 api/src/com/cloud/vm/UserVmService.java         |  2 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 69 ++++++++++----------
 .../com/cloud/vm/MockUserVmManagerImpl.java     |  2 +-
 3 files changed, 36 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5aee73b1/api/src/com/cloud/vm/UserVmService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/UserVmService.java b/api/src/com/cloud/vm/UserVmService.java
index fb574fa..628add4 100755
--- a/api/src/com/cloud/vm/UserVmService.java
+++ b/api/src/com/cloud/vm/UserVmService.java
@@ -441,5 +441,5 @@ public interface UserVmService {
 
     VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool);
 
-    UserVm restoreVM(RestoreVMCmd cmd);
+    UserVm restoreVM(RestoreVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException;
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5aee73b1/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 48195ad..8e8352a 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -448,25 +448,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
 
         _accountMgr.checkAccess(caller, null, true, userVm);
 
-        boolean result = resetVMPasswordInternal(cmd, password);
+        boolean result = resetVMPasswordInternal(vmId, password);
 
         if (result) {
             userVm.setPassword(password);
-            // update the password in vm_details table too
-            // Check if an SSH key pair was selected for the instance and if so
-            // use it to encrypt & save the vm password
-            String sshPublicKey = userVm.getDetail("SSH.PublicKey");
-            if (sshPublicKey != null && !sshPublicKey.equals("")
-                    && password != null && !password.equals("saved_password"))
{
-                String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(
-                        sshPublicKey, password);
-                if (encryptedPasswd == null) {
-                    throw new CloudRuntimeException("Error encrypting password");
-                }
-
-                userVm.setDetail("Encrypted.Password", encryptedPasswd);
-                _vmDao.saveDetails(userVm);
-            }
+            savePasswordToDB(userVm, password);
         } else {
             throw new CloudRuntimeException(
                     "Failed to reset password for the virtual machine ");
@@ -475,10 +461,22 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
         return userVm;
     }
 
-    private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd,
-            String password) throws ResourceUnavailableException,
-            InsufficientCapacityException {
-        Long vmId = cmd.getId();
+    private void savePasswordToDB(UserVmVO vm, String password) {
+        // update the password in vm_details table too
+        // Check if an SSH key pair was selected for the instance and if so use it to encrypt
& save the vm password
+        String sshPublicKey = vm.getDetail("SSH.PublicKey");
+        if (sshPublicKey != null && !sshPublicKey.equals("") && password
!= null && !password.equals("saved_password")) {
+            String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(sshPublicKey, password);
+            if (encryptedPasswd == null) {
+                throw new CloudRuntimeException("Error encrypting password");
+            }
+
+            vm.setDetail("Encrypted.Password", encryptedPasswd);
+            _vmDao.saveDetails(vm);
+        }
+    }
+
+    private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException,
InsufficientCapacityException {
         Long userId = UserContext.current().getCallerUserId();
         VMInstanceVO vmInstance = _vmDao.findById(vmId);
 
@@ -3829,20 +3827,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
                         "A valid password for this virtual machine was not provided.");
             }
 
-            // Check if an SSH key pair was selected for the instance and if so
-            // use it to encrypt & save the vm password
-            String sshPublicKey = vm.getDetail("SSH.PublicKey");
-            if (sshPublicKey != null && !sshPublicKey.equals("")
-                    && password != null && !password.equals("saved_password"))
{
-                String encryptedPasswd = RSAHelper.encryptWithSSHPublicKey(
-                        sshPublicKey, password);
-                if (encryptedPasswd == null) {
-                    throw new CloudRuntimeException("Error encrypting password");
-                }
-
-                vm.setDetail("Encrypted.Password", encryptedPasswd);
-                _vmDao.saveDetails(vm);
-            }
+            // Check if an SSH key pair was selected for the instance and if so use it to
encrypt & save the vm password
+            savePasswordToDB(vm, password);
 
             params = new HashMap<VirtualMachineProfile.Param, Object>();
             if (additionalParams != null) {
@@ -4723,7 +4709,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
     }
 
     @Override
-    public UserVm restoreVM(RestoreVMCmd cmd) {
+    public UserVm restoreVM(RestoreVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException
{
         // Input validation
         Account caller = UserContext.current().getCaller();
         Long userId = UserContext.current().getCallerUserId();
@@ -4808,6 +4794,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Use
                     + ", user may manually delete it", e);
         }
 
+        if (template.getEnablePassword()) {
+            String password = generateRandomPassword();
+            boolean result = resetVMPasswordInternal(vmId, password);
+
+            if (result) {
+                vm.setPassword(password);
+                _vmDao.loadDetails(vm);
+                savePasswordToDB(vm, password);
+            } else {
+                s_logger.debug("Failed to reset password when restore the virtual machine
" + vmId + ", user need to reset the password later");
+            }
+        }
+
         if (needRestart) {
             try {
                 _itMgr.start(vm, null, user, caller);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5aee73b1/server/test/com/cloud/vm/MockUserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/MockUserVmManagerImpl.java b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
index 1ee627f..327f7fb 100644
--- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java
+++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java
@@ -431,7 +431,7 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager,
     }
 
     @Override
-    public UserVm restoreVM(RestoreVMCmd cmd) {
+    public UserVm restoreVM(RestoreVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException
{
         // TODO Auto-generated method stub
         return null;
     }


Mime
View raw message