use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.
the class QemuImgFileTest method testFileNameAndFormatAtContructor.
@Test
public void testFileNameAndFormatAtContructor() {
PhysicalDiskFormat format = PhysicalDiskFormat.RAW;
String filename = "/tmp/test-image.qcow2";
QemuImgFile file = new QemuImgFile(filename, format);
assertEquals(file.getFileName(), filename);
assertEquals(file.getFormat(), format);
}
use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.
the class KVMStorageProcessor method createVolume.
@Override
public Answer createVolume(final CreateObjectCommand cmd) {
final VolumeObjectTO volume = (VolumeObjectTO) cmd.getData();
final PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
KVMStoragePool primaryPool = null;
KVMPhysicalDisk vol = null;
long disksize;
try {
primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid());
disksize = volume.getSize();
PhysicalDiskFormat format;
if (volume.getFormat() == null || StoragePoolType.RBD.equals(primaryStore.getPoolType())) {
format = primaryPool.getDefaultFormat();
} else {
format = PhysicalDiskFormat.valueOf(volume.getFormat().toString().toUpperCase());
}
MigrationOptions migrationOptions = volume.getMigrationOptions();
if (migrationOptions != null) {
String srcStoreUuid = migrationOptions.getSrcPoolUuid();
StoragePoolType srcPoolType = migrationOptions.getSrcPoolType();
KVMStoragePool srcPool = storagePoolMgr.getStoragePool(srcPoolType, srcStoreUuid);
int timeout = migrationOptions.getTimeout();
if (migrationOptions.getType() == MigrationOptions.Type.LinkedClone) {
vol = createLinkedCloneVolume(migrationOptions, srcPool, primaryPool, volume, format, timeout);
} else if (migrationOptions.getType() == MigrationOptions.Type.FullClone) {
vol = createFullCloneVolume(migrationOptions, volume, primaryPool, format);
}
} else {
vol = primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), disksize);
}
final VolumeObjectTO newVol = new VolumeObjectTO();
if (vol != null) {
newVol.setPath(vol.getName());
}
newVol.setSize(volume.getSize());
newVol.setFormat(ImageFormat.valueOf(format.toString().toUpperCase()));
return new CreateObjectAnswer(newVol);
} catch (final Exception e) {
s_logger.debug("Failed to create volume: ", e);
return new CreateObjectAnswer(e.toString());
}
}
use of org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat in project cloudstack by apache.
the class LibvirtStorageAdaptor method createDiskFromTemplateBacking.
@Override
public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout) {
String volumeDesc = String.format("volume [%s], with template backing [%s], in pool [%s] (%s), with size [%s]", name, template.getName(), destPool.getUuid(), destPool.getType(), size);
if (!poolTypesThatEnableCreateDiskFromTemplateBacking.contains(destPool.getType())) {
s_logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream().map(type -> type.toString()).collect(Collectors.joining(", "))));
return null;
}
if (format != PhysicalDiskFormat.QCOW2) {
s_logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2));
return null;
}
s_logger.info(String.format("Creating %s.", volumeDesc));
String destPoolLocalPath = destPool.getLocalPath();
String destPath = String.format("%s%s%s", destPoolLocalPath, destPoolLocalPath.endsWith("/") ? "" : "/", name);
try {
QemuImgFile destFile = new QemuImgFile(destPath, format);
destFile.setSize(size);
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
new QemuImg(timeout).create(destFile, backingFile);
} catch (QemuImgException e) {
s_logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e);
}
return null;
}
Aggregations