Skip to content

Commit 94c8b1d

Browse files
authored
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
1 parent 0ba2691 commit 94c8b1d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

plugins/storage/volume/storpool/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ SP_API_HTTP - address of StorPool Api
117117
SP_AUTH_TOKEN - StorPool's token
118118
SP_TEMPLATE - name of StorPool's template
119119

120+
> **NOTE:** You can use the alternative format option for the URL - storpool://{SP_AUTH_TOKEN}@{SP_API_HTTP}:{SP_API_HTTP_PORT}/{SP_TEMPLATE}
121+
120122
Storage Tags: If left blank, the StorPool storage plugin will use the pool name to create a corresponding storage tag.
121123
This storage tag may be used later, when defining service or disk offerings.
122124

plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ public static class SpConnectionDesc {
172172
private String templateName;
173173

174174
public SpConnectionDesc(String url) {
175+
try {
176+
extractUriParams(url);
177+
return;
178+
} catch (URISyntaxException e) {
179+
log.debug("[ignore] the uri is not valid");
180+
}
175181
String[] urlSplit = url.split(";");
176182
if (urlSplit.length == 1 && !urlSplit[0].contains("=")) {
177183
this.templateName = url;
@@ -240,6 +246,16 @@ public SpConnectionDesc(String url) {
240246
}
241247
}
242248

249+
private void extractUriParams(String url) throws URISyntaxException {
250+
URI uri = new URI(url);
251+
if (!StringUtils.equalsIgnoreCase(uri.getScheme(), "storpool")) {
252+
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}");
253+
}
254+
hostPort = uri.getHost() + ":" + uri.getPort();
255+
authToken = uri.getUserInfo();
256+
templateName = uri.getPath().replace("/", "");
257+
}
258+
243259
public SpConnectionDesc(String host, String authToken2, String templateName2) {
244260
this.hostPort = host;
245261
this.authToken = authToken2;

0 commit comments

Comments
 (0)