@@ -206,18 +206,24 @@ public boolean canEnableIndividualServices() {
206206 return false ;
207207 }
208208
209+ private String getSshKey (VirtualMachineProfile profile ) {
210+ UserVmDetailVO vmDetailSshKey = _userVmDetailsDao .findDetail (profile .getId (), "SSH.PublicKey" );
211+ return (vmDetailSshKey !=null ? vmDetailSshKey .getValue () : null );
212+ }
213+
209214 @ Override
210215 public boolean addPasswordAndUserdata (Network network , NicProfile nic , VirtualMachineProfile profile , DeployDestination dest , ReservationContext context )
211216 throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
212- UserVmDetailVO vmDetailSshKey = _userVmDetailsDao . findDetail (profile . getId (), "SSH.PublicKey" );
213- return (canHandle (network .getTrafficType ()) && updateConfigDrive ( profile ,
214- ( vmDetailSshKey != null ? vmDetailSshKey . getValue (): null ) , nic ))
217+ String sshPublicKey = getSshKey (profile );
218+ return (canHandle (network .getTrafficType ())
219+ && updateConfigDrive ( profile , sshPublicKey , nic ))
215220 && updateConfigDriveIso (network , profile , dest .getHost (), false );
216221 }
217222
218223 @ Override
219224 public boolean savePassword (Network network , NicProfile nic , VirtualMachineProfile profile ) throws ResourceUnavailableException {
220- if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (profile , (String ) profile .getParameter (VirtualMachineProfile .Param .VmSshPubKey ), nic ))) return false ;
225+ String sshPublicKey = getSshKey (profile );
226+ if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (profile , sshPublicKey , nic ))) return false ;
221227 return updateConfigDriveIso (network , profile , true );
222228 }
223229
@@ -229,7 +235,8 @@ public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile
229235
230236 @ Override
231237 public boolean saveUserData (Network network , NicProfile nic , VirtualMachineProfile profile ) throws ResourceUnavailableException {
232- if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (profile , (String ) profile .getParameter (VirtualMachineProfile .Param .VmSshPubKey ), nic ))) return false ;
238+ String sshPublicKey = getSshKey (profile );
239+ if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (profile , sshPublicKey , nic ))) return false ;
233240 return updateConfigDriveIso (network , profile , true );
234241 }
235242
0 commit comments