Skip to content

Commit 6becb33

Browse files
author
Daman Arora
committed
Add zoneId parameter to S3 image store commands
1 parent 71013b6 commit 6becb33

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.cloudstack.api.Parameter;
4747
import org.apache.cloudstack.api.ServerApiException;
4848
import org.apache.cloudstack.api.response.ImageStoreResponse;
49+
import org.apache.cloudstack.api.response.ZoneResponse;
4950

5051
import com.cloud.exception.ConcurrentOperationException;
5152
import com.cloud.exception.DiscoveryException;
@@ -61,6 +62,9 @@ public final class AddImageStoreS3CMD extends BaseCmd implements ClientOptions {
6162

6263
private static final String s_name = "addImageStoreS3Response";
6364

65+
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, description = "The Zone ID for the S3 image store")
66+
private Long zoneId;
67+
6468
@Parameter(name = S3_ACCESS_KEY, type = STRING, required = true, description = "S3 access key")
6569
private String accessKey;
6670

@@ -128,7 +132,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
128132
}
129133

130134
try{
131-
ImageStore result = _storageService.discoverImageStore(null, null, "S3", null, dm);
135+
ImageStore result = _storageService.discoverImageStore(null, null, "S3", zoneId, dm);
132136
ImageStoreResponse storeResponse;
133137
if (result != null) {
134138
storeResponse = _responseGenerator.createImageStoreResponse(result);

plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/S3ImageStoreLifeCycleImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public S3ImageStoreLifeCycleImpl() {
7272
@Override
7373
public DataStore initialize(Map<String, Object> dsInfos) {
7474

75+
Long dcId = (Long)dsInfos.get("zoneId");
7576
String url = (String)dsInfos.get("url");
7677
String name = (String)dsInfos.get("name");
7778
String providerName = (String)dsInfos.get("providerName");
@@ -83,6 +84,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
8384

8485
Map<String, Object> imageStoreParameters = new HashMap();
8586
imageStoreParameters.put("name", name);
87+
imageStoreParameters.put("zoneId", dcId);
8688
imageStoreParameters.put("url", url);
8789
String protocol = "http";
8890
String useHttps = details.get(ApiConstants.S3_HTTPS_FLAG);
@@ -93,7 +95,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
9395
if (scope != null) {
9496
imageStoreParameters.put("scope", scope);
9597
} else {
96-
imageStoreParameters.put("scope", ScopeType.REGION);
98+
imageStoreParameters.put("scope", ScopeType.ZONE);
9799
}
98100
imageStoreParameters.put("providerName", providerName);
99101
imageStoreParameters.put("role", role);

plugins/storage/image/s3/src/main/java/org/apache/cloudstack/storage/datastore/provider/S3ImageStoreProviderImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public Set<DataStoreProviderType> getTypes() {
9090

9191
@Override
9292
public boolean isScopeSupported(ScopeType scope) {
93-
if (scope == ScopeType.REGION)
94-
return true;
95-
return false;
93+
return scope == ScopeType.ZONE || scope == ScopeType.REGION;
9694
}
9795

9896
@Override

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,16 +3537,6 @@ public ImageStore discoverImageStore(String name, String url, String providerNam
35373537
throw new InvalidParameterValueException("Image store provider " + providerName + " does not support scope " + scopeType);
35383538
}
35393539

3540-
// check if we have already image stores from other different providers,
3541-
// we currently are not supporting image stores from different
3542-
// providers co-existing
3543-
List<ImageStoreVO> imageStores = _imageStoreDao.listImageStores();
3544-
for (ImageStoreVO store : imageStores) {
3545-
if (!store.getProviderName().equalsIgnoreCase(providerName)) {
3546-
throw new InvalidParameterValueException("You can only add new image stores from the same provider " + store.getProviderName() + " already added");
3547-
}
3548-
}
3549-
35503540
if (zoneId != null) {
35513541
// Check if the zone exists in the system
35523542
DataCenterVO zone = _dcDao.findById(zoneId);

0 commit comments

Comments
 (0)