use of com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef in project cosmic by MissionCriticalCloud.
the class LibvirtStoragePoolDefTest method testRbdStoragePool.
public void testRbdStoragePool() {
final PoolType type = PoolType.RBD;
final String name = "myRBDPool";
final String uuid = "921ef8b2-955a-4c18-a697-66bb9adf6131";
final String host = "127.0.0.1";
final String dir = "cloudstackrbdpool";
final String authUsername = "admin";
final String secretUuid = "08c2fa02-50d0-4a78-8903-b742d3f34934";
final AuthenticationType auth = AuthenticationType.CEPH;
final int port = 6789;
final LibvirtStoragePoolDef pool = new LibvirtStoragePoolDef(type, name, uuid, host, port, dir, authUsername, auth, secretUuid);
final String expectedXml = "<pool type='" + type.toString() + "'>\n<name>" + name + "</name>\n<uuid>" + uuid + "</uuid>\n" + "<source>\n<host name='" + host + "' port='" + port + "'/>\n<name>" + dir + "</name>\n" + "<auth username='" + authUsername + "' type='" + auth.toString() + "'>\n<secret uuid='" + secretUuid + "'/>\n" + "</auth>\n</source>\n</pool>\n";
assertEquals(expectedXml, pool.toString());
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef in project cosmic by MissionCriticalCloud.
the class LibvirtStoragePoolDefTest method testNfsStoragePool.
public void testNfsStoragePool() {
final PoolType type = PoolType.NETFS;
final String name = "myNFSPool";
final String uuid = "89a605bc-d470-4637-b3df-27388be452f5";
final String host = "127.0.0.1";
final String dir = "/export/primary";
final String targetPath = "/mnt/" + uuid;
final LibvirtStoragePoolDef pool = new LibvirtStoragePoolDef(type, name, uuid, host, dir, targetPath);
final String expectedXml = "<pool type='" + type.toString() + "'>\n<name>" + name + "</name>\n<uuid>" + uuid + "</uuid>\n" + "<source>\n<host name='" + host + "'/>\n<dir path='" + dir + "'/>\n</source>\n<target>\n" + "<path>" + targetPath + "</path>\n</target>\n</pool>\n";
assertEquals(expectedXml, pool.toString());
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef in project cosmic by MissionCriticalCloud.
the class LibvirtStoragePoolDefTest method testSetGetStoragePool.
public void testSetGetStoragePool() {
final PoolType type = PoolType.NETFS;
final String name = "myNFSPool";
final String uuid = "d7846cb0-f610-4a5b-8d38-ee6e8d63f37b";
final String host = "127.0.0.1";
final String dir = "/export/primary";
final String targetPath = "/mnt/" + uuid;
final int port = 1234;
final LibvirtStoragePoolDef pool = new LibvirtStoragePoolDef(type, name, uuid, host, port, dir, targetPath);
assertEquals(type, pool.getPoolType());
assertEquals(name, pool.getPoolName());
assertEquals(host, pool.getSourceHost());
assertEquals(port, pool.getSourcePort());
assertEquals(dir, pool.getSource());
assertEquals(targetPath, pool.getTargetPath());
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef in project cosmic by MissionCriticalCloud.
the class LibvirtStorageAdaptor method createClvmStoragePool.
private StoragePool createClvmStoragePool(final Connect conn, final String uuid, final String host, final String path) {
final String volgroupPath = "/dev/" + path;
String volgroupName = path;
volgroupName = volgroupName.replaceFirst("/", "");
final LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath);
try {
this.logger.debug(spd.toString());
return conn.storagePoolCreateXML(spd.toString(), 0);
} catch (final LibvirtException e) {
this.logger.error("Unable to add CLVM storage pool: ", e);
return null;
}
}
use of com.cloud.agent.resource.kvm.xml.LibvirtStoragePoolDef in project cosmic by MissionCriticalCloud.
the class LibvirtStorageAdaptor method getStoragePool.
@Override
public KvmStoragePool getStoragePool(final String uuid, final boolean refreshInfo) {
this.logger.info("Trying to fetch storage pool " + uuid + " from libvirt");
final StoragePool storage;
try {
final Connect conn = LibvirtConnection.getConnection();
storage = conn.storagePoolLookupByUUIDString(uuid);
if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
this.logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it.");
storage.create(0);
}
final LibvirtStoragePoolDef spd = getStoragePoolDef(storage);
if (spd == null) {
throw new CloudRuntimeException("Unable to parse the storage pool definition for storage pool " + uuid);
}
StoragePoolType type = null;
if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.NETFS) {
type = StoragePoolType.NetworkFilesystem;
} else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.DIR) {
type = StoragePoolType.Filesystem;
} else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.RBD) {
type = StoragePoolType.RBD;
} else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.LOGICAL) {
type = StoragePoolType.LVM;
} else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.GLUSTERFS) {
type = StoragePoolType.Gluster;
}
final LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);
if (pool.getType() != StoragePoolType.RBD) {
pool.setLocalPath(spd.getTargetPath());
} else {
pool.setLocalPath("");
}
if (pool.getType() == StoragePoolType.RBD || pool.getType() == StoragePoolType.Gluster) {
pool.setSourceHost(spd.getSourceHost());
pool.setSourcePort(spd.getSourcePort());
pool.setSourceDir(spd.getSource());
final String authUsername = spd.getAuthUsername();
if (authUsername != null) {
final Secret secret = conn.secretLookupByUUIDString(spd.getSecretUuid());
final String secretValue = new String(Base64.encodeBase64(secret.getByteValue()), Charset.defaultCharset());
pool.setAuthUsername(authUsername);
pool.setAuthSecret(secretValue);
}
}
if (refreshInfo) {
this.logger.info("Asking libvirt to refresh storage pool " + uuid);
pool.refresh();
}
pool.setCapacity(storage.getInfo().capacity);
pool.setUsed(storage.getInfo().allocation);
pool.setAvailable(storage.getInfo().available);
this.logger.debug("Succesfully refreshed pool " + uuid + " Capacity: " + storage.getInfo().capacity + " Used: " + storage.getInfo().allocation + " Available: " + storage.getInfo().available);
return pool;
} catch (final LibvirtException e) {
this.logger.debug("Could not find storage pool " + uuid + " in libvirt");
throw new CloudRuntimeException(e.toString(), e);
}
}
Aggregations