|
38 | 38 | import javax.inject.Inject; |
39 | 39 | import javax.naming.ConfigurationException; |
40 | 40 |
|
| 41 | +import com.cloud.agent.api.AttachOrDettachConfigDriveCommand; |
41 | 42 | import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; |
42 | 43 | import org.apache.cloudstack.context.CallContext; |
43 | 44 | import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; |
@@ -273,6 +274,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac |
273 | 274 | protected VGPUTypesDao _vgpuTypesDao; |
274 | 275 | @Inject |
275 | 276 | protected EntityManager _entityMgr; |
| 277 | + @Inject |
| 278 | + protected GuestOSCategoryDao _guestOSCategoryDao; |
| 279 | + @Inject |
| 280 | + protected GuestOSDao _guestOSDao = null; |
| 281 | + @Inject |
| 282 | + protected UserVmDetailsDao _vmDetailsDao; |
| 283 | + @Inject |
| 284 | + ServiceOfferingDao _serviceOfferingDao = null; |
276 | 285 |
|
277 | 286 | @Inject |
278 | 287 | ConfigDepot _configDepot; |
@@ -315,6 +324,8 @@ public void setHostAllocators(final List<HostAllocator> hostAllocators) { |
315 | 324 | protected VmWorkJobDao _workJobDao; |
316 | 325 | @Inject |
317 | 326 | protected AsyncJobManager _jobMgr; |
| 327 | + @Inject |
| 328 | + protected UserVmService _userVmSrv; |
318 | 329 |
|
319 | 330 | VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this); |
320 | 331 |
|
@@ -352,6 +363,9 @@ public void setHostAllocators(final List<HostAllocator> hostAllocators) { |
352 | 363 | Integer.class, "vm.job.report.interval", "60", |
353 | 364 | "Interval to send application level pings to make sure the connection is still working", false); |
354 | 365 |
|
| 366 | + static final ConfigKey<String> VmConfigDriveLabel = new ConfigKey<String>("Hidden", String.class, "vm.configdrive.label", "config", |
| 367 | + "The default lable name for the config drive", false); |
| 368 | + |
355 | 369 | ScheduledExecutorService _executor = null; |
356 | 370 |
|
357 | 371 | protected long _nodeId; |
@@ -1916,6 +1930,7 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy |
1916 | 1930 | final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()), null, null); |
1917 | 1931 | _networkMgr.prepareNicForMigration(profile, dest); |
1918 | 1932 | volumeMgr.prepareForMigration(profile, dest); |
| 1933 | + profile.setConfigDriveLabel( _userVmSrv.VmConfigDriveLabel.value()); |
1919 | 1934 |
|
1920 | 1935 | final VirtualMachineTO to = toVmTO(profile); |
1921 | 1936 | final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(to); |
@@ -2215,6 +2230,48 @@ private void orchestrateMigrateWithStorage(final String vmUuid, final long srcHo |
2215 | 2230 |
|
2216 | 2231 | boolean migrated = false; |
2217 | 2232 | try { |
| 2233 | + |
| 2234 | + // config drive: Detach the config drive at source host |
| 2235 | + // After migration successful attach the config drive in destination host |
| 2236 | + // On migration failure VM will be stopped, So configIso will be deleted |
| 2237 | + |
| 2238 | + Nic defaultNic = _networkModel.getDefaultNic(vm.getId()); |
| 2239 | + |
| 2240 | + List<String[]> vmData = null; |
| 2241 | + if (defaultNic != null) { |
| 2242 | + UserVmVO userVm = _userVmDao.findById(vm.getId()); |
| 2243 | + Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId()); |
| 2244 | + vm.setDetails(details); |
| 2245 | + |
| 2246 | + Network network = _networkModel.getNetwork(defaultNic.getNetworkId()); |
| 2247 | + if (_networkModel.isSharedNetworkWithoutServices(network.getId())) { |
| 2248 | + final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText(); |
| 2249 | + final String zoneName = _dcDao.findById(vm.getDataCenterId()).getName(); |
| 2250 | + boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows"); |
| 2251 | + |
| 2252 | + vmData = _networkModel.generateVmData(userVm.getUserData(), serviceOffering, zoneName, vm.getInstanceName(), vm.getId(), |
| 2253 | + (String) profile.getParameter(VirtualMachineProfile.Param.VmSshPubKey), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows); |
| 2254 | + String vmName = vm.getInstanceName(); |
| 2255 | + String configDriveIsoRootFolder = "/tmp"; |
| 2256 | + String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso"; |
| 2257 | + profile.setVmData(vmData); |
| 2258 | + profile.setConfigDriveLabel(VmConfigDriveLabel.value()); |
| 2259 | + profile.setConfigDriveIsoRootFolder(configDriveIsoRootFolder); |
| 2260 | + profile.setConfigDriveIsoFile(isoFile); |
| 2261 | + |
| 2262 | + // At source host detach the config drive iso. |
| 2263 | + AttachOrDettachConfigDriveCommand dettachCommand = new AttachOrDettachConfigDriveCommand(vm.getInstanceName(), vmData, VmConfigDriveLabel.value(), false); |
| 2264 | + try { |
| 2265 | + _agentMgr.send(srcHost.getId(), dettachCommand); |
| 2266 | + s_logger.debug("Deleted config drive ISO for vm " + vm.getInstanceName() + " In host " + srcHost); |
| 2267 | + } catch (OperationTimedoutException e) { |
| 2268 | + s_logger.debug("TIme out occured while exeuting command AttachOrDettachConfigDrive " + e.getMessage()); |
| 2269 | + |
| 2270 | + } |
| 2271 | + |
| 2272 | + } |
| 2273 | + } |
| 2274 | + |
2218 | 2275 | // Migrate the vm and its volume. |
2219 | 2276 | volumeMgr.migrateVolumes(vm, to, srcHost, destHost, volumeToPoolMap); |
2220 | 2277 |
|
@@ -3614,7 +3671,7 @@ public String getConfigComponentName() { |
3614 | 3671 | public ConfigKey<?>[] getConfigKeys() { |
3615 | 3672 | return new ConfigKey<?>[] {ClusterDeltaSyncInterval, StartRetry, VmDestroyForcestop, VmOpCancelInterval, VmOpCleanupInterval, VmOpCleanupWait, |
3616 | 3673 | VmOpLockStateRetry, |
3617 | | - VmOpWaitInterval, ExecuteInSequence, VmJobCheckInterval, VmJobTimeout, VmJobStateReportInterval}; |
| 3674 | + VmOpWaitInterval, ExecuteInSequence, VmJobCheckInterval, VmJobTimeout, VmJobStateReportInterval, VmConfigDriveLabel}; |
3618 | 3675 | } |
3619 | 3676 |
|
3620 | 3677 | public List<StoragePoolAllocator> getStoragePoolAllocators() { |
|
0 commit comments