Skip to content

Commit 3b89e02

Browse files
author
Paul Angus
authored
Merge pull request #2705 from nuagenetworks/bugfix/CLOUDSTACK-10381
CLOUDSTACK-10381: Fix password reset / reset ssh key with ConfigDrive
2 parents e41b4ed + 68d87d8 commit 3b89e02

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

server/src/com/cloud/network/element/ConfigDriveNetworkElement.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.cloud.storage.dao.GuestOSDao;
6464
import com.cloud.storage.dao.VolumeDao;
6565
import com.cloud.utils.component.AdapterBase;
66+
import com.cloud.utils.crypt.DBEncryptionUtil;
6667
import com.cloud.utils.exception.CloudRuntimeException;
6768
import com.cloud.utils.fsm.StateListener;
6869
import com.cloud.utils.fsm.StateMachine2;
@@ -212,7 +213,14 @@ public boolean savePassword(final Network network, final NicProfile nic, final V
212213
if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) {
213214
throw new CloudRuntimeException("VM should to stopped to reset password");
214215
}
215-
return canHandle(network.getTrafficType());
216+
217+
final boolean canHandle = canHandle(network.getTrafficType());
218+
219+
if (canHandle) {
220+
storePasswordInVmDetails(vm);
221+
}
222+
223+
return canHandle;
216224
}
217225

218226
@Override
@@ -223,7 +231,14 @@ public boolean saveSSHKey(final Network network, final NicProfile nic, final Vir
223231
if (vm != null && vm.getVirtualMachine().getState().equals(VirtualMachine.State.Running)) {
224232
throw new CloudRuntimeException("VM should to stopped to reset password");
225233
}
226-
return canHandle(network.getTrafficType());
234+
235+
final boolean canHandle = canHandle(network.getTrafficType());
236+
237+
if (canHandle) {
238+
storePasswordInVmDetails(vm);
239+
}
240+
241+
return canHandle;
227242
}
228243

229244
@Override
@@ -237,6 +252,20 @@ public boolean saveUserData(final Network network, final NicProfile nic, final V
237252
return canHandle(network.getTrafficType());
238253
}
239254

255+
/**
256+
* Store password in vm details so it can be picked up during VM start.
257+
*/
258+
private void storePasswordInVmDetails(VirtualMachineProfile vm) {
259+
final String password = (String) vm.getParameter(VirtualMachineProfile.Param.VmPassword);
260+
final String password_encrypted = DBEncryptionUtil.encrypt(password);
261+
final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
262+
263+
_userVmDetailsDao.addDetail(vm.getId(), "password", password_encrypted, false);
264+
265+
userVmVO.setUpdateParameters(true);
266+
_userVmDao.update(userVmVO.getId(), userVmVO);
267+
}
268+
240269
@Override
241270
public boolean verifyServicesCombination(Set<Service> services) {
242271
return true;

0 commit comments

Comments
 (0)