use of com.cloud.agent.resource.computing.LibvirtStoragePoolDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method createFileBasedStoragePool.
public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
return null;
}
File path = new File(localStoragePath);
if (!(path.canWrite() && path.canRead() && path.canExecute())) {
return null;
}
StoragePool pool = null;
try {
pool = conn.storagePoolLookupByUUIDString(uuid);
} catch (LibvirtException e) {
}
if (pool == null) {
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, null, null, localStoragePath);
try {
pool = conn.storagePoolDefineXML(spd.toString(), 0);
pool.create(0);
} catch (LibvirtException e) {
if (pool != null) {
try {
pool.destroy();
pool.undefine();
} catch (LibvirtException e1) {
}
pool = null;
}
throw new CloudRuntimeException(e.toString());
}
}
try {
StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
}
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
return pool;
}
use of com.cloud.agent.resource.computing.LibvirtStoragePoolDef 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.agent.resource.computing.LibvirtStoragePoolDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method createNfsStoragePool.
private StoragePool createNfsStoragePool(Connect conn, String uuid, String host, String path) {
String targetPath = _mountPoint + File.separator + uuid;
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.NETFS, uuid, uuid, host, path, targetPath);
_storageLayer.mkdir(targetPath);
StoragePool sp = null;
try {
s_logger.debug(spd.toString());
sp = conn.storagePoolDefineXML(spd.toString(), 0);
sp.create(0);
return sp;
} catch (LibvirtException e) {
s_logger.debug(e.toString());
if (sp != null) {
try {
sp.undefine();
sp.free();
} catch (LibvirtException l) {
s_logger.debug("Failed to define nfs storage pool with: " + l.toString());
}
}
return null;
}
}
use of com.cloud.agent.resource.computing.LibvirtStoragePoolDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method CreateSharedStoragePool.
private StoragePool CreateSharedStoragePool(Connect conn, String uuid, String host, String path) {
String mountPoint = path;
if (!_storageLayer.exists(mountPoint)) {
return null;
}
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid, host, path, path);
StoragePool sp = null;
try {
s_logger.debug(spd.toString());
sp = conn.storagePoolDefineXML(spd.toString(), 0);
sp.create(0);
return sp;
} catch (LibvirtException e) {
s_logger.debug(e.toString());
if (sp != null) {
try {
sp.undefine();
sp.free();
} catch (LibvirtException l) {
s_logger.debug("Failed to define shared mount point storage pool with: " + l.toString());
}
}
return null;
}
}
use of com.cloud.agent.resource.computing.LibvirtStoragePoolDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtStorageAdaptor method createStoragePool.
@Override
public KVMStoragePool createStoragePool(String name, String host, String path, StoragePoolType type) {
StoragePool sp = null;
Connect conn = null;
try {
conn = LibvirtConnection.getConnection();
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
try {
sp = conn.storagePoolLookupByUUIDString(name);
if (sp.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
sp.undefine();
sp = null;
}
} catch (LibvirtException e) {
}
if (sp == null) {
if (type == StoragePoolType.NetworkFilesystem) {
sp = createNfsStoragePool(conn, name, host, path);
} else if (type == StoragePoolType.SharedMountPoint || type == StoragePoolType.Filesystem) {
sp = CreateSharedStoragePool(conn, name, host, path);
}
}
try {
StoragePoolInfo spi = sp.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
sp.create(0);
}
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, sp);
LibvirtStoragePool pool = new LibvirtStoragePool(name, sp.getName(), type, this, sp);
pool.setLocalPath(spd.getTargetPath());
getStats(pool);
return pool;
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
Aggregations