use of com.cloud.storage.Storage in project cloudstack by apache.
the class LibvirtHandleConfigDriveCommandWrapper method execute.
@Override
public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtComputingResource libvirtComputingResource) {
String mountPoint = null;
try {
if (command.isCreate()) {
LOG.debug("Creating config drive: " + command.getIsoFile());
NetworkElement.Location location = NetworkElement.Location.PRIMARY;
if (command.isHostCachePreferred()) {
LOG.debug("Using the KVM host for config drive");
mountPoint = libvirtComputingResource.getConfigPath();
location = NetworkElement.Location.HOST;
} else {
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
KVMStoragePool pool = null;
String poolUuid = null;
Storage.StoragePoolType poolType = null;
DataStoreTO dataStoreTO = command.getDestStore();
if (dataStoreTO != null) {
if (dataStoreTO instanceof PrimaryDataStoreTO) {
PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
poolType = primaryDataStoreTO.getPoolType();
} else {
poolType = Storage.StoragePoolType.NetworkFilesystem;
}
poolUuid = command.getDestStore().getUuid();
pool = storagePoolMgr.getStoragePool(poolType, poolUuid);
}
if (pool == null || poolType == null) {
return new HandleConfigDriveIsoAnswer(command, "Unable to create config drive, Pool " + (poolUuid != null ? poolUuid : "") + " not found");
}
if (pool.supportsConfigDriveIso()) {
LOG.debug("Using the pool: " + poolUuid + " for config drive");
mountPoint = pool.getLocalPath();
} else if (command.getUseHostCacheOnUnsupportedPool()) {
LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host");
mountPoint = libvirtComputingResource.getConfigPath();
location = NetworkElement.Location.HOST;
} else {
LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString());
return new HandleConfigDriveIsoAnswer(command, "Config drive for KVM is not supported for pool type: " + poolType.toString());
}
}
Path isoPath = Paths.get(mountPoint, command.getIsoFile());
File isoFile = new File(mountPoint, command.getIsoFile());
if (command.getIsoData() == null) {
return new HandleConfigDriveIsoAnswer(command, "Invalid config drive ISO data received");
}
if (isoFile.exists()) {
LOG.debug("An old config drive iso already exists");
}
Files.createDirectories(isoPath.getParent());
ConfigDriveBuilder.base64StringToFile(command.getIsoData(), mountPoint, command.getIsoFile());
return new HandleConfigDriveIsoAnswer(command, location);
} else {
LOG.debug("Deleting config drive: " + command.getIsoFile());
Path configDrivePath = null;
if (command.isHostCachePreferred()) {
// Check and delete config drive in host storage if exists
mountPoint = libvirtComputingResource.getConfigPath();
configDrivePath = Paths.get(mountPoint, command.getIsoFile());
Files.deleteIfExists(configDrivePath);
} else {
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
KVMStoragePool pool = null;
DataStoreTO dataStoreTO = command.getDestStore();
if (dataStoreTO != null) {
if (dataStoreTO instanceof PrimaryDataStoreTO) {
PrimaryDataStoreTO primaryDataStoreTO = (PrimaryDataStoreTO) dataStoreTO;
Storage.StoragePoolType poolType = primaryDataStoreTO.getPoolType();
pool = storagePoolMgr.getStoragePool(poolType, command.getDestStore().getUuid());
} else {
pool = storagePoolMgr.getStoragePool(Storage.StoragePoolType.NetworkFilesystem, command.getDestStore().getUuid());
}
}
if (pool != null && pool.supportsConfigDriveIso()) {
mountPoint = pool.getLocalPath();
configDrivePath = Paths.get(mountPoint, command.getIsoFile());
Files.deleteIfExists(configDrivePath);
}
}
return new HandleConfigDriveIsoAnswer(command);
}
} catch (final IOException e) {
LOG.debug("Failed to handle config drive due to " + e.getMessage(), e);
return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.getMessage());
} catch (final CloudRuntimeException e) {
LOG.debug("Failed to handle config drive due to " + e.getMessage(), e);
return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.toString());
}
}
use of com.cloud.storage.Storage in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method setVolumeMigrationOptions.
/**
* Prepare hosts for KVM live storage migration depending on volume type by setting MigrationOptions on destination volume:
* - Linked clones (backing file on disk): Decide if template (backing file) should be copied to destination storage prior disk creation
* - Full clones (no backing file): Take snapshot of the VM prior disk creation
* Return this information
*/
protected void setVolumeMigrationOptions(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, VirtualMachineTO vmTO, Host srcHost, StoragePoolVO destStoragePool) {
if (!destStoragePool.isManaged()) {
String srcVolumeBackingFile = getVolumeBackingFile(srcVolumeInfo);
String srcPoolUuid = srcVolumeInfo.getDataStore().getUuid();
StoragePoolVO srcPool = _storagePoolDao.findById(srcVolumeInfo.getPoolId());
Storage.StoragePoolType srcPoolType = srcPool.getPoolType();
MigrationOptions migrationOptions;
if (StringUtils.isNotBlank(srcVolumeBackingFile)) {
migrationOptions = createLinkedCloneMigrationOptions(srcVolumeInfo, destVolumeInfo, srcVolumeBackingFile, srcPoolUuid, srcPoolType);
} else {
migrationOptions = createFullCloneMigrationOptions(srcVolumeInfo, vmTO, srcHost, srcPoolUuid, srcPoolType);
}
migrationOptions.setTimeout(StorageManager.KvmStorageOnlineMigrationWait.value());
destVolumeInfo.setMigrationOptions(migrationOptions);
}
}
use of com.cloud.storage.Storage in project cloudstack by apache.
the class LibvirtCheckStorageAvailabilityWrapper method execute.
@Override
public Answer execute(CheckStorageAvailabilityCommand command, LibvirtComputingResource resource) {
KVMStoragePoolManager storagePoolMgr = resource.getStoragePoolMgr();
Map<String, Storage.StoragePoolType> poolsMap = command.getPoolsMap();
for (String poolUuid : poolsMap.keySet()) {
Storage.StoragePoolType type = poolsMap.get(poolUuid);
s_logger.debug("Checking if storage pool " + poolUuid + " (" + type + ") is mounted on this host");
try {
KVMStoragePool storagePool = storagePoolMgr.getStoragePool(type, poolUuid);
if (storagePool == null) {
s_logger.info("Storage pool " + poolUuid + " is not available");
return new Answer(command, false, "Storage pool " + poolUuid + " not available");
}
} catch (CloudRuntimeException e) {
s_logger.info("Storage pool " + poolUuid + " is not available");
return new Answer(command, e);
}
}
return new Answer(command);
}
Aggregations