use of com.cloud.agent.resource.kvm.xml.LibvirtStorageVolumeDef in project cosmic by MissionCriticalCloud.
the class LibvirtStorageAdaptor method createPhysicalDiskByLibVirt.
private KvmPhysicalDisk createPhysicalDiskByLibVirt(final String name, final KvmStoragePool pool, final PhysicalDiskFormat format, final long size) {
final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
final StoragePool virtPool = libvirtPool.getPool();
final LibvirtStorageVolumeDef.VolumeFormat libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.getFormat(format);
final String volPath;
final String volName;
final long volAllocation;
final long volCapacity;
final LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null, null);
this.logger.debug(volDef.toString());
try {
final StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
volPath = vol.getPath();
volName = vol.getName();
volAllocation = vol.getInfo().allocation;
volCapacity = vol.getInfo().capacity;
} catch (final LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
final KvmPhysicalDisk disk = new KvmPhysicalDisk(volPath, volName, pool);
disk.setFormat(format);
disk.setSize(volAllocation);
disk.setVirtualSize(volCapacity);
return disk;
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStorageVolumeDef in project cosmic by MissionCriticalCloud.
the class LibvirtMigrateWithStorageAcrossClustersCommandWrapper method execute.
@Override
public Answer execute(final MigrateWithStorageAcrossClustersCommand command, final LibvirtComputingResource libvirtComputingResource) {
final VirtualMachineTO vm = command.getVirtualMachine();
try {
final LibvirtUtilitiesHelper utilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
final Connect sourceConnection = utilitiesHelper.getConnectionByVmName(vm.getName());
final Connect destinationConnection = utilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIpAddress() + "/system");
final Domain domain = sourceConnection.domainLookupByName(vm.getName());
// VIR_DOMAIN_XML_MIGRATABLE = 8
String domainXml = domain.getXMLDesc(8);
final XPath xPath = XPathFactory.newInstance().newXPath();
final XPathExpression expression = xPath.compile("/pool/target/path");
final List<VolumeObjectTO> volumes = new ArrayList<>();
for (final Pair<VolumeTO, StorageFilerTO> entry : command.getVolumeMapping()) {
final VolumeTO volumeTO = entry.first();
final StorageFilerTO storageFilerTO = entry.second();
final StoragePool sourcePool = sourceConnection.storagePoolLookupByName(volumeTO.getPoolUuid());
final String sourcePoolXml = sourcePool.getXMLDesc(0);
final StoragePool destinationPool = destinationConnection.storagePoolLookupByName(storageFilerTO.getUuid());
final String destinationPoolXml = destinationPool.getXMLDesc(0);
final String sourcePath = expression.evaluate(new InputSource(new StringReader(sourcePoolXml)));
final String sourceLocation = sourcePath + "/" + volumeTO.getPath();
final String destinationPath = expression.evaluate(new InputSource(new StringReader(destinationPoolXml)));
final String destinationLocation = destinationPath + "/" + volumeTO.getPath();
domainXml = domainXml.replace(sourceLocation, destinationLocation);
final VolumeObjectTO volumeObjectTO = new VolumeObjectTO();
volumeObjectTO.setId(volumeTO.getId());
volumeObjectTO.setPath(volumeTO.getPath());
volumes.add(volumeObjectTO);
StorageVol storageVol = null;
try {
storageVol = destinationPool.storageVolLookupByName(volumeTO.getPath());
} catch (final LibvirtException e) {
s_logger.debug("Could not find volume " + volumeTO.getPath() + ": " + e.getMessage());
}
if (storageVol == null) {
LibvirtStorageVolumeDef volumeDef = new LibvirtStorageVolumeDef(volumeTO.getPath(), volumeTO.getSize(), LibvirtStorageVolumeDef.VolumeFormat.getFormat(volumeTO.getImageFormat().name()), null, null, volumeTO.getStorageProvisioningType());
destinationPool.storageVolCreateXML(volumeDef.toString(), 0);
}
}
// VIR_MIGRATE_LIVE = 1
// VIR_MIGRATE_UNDEFINE_SOURCE = 16
// VIR_MIGRATE_NON_SHARED_DISK = 64
domain.migrate(destinationConnection, 1 | 16 | 64, domainXml, vm.getName(), null, libvirtComputingResource.getMigrateSpeedAcrossCluster());
return new MigrateWithStorageAcrossClustersAnswer(command, volumes);
} catch (final Exception e) {
s_logger.error("Migration of vm " + vm.getName() + " with storage failed due to " + e.toString(), e);
return new MigrateWithStorageAcrossClustersAnswer(command, e);
}
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStorageVolumeDef in project cosmic by MissionCriticalCloud.
the class LibvirtStorageAdaptor method getPhysicalDisk.
@Override
public KvmPhysicalDisk getPhysicalDisk(final String volumeUuid, final KvmStoragePool pool) {
final LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
try {
final StorageVol vol = getVolume(libvirtPool.getPool(), volumeUuid);
final KvmPhysicalDisk disk;
final LibvirtStorageVolumeDef voldef = getStorageVolumeDef(vol);
disk = new KvmPhysicalDisk(vol.getPath(), vol.getName(), pool);
disk.setSize(vol.getInfo().allocation);
disk.setVirtualSize(vol.getInfo().capacity);
if (pool.getType() == StoragePoolType.RBD) {
disk.setFormat(PhysicalDiskFormat.RAW);
} else if (pool.getType() == StoragePoolType.NetworkFilesystem) {
final QemuImg qemuImg = new QemuImg(60000);
final Map<String, String> info = qemuImg.info(new QemuImgFile(disk.getPath()));
disk.setFormat(PhysicalDiskFormat.valueOf(info.get("file_format").toUpperCase()));
} else if (voldef.getFormat() == null) {
disk.setFormat(pool.getDefaultFormat());
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.QCOW2) {
disk.setFormat(PhysicalDiskFormat.QCOW2);
} else if (voldef.getFormat() == LibvirtStorageVolumeDef.VolumeFormat.RAW) {
disk.setFormat(PhysicalDiskFormat.RAW);
}
return disk;
} catch (final LibvirtException | QemuImgException e) {
this.logger.debug("Failed to get physical disk:", e);
throw new CloudRuntimeException(e.toString());
}
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStorageVolumeDef in project cosmic by MissionCriticalCloud.
the class ManagedNfsStorageAdaptor method getPhysicalDisk.
/*
* creates a disk based on the created nfs storage pool using libvirt
*/
@Override
public KvmPhysicalDisk getPhysicalDisk(final String volumeUuid, final KvmStoragePool pool) {
// now create the volume upon the given storage pool in kvm
final Connect conn;
StoragePool virtPool = null;
try {
conn = LibvirtConnection.getConnection();
virtPool = conn.storagePoolLookupByName("/" + volumeUuid);
} catch (final LibvirtException e1) {
throw new CloudRuntimeException(e1.toString());
}
LibvirtStorageVolumeDef.VolumeFormat libvirtformat = null;
long volCapacity = 0;
// check whether the volume is present on the given pool
StorageVol vol = getVolume(virtPool, volumeUuid);
try {
if (vol == null) {
libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.QCOW2;
final StoragePoolInfo poolinfo = virtPool.getInfo();
volCapacity = poolinfo.available;
final LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(volumeUuid, volCapacity, libvirtformat, null, null, null);
this.logger.debug(volDef.toString());
vol = virtPool.storageVolCreateXML(volDef.toString(), 0);
}
final KvmPhysicalDisk disk = new KvmPhysicalDisk(vol.getPath(), volumeUuid, pool);
disk.setFormat(PhysicalDiskFormat.QCOW2);
disk.setSize(vol.getInfo().allocation);
disk.setVirtualSize(vol.getInfo().capacity);
return disk;
} catch (final LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
Aggregations