use of org.libvirt.Secret in project cloudstack by apache.
the class LibvirtStorageAdaptor method deleteStoragePool.
@Override
public boolean deleteStoragePool(String uuid) {
s_logger.info("Attempting to remove storage pool " + uuid + " from libvirt");
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
StoragePool sp = null;
Secret s = null;
try {
sp = conn.storagePoolLookupByUUIDString(uuid);
} catch (LibvirtException e) {
s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed");
return true;
}
/*
* Some storage pools, like RBD also have 'secret' information stored in libvirt
* Destroy them if they exist
*/
try {
s = conn.secretLookupByUUIDString(uuid);
} catch (LibvirtException e) {
s_logger.info("Storage pool " + uuid + " has no corresponding secret. Not removing any secret.");
}
try {
if (sp.isPersistent() == 1) {
sp.destroy();
sp.undefine();
} else {
sp.destroy();
}
sp.free();
if (s != null) {
s.undefine();
s.free();
}
s_logger.info("Storage pool " + uuid + " was succesfully removed from libvirt.");
return true;
} catch (LibvirtException e) {
// handle ebusy error when pool is quickly destroyed
if (e.toString().contains("exit status 16")) {
String targetPath = _mountPoint + File.separator + uuid;
s_logger.error("deleteStoragePool removed pool from libvirt, but libvirt had trouble unmounting the pool. Trying umount location " + targetPath + "again in a few seconds");
String result = Script.runSimpleBashScript("sleep 5 && umount " + targetPath);
if (result == null) {
s_logger.error("Succeeded in unmounting " + targetPath);
return true;
}
s_logger.error("Failed to unmount " + targetPath);
}
throw new CloudRuntimeException(e.toString(), e);
}
}
Aggregations