use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method getResizeScriptType.
public String getResizeScriptType(final KvmStoragePool pool, final KvmPhysicalDisk vol) {
final StoragePoolType poolType = pool.getType();
final PhysicalDiskFormat volFormat = vol.getFormat();
if (pool.getType() == StoragePoolType.CLVM && volFormat == PhysicalDiskFormat.RAW) {
return "CLVM";
} else if ((poolType == StoragePoolType.NetworkFilesystem || poolType == StoragePoolType.SharedMountPoint || poolType == StoragePoolType.Filesystem || poolType == StoragePoolType.Gluster) && volFormat == PhysicalDiskFormat.QCOW2) {
return "QCOW2";
}
throw new CloudRuntimeException("Cannot determine resize type from pool type " + pool.getType());
}
use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.
the class LibvirtStoragePoolTest method testAttributes.
public void testAttributes() {
final String uuid = "4c4fb08b-373e-4f30-a120-3aa3a43f31da";
final String name = "myfirstpool";
final StoragePoolType type = StoragePoolType.NetworkFilesystem;
final StorageAdaptor adapter = Mockito.mock(LibvirtStorageAdaptor.class);
final StoragePool storage = Mockito.mock(StoragePool.class);
final LibvirtStoragePool pool = new LibvirtStoragePool(uuid, name, type, adapter, storage);
assertEquals(pool.getCapacity(), 0);
assertEquals(pool.getUsed(), 0);
assertEquals(pool.getName(), name);
assertEquals(pool.getUuid(), uuid);
assertEquals(pool.getAvailable(), 0);
assertEquals(pool.getStoragePoolType(), type);
pool.setCapacity(2048);
pool.setUsed(1024);
pool.setAvailable(1023);
assertEquals(pool.getCapacity(), 2048);
assertEquals(pool.getUsed(), 1024);
assertEquals(pool.getAvailable(), 1023);
}
use of com.cloud.storage.Storage.StoragePoolType in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method getStoragePool.
@Override
public KVMStoragePool getStoragePool(String uuid) {
StoragePool storage = null;
try {
Connect conn = LibvirtConnection.getConnection();
storage = conn.storagePoolLookupByUUIDString(uuid);
if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
storage.create(0);
}
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage);
StoragePoolType type = null;
if (spd.getPoolType() == LibvirtStoragePoolDef.poolType.NETFS || spd.getPoolType() == LibvirtStoragePoolDef.poolType.DIR) {
type = StoragePoolType.Filesystem;
}
LibvirtStoragePool pool = new LibvirtStoragePool(uuid, storage.getName(), type, this, storage);
pool.setLocalPath(spd.getTargetPath());
getStats(pool);
return pool;
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.
the class KvmStoragePoolManager method getStoragePoolByUri.
public KvmStoragePool getStoragePoolByUri(final String uri) {
URI storageUri = null;
try {
storageUri = new URI(uri);
} catch (final URISyntaxException e) {
throw new CloudRuntimeException(e.toString());
}
String sourcePath = null;
String uuid = null;
String sourceHost = "";
StoragePoolType protocol = null;
if (storageUri.getScheme().equalsIgnoreCase("nfs")) {
sourcePath = storageUri.getPath();
sourcePath = sourcePath.replace("//", "/");
sourceHost = storageUri.getHost();
uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
protocol = StoragePoolType.NetworkFilesystem;
}
// secondary storage registers itself through here
return createStoragePool(uuid, sourceHost, 0, sourcePath, "", protocol, false);
}
use of com.cloud.storage.Storage.StoragePoolType in project cosmic by MissionCriticalCloud.
the class LibvirtStorageAdaptor method getStoragePool.
@Override
public KvmStoragePool getStoragePool(final String uuid, final boolean refreshInfo) {
logger.info("Trying to fetch storage pool " + uuid + " from libvirt");
StoragePool storage = null;
try {
final Connect conn = LibvirtConnection.getConnection();
storage = conn.storagePoolLookupByUUIDString(uuid);
if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it.");
storage.create(0);
}
final LibvirtStoragePoolDef spd = getStoragePoolDef(conn, 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.CLVM;
} 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.getSourceDir());
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) {
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);
logger.debug("Succesfully refreshed pool " + uuid + " Capacity: " + storage.getInfo().capacity + " Used: " + storage.getInfo().allocation + " Available: " + storage.getInfo().available);
return pool;
} catch (final LibvirtException e) {
logger.debug("Could not find storage pool " + uuid + " in libvirt");
throw new CloudRuntimeException(e.toString(), e);
}
}
Aggregations