String[] poolnames = conn.listStoragePools();
for (String poolname : poolnames) {
s_logger.debug("Checking path of existing pool " + poolname
+ " against pool we want to create");
StoragePool p = conn.storagePoolLookupByName(poolname);
LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p);
String targetPath = pdef.getTargetPath();
if (targetPath != null && targetPath.equals(path)) {
s_logger.debug("Storage pool utilizing path '" + path + "' already exists as pool "
+ poolname + ", undefining so we can re-define with correct name " + name);
if (p.isPersistent() == 1) {
p.destroy();
p.undefine();
} else {
p.destroy();
}
}
}
} catch (LibvirtException e) {
s_logger.error("Failure in attempting to see if an existing storage pool might "
+ "be using the path of the pool to be created:" + e);
}
s_logger.debug("Attempting to create storage pool " + name);
if (type == StoragePoolType.NetworkFilesystem) {
try {
sp = createNfsStoragePool(conn, name, host, path);
} catch (LibvirtException e) {
s_logger.error("Failed to create mount");
s_logger.error(e.getStackTrace());
throw new CloudRuntimeException(e.toString());
}
} else if (type == StoragePoolType.SharedMountPoint
|| type == StoragePoolType.Filesystem) {
sp = createSharedStoragePool(conn, name, host, path);
} else if (type == StoragePoolType.RBD) {
sp = createRBDStoragePool(conn, name, host, port, userInfo, path);
} else if (type == StoragePoolType.CLVM) {
sp = createCLVMStoragePool(conn, name, host, path);
}
}
try {
if (sp.isActive() == 0) {
s_logger.debug("attempting to activate pool " + name);
sp.create(0);
}
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, sp);
LibvirtStoragePool pool = new LibvirtStoragePool(name,
sp.getName(), type, this, sp);
if (pool.getType() != StoragePoolType.RBD) {
pool.setLocalPath(spd.getTargetPath());
} else {
pool.setLocalPath("");
}
pool.setCapacity(sp.getInfo().capacity);