diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index c1e1eedffb1..4d5d560f08e 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2756,25 +2756,25 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public String getVolumePath(final Connect conn, final DiskTO volume, boolean diskOnHostCache) throws LibvirtException, URISyntaxException { final DataTO data = volume.getData(); final DataStoreTO store = data.getDataStore(); + final String dataPath = data.getPath(); - if (volume.getType() == Volume.Type.ISO && data.getPath() != null && (store instanceof NfsTO || - store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload())) { - - if (data.getPath().startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) { - String configDrivePath = getConfigPath() + "/" + data.getPath(); - return configDrivePath; + if (volume.getType() == Volume.Type.ISO && dataPath != null) { + if (dataPath.startsWith(ConfigDrive.CONFIGDRIVEDIR) && diskOnHostCache) { + return getConfigPath() + "/" + data.getPath(); } - final String isoPath = store.getUrl().split("\\?")[0] + File.separator + data.getPath(); - final int index = isoPath.lastIndexOf("/"); - final String path = isoPath.substring(0, index); - final String name = isoPath.substring(index + 1); - final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path); - final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); - return isoVol.getPath(); - } else { - return data.getPath(); + if (store instanceof NfsTO || store instanceof PrimaryDataStoreTO && data instanceof TemplateObjectTO && !((TemplateObjectTO) data).isDirectDownload()) { + final String isoPath = store.getUrl().split("\\?")[0] + File.separator + dataPath; + final int index = isoPath.lastIndexOf("/"); + final String path = isoPath.substring(0, index); + final String name = isoPath.substring(index + 1); + final KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(path); + final KVMPhysicalDisk isoVol = secondaryPool.getPhysicalDisk(name); + return isoVol.getPath(); + } } + + return dataPath; } public void createVbd(final Connect conn, final VirtualMachineTO vmSpec, final String vmName, final LibvirtVMDef vm) throws InternalErrorException, LibvirtException, URISyntaxException { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java index 21552bd6a82..cdb9b384b03 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java @@ -153,7 +153,7 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper configKey = null; Optional optionalValue; - final ConfigKey configKey = _configDepot.get(name); - if (configKey == null) { - s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface"); - throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); + String defaultValue; + String category; + String configScope; + final ConfigurationVO config = _configDao.findByName(name); + if (config == null) { + configKey = _configDepot.get(name); + if (configKey == null) { + s_logger.warn("Probably the component manager where configuration variable " + name + " is defined needs to implement Configurable interface"); + throw new InvalidParameterValueException("Config parameter with name " + name + " doesn't exist"); + } + defaultValue = configKey.defaultValue(); + category = configKey.category(); + configScope = configKey.scope().toString(); + } else { + defaultValue = config.getDefaultValue(); + category = config.getCategory(); + configScope = config.getScope(); } - String defaultValue = configKey.defaultValue(); - String category = configKey.category(); - String configScope = configKey.scope().toString(); String scope = ""; Map scopeMap = new LinkedHashMap<>(); @@ -971,7 +982,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("unable to find zone by id " + id); } _dcDetailsDao.removeDetail(id, name); - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -981,13 +992,13 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("unable to find cluster by id " + id); } ClusterDetailsVO clusterDetailsVO = _clusterDetailsDao.findDetail(id, name); - newValue = configKey.value().toString(); + newValue = configKey != null ? configKey.value().toString() : config.getValue(); if (name.equalsIgnoreCase("cpu.overprovisioning.factor") || name.equalsIgnoreCase("mem.overprovisioning.factor")) { _clusterDetailsDao.persist(id, name, newValue); } else if (clusterDetailsVO != null) { _clusterDetailsDao.remove(clusterDetailsVO.getId()); } - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id): config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -997,7 +1008,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati throw new InvalidParameterValueException("unable to find storage pool by id " + id); } _storagePoolDetailsDao.removeDetail(id, name); - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -1010,7 +1021,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (domainDetailVO != null) { _domainDetailsDao.remove(domainDetailVO.getId()); } - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -1023,7 +1034,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (accountDetailVO != null) { _accountDetailsDao.remove(accountDetailVO.getId()); } - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -1036,7 +1047,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati if (imageStoreDetailVO != null) { _imageStoreDetailsDao.remove(imageStoreDetailVO.getId()); } - optionalValue = Optional.ofNullable(configKey.valueIn(id)); + optionalValue = Optional.ofNullable(configKey != null ? configKey.valueIn(id) : config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; break; @@ -1045,7 +1056,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati s_logger.error("Failed to reset configuration option, name: " + name + ", defaultValue:" + defaultValue); throw new CloudRuntimeException("Failed to reset configuration value. Please contact Cloud Support."); } - optionalValue = Optional.ofNullable(configKey.value()); + optionalValue = Optional.ofNullable(configKey != null ? configKey.value() : config.getValue()); newValue = optionalValue.isPresent() ? optionalValue.get().toString() : defaultValue; } diff --git a/server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java b/server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java index 4f12325cc67..d08ca4ee239 100644 --- a/server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java +++ b/server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java @@ -497,7 +497,7 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle agentId = dest.getHost().getId(); } if (!VirtualMachineManager.VmConfigDriveOnPrimaryPool.valueIn(dest.getDataCenter().getId()) && - !VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId())) { + !VirtualMachineManager.VmConfigDriveForceHostCacheUse.valueIn(dest.getDataCenter().getId()) && dataStore != null) { agentId = findAgentIdForImageStore(dataStore); } return agentId; @@ -630,6 +630,10 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle private boolean deleteConfigDriveIso(final VirtualMachine vm) throws ResourceUnavailableException { Long hostId = (vm.getHostId() != null) ? vm.getHostId() : vm.getLastHostId(); Location location = getConfigDriveLocation(vm.getId()); + if (hostId == null) { + LOG.info(String.format("The VM was never booted; no config-drive ISO created for VM %s", vm.getName())); + return true; + } if (location == Location.HOST) { return deleteConfigDriveIsoOnHostCache(vm, hostId); } @@ -639,7 +643,9 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle if (location == Location.SECONDARY) { dataStore = _dataStoreMgr.getImageStoreWithFreeCapacity(vm.getDataCenterId()); - agentId = findAgentIdForImageStore(dataStore); + if (dataStore != null) { + agentId = findAgentIdForImageStore(dataStore); + } } else if (location == Location.PRIMARY) { List volumes = _volumeDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT); if (volumes != null && volumes.size() > 0) {