public StorageVol getVolume(StoragePool pool, String volName) { StorageVol vol = null; try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { s_logger.debug("Could not find volume " + volName + ": " + e.getMessage()); } /** * The volume was not found in the storage pool * This can happen when a volume has just been created on a different host and * since then the libvirt storage pool has not been refreshed. */ if (vol == null) { try { s_logger.debug("Refreshing storage pool " + pool.getName()); refreshPool(pool); } catch (LibvirtException e) { s_logger.debug("Failed to refresh storage pool: " + e.getMessage()); } try { vol = pool.storageVolLookupByName(volName); s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); } catch (LibvirtException e) { throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage()); } } return vol; }
protected String getMountPoint(NfsStoragePool storagePool) { StoragePool pool = null; String poolName = null; try { pool = LibvirtConnection.getConnection().storagePoolLookupByUUIDString(storagePool._poolUUID); if (pool != null) { StoragePoolInfo spi = pool.getInfo(); if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { pool.create(0); } else { /* * Sometimes, the mount point is lost, even libvirt thinks * the storage pool still running */ } poolName = pool.getName(); } } catch (LibvirtException e) { s_logger.debug("Ignoring libvirt error.", e); } finally { try { if (pool != null) { pool.free(); } } catch (LibvirtException e) { s_logger.debug("Ignoring libvirt error.", e); } } return checkingMountPoint(storagePool, poolName); }
LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);
public static StoragePool findStoragePoolWithFile(Connect conn, String path) throws LibvirtException { for (String spn : conn.listStoragePools()) { StoragePool sp = conn.storagePoolLookupByName(spn); if (findVolumeInPool(sp, path) != null) { log.debug("Found storage pool '{}' for image '{}'", sp.getName(), path); return sp; } } throw new LibvirtRuntimeException("pool with image " + path + " not found"); }