try {
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 = createNetfsStoragePool(poolType.NETFS, conn, name, host, path);
} catch (LibvirtException e) {
s_logger.error("Failed to create netfs mount: " + host + ":" + path , e);
s_logger.error(e.getStackTrace());
throw new CloudRuntimeException(e.toString());
}
} else if (type == StoragePoolType.Gluster) {
try {
sp = createNetfsStoragePool(poolType.GLUSTERFS, conn, name, host, path);
} catch (LibvirtException e) {
s_logger.error("Failed to create glusterfs mount: " + host + ":" + path , e);
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);
}
}
if (sp == null) {
throw new CloudRuntimeException("Failed to create storage pool: " + name);
}
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("");
}
if (pool.getType() == StoragePoolType.RBD
|| pool.getType() == StoragePoolType.Gluster) {
pool.setSourceHost(spd.getSourceHost());
pool.setSourcePort(spd.getSourcePort());
pool.setSourceDir(spd.getSourceDir());
String authUsername = spd.getAuthUserName();
if (authUsername != null) {
Secret secret = conn.secretLookupByUUIDString(spd.getSecretUUID());
String secretValue = new String(Base64.encodeBase64(secret.getByteValue()));
pool.setAuthUsername(authUsername);
pool.setAuthSecret(secretValue);
}
}