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;