@@ -206,30 +206,37 @@ 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 ) ))
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 )))) 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
224230 @ Override
225231 public boolean saveSSHKey (Network network , NicProfile nic , VirtualMachineProfile vm , String sshPublicKey ) throws ResourceUnavailableException {
226- if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (vm , sshPublicKey ))) return false ;
232+ if (!(canHandle (network .getTrafficType ()) && updateConfigDrive (vm , sshPublicKey , nic ))) return false ;
227233 return updateConfigDriveIso (network , vm , true );
228234 }
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 )))) 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
@@ -330,7 +337,7 @@ private boolean updateConfigDriveIso(Network network, VirtualMachineProfile prof
330337 Answer createIsoAnswer = endpoint .sendMessage (configDriveIsoCommand );
331338 if (!createIsoAnswer .getResult ()) {
332339 throw new ResourceUnavailableException (String .format ("%s ISO failed, details: %s" ,
333- (update ?"Update" :"Create" ), createIsoAnswer .getDetails ()),ConfigDriveNetworkElement .class ,0L );
340+ (update ?"Update" :"Create" ), createIsoAnswer .getDetails ()), ConfigDriveNetworkElement .class , 0L );
334341 }
335342 configureConfigDriveDisk (profile , secondaryStore );
336343
@@ -363,7 +370,7 @@ private void configureConfigDriveDisk(VirtualMachineProfile profile, DataStore s
363370 }
364371 }
365372
366- private boolean updateConfigDrive (VirtualMachineProfile profile , String publicKey ) {
373+ private boolean updateConfigDrive (VirtualMachineProfile profile , String publicKey , NicProfile nic ) {
367374 UserVmVO vm = _userVmDao .findById (profile .getId ());
368375 if (vm .getType () != VirtualMachine .Type .User ) {
369376 return false ;
@@ -372,11 +379,10 @@ private boolean updateConfigDrive(VirtualMachineProfile profile, String publicKe
372379 Nic defaultNic = _networkModel .getDefaultNic (vm .getId ());
373380 if (defaultNic != null ) {
374381 final String serviceOffering = _serviceOfferingDao .findByIdIncludingRemoved (vm .getId (), vm .getServiceOfferingId ()).getDisplayText ();
375- final String zoneName = _dcDao .findById (vm .getDataCenterId ()).getName ();
376382 boolean isWindows = _guestOSCategoryDao .findById (_guestOSDao .findById (vm .getGuestOSId ()).getCategoryId ()).getName ().equalsIgnoreCase ("Windows" );
377383
378- List <String []> vmData = _networkModel .generateVmData (vm .getUserData (), serviceOffering , zoneName , vm .getInstanceName (), vm .getId (),
379- publicKey , (String ) profile .getParameter (VirtualMachineProfile .Param .VmPassword ), isWindows );
384+ List <String []> vmData = _networkModel .generateVmData (vm .getUserData (), serviceOffering , vm . getDataCenterId () , vm .getInstanceName (), vm .getId (),
385+ vm . getUuid (), nic . getIPv4Address (), publicKey , (String ) profile .getParameter (VirtualMachineProfile .Param .VmPassword ), isWindows );
380386 profile .setVmData (vmData );
381387 profile .setConfigDriveLabel (VirtualMachineManager .VmConfigDriveLabel .value ());
382388 }
0 commit comments