Skip to content

Commit 124d091

Browse files
committed
CLOUDSTACK-10358: SSH keys are missing on Config Drive disk in some cases
1 parent 57de75c commit 124d091

8 files changed

Lines changed: 757 additions & 1078 deletions

File tree

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,15 +2518,15 @@ private void orchestrateMigrateWithStorage(final String vmUuid, final long srcHo
25182518
if (defaultNic != null) {
25192519
UserVmVO userVm = _userVmDao.findById(vm.getId());
25202520
Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
2521-
vm.setDetails(details);
2521+
userVm.setDetails(details);
25222522

25232523
Network network = _networkModel.getNetwork(defaultNic.getNetworkId());
25242524
if (_networkModel.isSharedNetworkWithoutServices(network.getId())) {
25252525
final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
25262526
boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
25272527

25282528
vmData = _networkModel.generateVmData(userVm.getUserData(), serviceOffering, vm.getDataCenterId(), vm.getInstanceName(), vm.getId(),
2529-
vm.getUuid(), defaultNic.getMacAddress(), (String) profile.getParameter(VirtualMachineProfile.Param.VmSshPubKey), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
2529+
vm.getUuid(), defaultNic.getMacAddress(), userVm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
25302530
String vmName = vm.getInstanceName();
25312531
String configDriveIsoRootFolder = "/tmp";
25322532
String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso";

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4127,7 +4127,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
41274127
boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
41284128

41294129
List<String[]> vmData = _networkModel.generateVmData(vm.getUserData(), serviceOffering, vm.getDataCenterId(), vm.getInstanceName(), vm.getId(),
4130-
vm.getUuid(), defaultNic.getIPv4Address(), (String) profile.getParameter(VirtualMachineProfile.Param.VmSshPubKey), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
4130+
vm.getUuid(), defaultNic.getIPv4Address(), vm.getDetail("SSH.PublicKey"), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows);
41314131
String vmName = vm.getInstanceName();
41324132
String configDriveIsoRootFolder = "/tmp";
41334133
String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso";

0 commit comments

Comments
 (0)