You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2018/06/11 13:53:02 UTC
[GitHub] PaulAngus closed pull request #2705: CLOUDSTACK-10381: Fix password
reset / reset ssh key with ConfigDrive
PaulAngus closed pull request #2705: CLOUDSTACK-10381: Fix password reset / reset ssh key with ConfigDrive
URL: https://github.com/apache/cloudstack/pull/2705
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
index dab4a14311c..a304ea43fa2 100644
--- a/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
+++ b/server/src/com/cloud/network/element/ConfigDriveNetworkElement.java
@@ -63,6 +63,7 @@
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.component.AdapterBase;
+import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.StateListener;
import com.cloud.utils.fsm.StateMachine2;
@@ -212,7 +213,14 @@ public boolean savePassword(final Network network, final NicProfile nic, final V
if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) {
throw new CloudRuntimeException("VM should to stopped to reset password");
}
- return canHandle(network.getTrafficType());
+
+ final boolean canHandle = canHandle(network.getTrafficType());
+
+ if (canHandle) {
+ storePasswordInVmDetails(vm);
+ }
+
+ return canHandle;
}
@Override
@@ -223,7 +231,14 @@ public boolean saveSSHKey(final Network network, final NicProfile nic, final Vir
if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) {
throw new CloudRuntimeException("VM should to stopped to reset password");
}
- return canHandle(network.getTrafficType());
+
+ final boolean canHandle = canHandle(network.getTrafficType());
+
+ if (canHandle) {
+ storePasswordInVmDetails(vm);
+ }
+
+ return canHandle;
}
@Override
@@ -237,6 +252,20 @@ public boolean saveUserData(final Network network, final NicProfile nic, final V
return canHandle(network.getTrafficType());
}
+ /**
+ * Store password in vm details so it can be picked up during VM start.
+ */
+ private void storePasswordInVmDetails(VirtualMachineProfile vm) {
+ final String password = (String) vm.getParameter(VirtualMachineProfile.Param.VmPassword);
+ final String password_encrypted = DBEncryptionUtil.encrypt(password);
+ final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
+
+ _userVmDetailsDao.addDetail(vm.getId(), "password", password_encrypted, false);
+
+ userVmVO.setUpdateParameters(true);
+ _userVmDao.update(userVmVO.getId(), userVmVO);
+ }
+
@Override
public boolean verifyServicesCombination(Set<Service> services) {
return true;
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services