6363import com .cloud .storage .dao .GuestOSDao ;
6464import com .cloud .storage .dao .VolumeDao ;
6565import com .cloud .utils .component .AdapterBase ;
66+ import com .cloud .utils .crypt .DBEncryptionUtil ;
6667import com .cloud .utils .exception .CloudRuntimeException ;
6768import com .cloud .utils .fsm .StateListener ;
6869import 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