KVMPhysicalDisk disk; LibvirtStorageVolumeDef voldef = getStorageVolumeDef(libvirtPool.getPool().getConnect(), vol); disk = new KVMPhysicalDisk(vol.getPath(), vol.getName(), pool); disk.setSize(vol.getInfo().allocation); disk.setVirtualSize(vol.getInfo().capacity);
private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool pool, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) { LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool; StoragePool virtPool = libvirtPool.getPool(); LibvirtStorageVolumeDef.VolumeFormat libvirtformat = LibvirtStorageVolumeDef.VolumeFormat.getFormat(format); String volPath = null; String volName = null; long volAllocation = 0; long volCapacity = 0; LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null); s_logger.debug(volDef.toString()); try { StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0); volPath = vol.getPath(); volName = vol.getName(); volAllocation = vol.getInfo().allocation; volCapacity = vol.getInfo().capacity; } catch (LibvirtException e) { throw new CloudRuntimeException(e.toString()); } KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, volName, pool); disk.setFormat(format); disk.setSize(volAllocation); disk.setVirtualSize(volCapacity); return disk; }
public String getName() { try { return volume.getName(); } catch (LibvirtException e) { throw new LibvirtRuntimeException(e); } }
private static StorageVol findVolumeInPool(StoragePool sp, String image) throws LibvirtException { for (String v : sp.listVolumes()) { StorageVol vol = sp.storageVolLookupByName(v); if (vol.getPath().equals(image)) { log.debug("Found volume '{}' for image '{}'", vol.getName(), image); return vol; } } return null; }
/** Look up a disk image's {@link StorageVol} in the {@link StoragePool}s attached to connection. */ public static StorageVol findVolume(Connect connection, String path) throws LibvirtException { log.debug("Looking up StorageVolume for path '{}'", path); for (String s : connection.listStoragePools()) { StoragePool sp = connection.storagePoolLookupByName(s); for (String v : sp.listVolumes()) { StorageVol vol = sp.storageVolLookupByName(v); if (vol.getPath().equals(path)) { log.debug("Found volume '{}' for path '{}'", vol.getName(), path); return vol; } } } throw new LibvirtRuntimeException("no volume found for path " + path); }