use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.
the class LibvirtComputingResource method mapRbdDevice.
public String mapRbdDevice(final KVMPhysicalDisk disk) {
final KVMStoragePool pool = disk.getPool();
// Check if rbd image is already mapped
final String[] splitPoolImage = disk.getPath().split("/");
String device = Script.runSimpleBashScript("rbd showmapped | grep \"" + splitPoolImage[0] + "[ ]*" + splitPoolImage[1] + "\" | grep -o \"[^ ]*[ ]*$\"");
if (device == null) {
// If not mapped, map and return mapped device
Script.runSimpleBashScript("rbd map " + disk.getPath() + " --id " + pool.getAuthUserName());
device = Script.runSimpleBashScript("rbd showmapped | grep \"" + splitPoolImage[0] + "[ ]*" + splitPoolImage[1] + "\" | grep -o \"[^ ]*[ ]*$\"");
}
return device;
}
use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.
the class LibvirtComputingResource method getPhysicalDiskFromNfsStore.
private KVMPhysicalDisk getPhysicalDiskFromNfsStore(String dataStoreUrl, DataTO data) {
final String volPath = dataStoreUrl + File.separator + data.getPath();
final int index = volPath.lastIndexOf("/");
final String volDir = volPath.substring(0, index);
final String volName = volPath.substring(index + 1);
final KVMStoragePool storage = _storagePoolMgr.getStoragePoolByURI(volDir);
return storage.getPhysicalDisk(volName);
}
use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.
the class LibvirtCopyVolumeCommandWrapper method handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails.
private Answer handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(CopyVolumeCommand command, LibvirtComputingResource libvirtComputingResource) {
KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
PrimaryDataStoreTO srcPrimaryDataStore = null;
KVMStoragePool secondaryStoragePool = null;
Map<String, String> srcDetails = command.getSrcDetails();
String srcPath = srcDetails.get(DiskTO.IQN);
if (srcPath == null) {
return new CopyVolumeAnswer(command, false, "No IQN was specified", null, null);
}
try {
LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
String destVolumeName = libvirtUtilitiesHelper.generateUUIDName() + ".qcow2";
String destVolumePath = command.getVolumePath() + File.separator;
String secondaryStorageUrl = command.getSecondaryStorageURL();
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
secondaryStoragePool.createFolder(File.separator + destVolumePath);
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + File.separator + destVolumePath);
VolumeObjectTO srcVolumeObjectTO = (VolumeObjectTO) command.getSrcData();
srcPrimaryDataStore = (PrimaryDataStoreTO) srcVolumeObjectTO.getDataStore();
storagePoolMgr.connectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath, srcDetails);
KVMPhysicalDisk srcPhysicalDisk = storagePoolMgr.getPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
storagePoolMgr.copyPhysicalDisk(srcPhysicalDisk, destVolumeName, secondaryStoragePool, command.getWait() * 1000);
return new CopyVolumeAnswer(command, true, null, null, destVolumePath + destVolumeName);
} catch (final CloudRuntimeException e) {
return new CopyVolumeAnswer(command, false, e.toString(), null, null);
} finally {
try {
if (srcPrimaryDataStore != null) {
storagePoolMgr.disconnectPhysicalDisk(srcPrimaryDataStore.getPoolType(), srcPrimaryDataStore.getUuid(), srcPath);
}
} catch (Exception e) {
LOGGER.warn("Unable to disconnect from the source device.", e);
}
if (secondaryStoragePool != null) {
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
}
}
}
use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.
the class LibvirtCopyVolumeCommandWrapper method execute.
@Override
public Answer execute(final CopyVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
/**
* This method is only used for copying files from Primary Storage TO
* Secondary Storage
*
* It COULD also do it the other way around, but the code in the
* ManagementServerImpl shows that it always sets copyToSecondary to
* true
*/
Map<String, String> srcDetails = command.getSrcDetails();
if (srcDetails != null) {
return handleCopyDataFromVolumeToSecondaryStorageUsingSrcDetails(command, libvirtComputingResource);
}
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final boolean copyToSecondary = command.toSecondaryStorage();
final StorageFilerTO pool = command.getPool();
final String secondaryStorageUrl = command.getSecondaryStorageURL();
KVMStoragePool secondaryStoragePool = null;
String volumePath;
KVMStoragePool primaryPool;
try {
try {
primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid());
} catch (final CloudRuntimeException e) {
if (e.getMessage().contains("not found")) {
primaryPool = storagePoolMgr.createStoragePool(pool.getUuid(), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUserInfo(), pool.getType());
} else {
return new CopyVolumeAnswer(command, false, e.getMessage(), null, null);
}
}
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final String volumeName = libvirtUtilitiesHelper.generateUUIDName();
if (copyToSecondary) {
final String destVolumeName = volumeName + ".qcow2";
final KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(command.getVolumePath());
final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl);
secondaryStoragePool.createFolder(volumeDestPath);
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumeDestPath);
storagePoolMgr.copyPhysicalDisk(volume, destVolumeName, secondaryStoragePool, 0);
return new CopyVolumeAnswer(command, true, null, null, volumeName);
} else {
volumePath = "/volumes/" + command.getVolumeId() + File.separator;
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl + volumePath);
final KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(command.getVolumePath() + ".qcow2");
storagePoolMgr.copyPhysicalDisk(volume, volumeName, primaryPool, 0);
return new CopyVolumeAnswer(command, true, null, null, volumeName);
}
} catch (final CloudRuntimeException e) {
return new CopyVolumeAnswer(command, false, e.toString(), null, null);
} finally {
if (secondaryStoragePool != null) {
storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
}
}
}
use of com.cloud.hypervisor.kvm.storage.KVMStoragePool in project cloudstack by apache.
the class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper method execute.
@Override
public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplName = libvirtUtilitiesHelper.generateUUIDName();
final String tmplFileName = tmplName + ".qcow2";
KVMStoragePool secondaryPool = null;
KVMStoragePool snapshotPool = null;
final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
try {
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
snapshotPool = storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
secondaryPool = storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl());
final KVMPhysicalDisk snapshot = snapshotPool.getPhysicalDisk(command.getSnapshotName());
final String templatePath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
final StorageLayer storage = libvirtComputingResource.getStorage();
storage.mkdirs(templatePath);
final String tmplPath = templateInstallFolder + File.separator + tmplFileName;
final String createTmplPath = libvirtComputingResource.createTmplPath();
final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout();
final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger);
scriptCommand.add("-t", templatePath);
scriptCommand.add("-n", tmplFileName);
scriptCommand.add("-f", snapshot.getPath());
scriptCommand.execute();
final Processor qcow2Processor = libvirtUtilitiesHelper.buildQCOW2Processor(storage);
final FormatInfo info = qcow2Processor.process(templatePath, null, tmplName);
final TemplateLocation loc = libvirtUtilitiesHelper.buildTemplateLocation(storage, templatePath);
loc.create(1, true, tmplName);
loc.addFormat(info);
loc.save();
return new CreatePrivateTemplateAnswer(command, true, "", tmplPath, info.virtualSize, info.size, tmplName, info.format);
} catch (final ConfigurationException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final InternalErrorException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final IOException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} catch (final CloudRuntimeException e) {
return new CreatePrivateTemplateAnswer(command, false, e.getMessage());
} finally {
if (secondaryPool != null) {
storagePoolMgr.deleteStoragePool(secondaryPool.getType(), secondaryPool.getUuid());
}
if (snapshotPool != null) {
storagePoolMgr.deleteStoragePool(snapshotPool.getType(), snapshotPool.getUuid());
}
}
}
Aggregations