cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject git commit: updated refs/heads/master to 0069037
Date Fri, 18 Jul 2014 09:08:24 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 733a7ba8c -> 006903757


CLOUDSTACK-7113: Ability to reset password when Router VM is stopped
With this improvement password reset also happens when router is in stopped state on resetPasswordCmd
and restoreVM


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

Branch: refs/heads/master
Commit: 0069037573247e2cbe545e8d01d609040444e453
Parents: 733a7ba
Author: Harikrishna Patnala <harikrishna.patnala@citrix.com>
Authored: Wed Jul 16 15:33:13 2014 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Fri Jul 18 14:37:44 2014 +0530

----------------------------------------------------------------------
 .../network/element/VirtualRouterElement.java   | 20 ++++++++++-
 server/src/com/cloud/vm/UserVmManagerImpl.java  | 35 ++++++++++++++++++--
 2 files changed, 51 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00690375/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index 3fcf578..fd15ee3 100755
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -74,6 +74,7 @@ import com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy;
 import com.cloud.network.lb.LoadBalancingRulesManager;
 import com.cloud.network.router.VirtualRouter.Role;
 import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
+import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.rules.FirewallRule;
 import com.cloud.network.rules.LbStickinessMethod;
 import com.cloud.network.rules.LbStickinessMethod.StickinessMethodType;
@@ -89,6 +90,7 @@ import com.cloud.user.AccountManager;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.db.QueryBuilder;
+import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DomainRouterVO;
@@ -681,7 +683,23 @@ NetworkMigrationResponder, AggregatedCommandExecutor {
         @SuppressWarnings("unchecked")
         VirtualMachineProfile uservm = vm;
 
-        return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
+        // If any router is running then send save password command otherwise save the password
in DB
+        for (VirtualRouter router : routers) {
+            if (router.getState() == State.Running) {
+                return _routerMgr.savePasswordToRouter(network, nic, uservm, routers);
+            }
+        }
+        String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
+        String password_encrypted = DBEncryptionUtil.encrypt(password);
+        UserVmVO userVmVO = _userVmDao.findById(vm.getId());
+
+        _userVmDao.loadDetails(userVmVO);
+        userVmVO.setDetail("password", password_encrypted);
+        _userVmDao.saveDetails(userVmVO);
+
+        userVmVO.setUpdateParameters(true);
+        _userVmDao.update(userVmVO.getId(), userVmVO);
+        return true;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/00690375/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 d0bc186..2de6f86 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -261,6 +261,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.exception.ExecutionException;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.utils.net.NetUtils;
+import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.dao.InstanceGroupDao;
 import com.cloud.vm.dao.InstanceGroupVMMapDao;
@@ -3439,7 +3440,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
 
             String password = "saved_password";
             if (template.getEnablePassword()) {
-                password = generateRandomPassword();
+                if (vm.getDetail("password") != null) {
+                    password = DBEncryptionUtil.decrypt(vm.getDetail("password"));
+                 } else {
+                    password = generateRandomPassword();
+                 }
             }
 
             if (!validPassword(password)) {
@@ -3479,6 +3484,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             if (template.getEnablePassword()) {
                 vm.setPassword((String)vmParamPair.second().get(VirtualMachineProfile.Param.VmPassword));
                 vm.setUpdateParameters(false);
+                if (vm.getDetail("password") != null) {
+                    _vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId());
+                }
                 _vmDao.update(vm.getId(), vm);
             }
         }
@@ -4721,8 +4729,11 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         }
         }
 
+        Map<VirtualMachineProfile.Param, Object> params = null;
+        String password = null;
+
         if (template.getEnablePassword()) {
-            String password = generateRandomPassword();
+            password = generateRandomPassword();
             boolean result = resetVMPasswordInternal(vmId, password);
             if (result) {
                 vm.setPassword(password);
@@ -4738,7 +4749,25 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
 
         if (needRestart) {
             try {
-                _itMgr.start(vm.getUuid(), null);
+                if (vm.getDetail("password") != null) {
+                    params = new HashMap<VirtualMachineProfile.Param, Object>();
+                    params.put(VirtualMachineProfile.Param.VmPassword, password);
+                }
+                _itMgr.start(vm.getUuid(), params);
+                vm = _vmDao.findById(vmId);
+                if (template.getEnablePassword()) {
+                    // this value is not being sent to the backend; need only for api
+                    // display purposes
+                    vm.setPassword(password);
+                    if (vm.isUpdateParameters()) {
+                        vm.setUpdateParameters(false);
+                        _vmDao.loadDetails(vm);
+                        if (vm.getDetail("password") != null) {
+                            _vmDetailsDao.remove(_vmDetailsDao.findDetail(vm.getId(), "password").getId());
+                        }
+                        _vmDao.update(vm.getId(), vm);
+                    }
+                }
             } catch (Exception e) {
                 s_logger.debug("Unable to start VM " + vm.getUuid(), e);
                 CloudRuntimeException ex = new CloudRuntimeException("Unable to start VM
with specified id" + e.getMessage());


Mime
View raw message