Search in sources :

Example 1 with LibvirtSecretDef

use of com.cloud.agent.resource.kvm.xml.LibvirtSecretDef in project cosmic by MissionCriticalCloud.

the class LibvirtSecretDefTest method testVolumeSecretDef.

public void testVolumeSecretDef() {
    final String uuid = "db66f42b-a79e-4666-9910-9dfc8a024427";
    final String name = "myEncryptedQCOW2";
    final Usage use = Usage.VOLUME;
    final LibvirtSecretDef def = new LibvirtSecretDef(use, uuid);
    def.setVolumeVolume(name);
    final String expectedXml = "<secret ephemeral='no' private='no'>\n<uuid>" + uuid + "</uuid>\n" + "<usage type='" + use.toString() + "'>\n<volume>" + name + "</volume>\n</usage>\n</secret>\n";
    assertEquals(expectedXml, def.toString());
}
Also used : Usage(com.cloud.agent.resource.kvm.xml.LibvirtSecretDef.Usage) LibvirtSecretDef(com.cloud.agent.resource.kvm.xml.LibvirtSecretDef)

Example 2 with LibvirtSecretDef

use of com.cloud.agent.resource.kvm.xml.LibvirtSecretDef in project cosmic by MissionCriticalCloud.

the class LibvirtSecretDefTest method testCephSecretDef.

public void testCephSecretDef() {
    final String uuid = "a9febe83-ac5c-467a-bf19-eb75325ec23c";
    final String name = "admin";
    final Usage use = Usage.CEPH;
    final LibvirtSecretDef def = new LibvirtSecretDef(use, uuid);
    def.setCephName(name);
    final String expectedXml = "<secret ephemeral='no' private='no'>\n<uuid>" + uuid + "</uuid>\n" + "<usage type='" + use.toString() + "'>\n<name>" + name + "</name>\n</usage>\n</secret>\n";
    assertEquals(expectedXml, def.toString());
}
Also used : Usage(com.cloud.agent.resource.kvm.xml.LibvirtSecretDef.Usage) LibvirtSecretDef(com.cloud.agent.resource.kvm.xml.LibvirtSecretDef)

Example 3 with LibvirtSecretDef

use of com.cloud.agent.resource.kvm.xml.LibvirtSecretDef in project cosmic by MissionCriticalCloud.

the class LibvirtStorageAdaptor method createRbdStoragePool.

private StoragePool createRbdStoragePool(final Connect conn, final String uuid, final String host, final int port, final String userInfo, final String path) {
    final LibvirtStoragePoolDef storagePoolDefinition;
    final StoragePool storagePool;
    Secret secretString = null;
    final String[] userInfoTemp = userInfo.split(":");
    if (userInfoTemp.length == 2) {
        final LibvirtSecretDef sd = new LibvirtSecretDef(Usage.CEPH, uuid);
        sd.setCephName(userInfoTemp[0] + "@" + host + ":" + port + "/" + path);
        try {
            this.logger.debug(sd.toString());
            secretString = conn.secretDefineXML(sd.toString());
            secretString.setValue(Base64.decodeBase64(userInfoTemp[1]));
        } catch (final LibvirtException e) {
            this.logger.error("Failed to define the libvirt secret: " + e.toString());
            if (secretString != null) {
                try {
                    secretString.undefine();
                    secretString.free();
                } catch (final LibvirtException l) {
                    this.logger.error("Failed to undefine the libvirt secret: " + l.toString());
                }
            }
            return null;
        }
        storagePoolDefinition = new LibvirtStoragePoolDef(PoolType.RBD, uuid, uuid, host, port, path, userInfoTemp[0], AuthenticationType.CEPH, uuid);
    } else {
        storagePoolDefinition = new LibvirtStoragePoolDef(PoolType.RBD, uuid, uuid, host, port, path, "");
    }
    try {
        this.logger.debug(storagePoolDefinition.toString());
        storagePool = conn.storagePoolCreateXML(storagePoolDefinition.toString(), 0);
        return storagePool;
    } catch (final LibvirtException e) {
        this.logger.error("Failed to create RBD storage pool: " + e.toString());
        if (secretString != null) {
            try {
                this.logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret");
                secretString.undefine();
                secretString.free();
            } catch (final LibvirtException se) {
                this.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.agent.resource.kvm.xml.LibvirtStoragePoolDef) LibvirtSecretDef(com.cloud.agent.resource.kvm.xml.LibvirtSecretDef)

Aggregations

LibvirtSecretDef (com.cloud.agent.resource.kvm.xml.LibvirtSecretDef)3 Usage (com.cloud.agent.resource.kvm.xml.LibvirtSecretDef.Usage)2 LibvirtStoragePoolDef (com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef)1 LibvirtException (org.libvirt.LibvirtException)1 Secret (org.libvirt.Secret)1 StoragePool (org.libvirt.StoragePool)1