Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8842610281 for ; Fri, 3 May 2013 17:11:32 +0000 (UTC) Received: (qmail 82193 invoked by uid 500); 3 May 2013 17:11:30 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 82141 invoked by uid 500); 3 May 2013 17:11:30 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 81944 invoked by uid 99); 3 May 2013 17:11:30 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 May 2013 17:11:30 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 28BDC886340; Fri, 3 May 2013 17:11:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sateesh@apache.org To: commits@cloudstack.apache.org Date: Fri, 03 May 2013 17:11:34 -0000 Message-Id: <032b3a86ed3d41c987ceda4a33f6f459@git.apache.org> In-Reply-To: <1c73a6fc6fc14aac8bd15a80bb30af9e@git.apache.org> References: <1c73a6fc6fc14aac8bd15a80bb30af9e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/50] git commit: updated refs/heads/vmware-datamodel to 2acbe30 CLOUDSTACK-2180: restoreVirtualMachine returns no password if the template is password enabled New password is generated as part of restore vm(passwd enabled template) and send new password on VR Signed-off-by: Abhinandan Prateek Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1cb9bd53 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1cb9bd53 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1cb9bd53 Branch: refs/heads/vmware-datamodel Commit: 1cb9bd531f4eaaef3a99608ab77cba1851b37e42 Parents: 10b6c1c Author: Harikrishna Patnala Authored: Thu Apr 25 13:17:17 2013 +0530 Committer: Abhinandan Prateek Committed: Wed May 1 12:29:08 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/vm/UserVmService.java | 2 +- server/src/com/cloud/vm/UserVmManagerImpl.java | 32 ++++++++++++-- .../test/com/cloud/vm/MockUserVmManagerImpl.java | 2 +- server/test/com/cloud/vm/UserVmManagerTest.java | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1cb9bd53/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 7e89cd3..c8ccb67 100755 --- a/api/src/com/cloud/vm/UserVmService.java +++ b/api/src/com/cloud/vm/UserVmService.java @@ -449,7 +449,7 @@ public interface UserVmService { VirtualMachine vmStorageMigration(Long vmId, StoragePool destPool); - UserVm restoreVM(RestoreVMCmd cmd); + UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; UserVm upgradeVirtualMachine(ScaleVMCmd scaleVMCmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1cb9bd53/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 f58d6be..6179948 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -485,7 +485,7 @@ 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); @@ -512,10 +512,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use return userVm; } - private boolean resetVMPasswordInternal(ResetVMPasswordCmd cmd, + private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException, InsufficientCapacityException { - Long vmId = cmd.getId(); Long userId = UserContext.current().getCallerUserId(); VMInstanceVO vmInstance = _vmDao.findById(vmId); @@ -4078,7 +4077,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } @Override - public UserVm restoreVM(RestoreVMCmd cmd) { + public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException { // Input validation Account caller = UserContext.current().getCaller(); @@ -4096,7 +4095,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use return restoreVMInternal(caller, vm, newTemplateId); } - public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId){ + public UserVm restoreVMInternal(Account caller, UserVmVO vm, Long newTemplateId) throws InsufficientCapacityException, ResourceUnavailableException { Long userId = caller.getId(); Account owner = _accountDao.findById(vm.getAccountId()); @@ -4190,6 +4189,29 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use _volsDao.detachVolume(root.getId()); this.volumeMgr.destroyVolume(root); + if (template.getEnablePassword()) { + String password = generateRandomPassword(); + boolean result = resetVMPasswordInternal(vmId, password); + if (result) { + vm.setPassword(password); + _vmDao.loadDetails(vm); + // 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("VM reset is completed but error occurred when encrypting newly created password"); + } + vm.setDetail("Encrypted.Password", encryptedPasswd); + _vmDao.saveDetails(vm); + } + } else { + throw new CloudRuntimeException("VM reset is completed but failed to reset password for the virtual machine "); + } + } + if (needRestart) { try { _itMgr.start(vm, null, user, caller); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1cb9bd53/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 d886fd8..22bbbe8 100644 --- a/server/test/com/cloud/vm/MockUserVmManagerImpl.java +++ b/server/test/com/cloud/vm/MockUserVmManagerImpl.java @@ -401,7 +401,7 @@ public class MockUserVmManagerImpl extends ManagerBase implements UserVmManager, } @Override - public UserVm restoreVM(RestoreVMCmd cmd) { + public UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException{ // TODO Auto-generated method stub return null; } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1cb9bd53/server/test/com/cloud/vm/UserVmManagerTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vm/UserVmManagerTest.java b/server/test/com/cloud/vm/UserVmManagerTest.java index e5e2ff2..08f2a9c 100755 --- a/server/test/com/cloud/vm/UserVmManagerTest.java +++ b/server/test/com/cloud/vm/UserVmManagerTest.java @@ -121,7 +121,7 @@ public class UserVmManagerTest { // Test restoreVm when VM state not in running/stopped case @Test(expected=CloudRuntimeException.class) - public void testRestoreVMF1() throws ResourceAllocationException { + public void testRestoreVMF1() throws ResourceAllocationException, InsufficientCapacityException, ResourceUnavailableException { when(_vmDao.findById(anyLong())).thenReturn(_vmMock); when(_templateDao.findById(anyLong())).thenReturn(_templateMock);