Search in sources :

Example 6 with Secret

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);
    }
}
Also used : Secret(org.libvirt.Secret) LibvirtException(org.libvirt.LibvirtException) StoragePool(org.libvirt.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connect(org.libvirt.Connect)

Aggregations

LibvirtException (org.libvirt.LibvirtException)6 Secret (org.libvirt.Secret)6 StoragePool (org.libvirt.StoragePool)6 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Connect (org.libvirt.Connect)4 LibvirtSecretDef (com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)2