This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.19
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.19 by this push:
new 94c8b1da5ce Option to create StorPool primary storage with a valid URL
(#8356)
94c8b1da5ce is described below
commit 94c8b1da5ce0cca291f3206dad92dc5fd0bd9aa4
Author: slavkap <[email protected]>
AuthorDate: Mon Feb 5 10:51:13 2024 +0200
Option to create StorPool primary storage with a valid URL (#8356)
* Option to create primary storage with a valid URL
* check if the scheme is valid
---
plugins/storage/volume/storpool/README.md | 2 ++
.../cloudstack/storage/datastore/util/StorPoolUtil.java | 16 ++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/plugins/storage/volume/storpool/README.md
b/plugins/storage/volume/storpool/README.md
index 030abd72d1f..77522344b52 100644
--- a/plugins/storage/volume/storpool/README.md
+++ b/plugins/storage/volume/storpool/README.md
@@ -117,6 +117,8 @@ SP_API_HTTP - address of StorPool Api
SP_AUTH_TOKEN - StorPool's token
SP_TEMPLATE - name of StorPool's template
+> **NOTE:** You can use the alternative format option for the URL -
storpool://{SP_AUTH_TOKEN}@{SP_API_HTTP}:{SP_API_HTTP_PORT}/{SP_TEMPLATE}
+
Storage Tags: If left blank, the StorPool storage plugin will use the pool
name to create a corresponding storage tag.
This storage tag may be used later, when defining service or disk offerings.
diff --git
a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java
b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java
index 3a428efe5a1..e176d67c12d 100644
---
a/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java
+++
b/plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java
@@ -172,6 +172,12 @@ public class StorPoolUtil {
private String templateName;
public SpConnectionDesc(String url) {
+ try {
+ extractUriParams(url);
+ return;
+ } catch (URISyntaxException e) {
+ log.debug("[ignore] the uri is not valid");
+ }
String[] urlSplit = url.split(";");
if (urlSplit.length == 1 && !urlSplit[0].contains("=")) {
this.templateName = url;
@@ -240,6 +246,16 @@ public class StorPoolUtil {
}
}
+ private void extractUriParams(String url) throws URISyntaxException {
+ URI uri = new URI(url);
+ if (!StringUtils.equalsIgnoreCase(uri.getScheme(), "storpool")) {
+ throw new CloudRuntimeException("The scheme is invalid. The
URL should be with a format
storpool://{SP_AUTH_TOKEN}@{SP_API_HTTP}:{SP_API_HTTP_PORT}/{SP_TEMPLATE}");
+ }
+ hostPort = uri.getHost() + ":" + uri.getPort();
+ authToken = uri.getUserInfo();
+ templateName = uri.getPath().replace("/", "");
+ }
+
public SpConnectionDesc(String host, String authToken2, String
templateName2) {
this.hostPort = host;
this.authToken = authToken2;