Search in sources :

Example 1 with LibvirtSecretDef

use of com.cloud.hypervisor.kvm.resource.LibvirtSecretDef in project cloudstack by apache.

the class LibvirtStorageAdaptor method createRBDStoragePool.

private StoragePool createRBDStoragePool(Connect conn, String uuid, String host, int port, String userInfo, String path) {
    LibvirtStoragePoolDef spd;
    StoragePool sp = null;
    Secret s = null;
    String[] userInfoTemp = userInfo.split(":");
    if (userInfoTemp.length == 2) {
        LibvirtSecretDef sd = new LibvirtSecretDef(Usage.CEPH, uuid);
        sd.setCephName(userInfoTemp[0] + "@" + host + ":" + port + "/" + path);
        try {
            s_logger.debug(sd.toString());
            s = conn.secretDefineXML(sd.toString());
            s.setValue(Base64.decodeBase64(userInfoTemp[1]));
        } catch (LibvirtException e) {
            s_logger.error("Failed to define the libvirt secret: " + e.toString());
            if (s != null) {
                try {
                    s.undefine();
                    s.free();
                } catch (LibvirtException l) {
                    s_logger.error("Failed to undefine the libvirt secret: " + l.toString());
                }
            }
            return null;
        }
        spd = new LibvirtStoragePoolDef(PoolType.RBD, uuid, uuid, host, port, path, userInfoTemp[0], AuthenticationType.CEPH, uuid);
    } else {
        spd = new LibvirtStoragePoolDef(PoolType.RBD, uuid, uuid, host, port, path, "");
    }
    try {
        s_logger.debug(spd.toString());
        sp = conn.storagePoolCreateXML(spd.toString(), 0);
        return sp;
    } catch (LibvirtException e) {
        s_logger.error("Failed to create RBD storage pool: " + e.toString());
        if (sp != null) {
            try {
                if (sp.isPersistent() == 1) {
                    sp.destroy();
                    sp.undefine();
                } else {
                    sp.destroy();
                }
                sp.free();
            } catch (LibvirtException l) {
                s_logger.error("Failed to undefine RBD storage pool: " + l.toString());
            }
        }
        if (s != null) {
            try {
                s_logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret");
                s.undefine();
                s.free();
            } catch (LibvirtException se) {
                s_logger.error("Failed to remove the libvirt secret: " + se.toString());
            }
        }
        return null;
    }
}
Also used : Secret(org.libvirt.Secret) StoragePool(org.libvirt.StoragePool) LibvirtException(org.libvirt.LibvirtException) LibvirtStoragePoolDef(com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef) LibvirtSecretDef(com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)

Aggregations

LibvirtSecretDef (com.cloud.hypervisor.kvm.resource.LibvirtSecretDef)1 LibvirtStoragePoolDef (com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef)1 LibvirtException (org.libvirt.LibvirtException)1 Secret (org.libvirt.Secret)1 StoragePool (org.libvirt.StoragePool)1