|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.cloudstack.api.command.admin.storage; |
| 19 | + |
| 20 | +import org.apache.cloudstack.api.APICommand; |
| 21 | +import org.apache.cloudstack.api.ApiCommandResourceType; |
| 22 | +import org.apache.cloudstack.api.ApiConstants; |
| 23 | +import org.apache.cloudstack.api.BaseAsyncCmd; |
| 24 | +import org.apache.cloudstack.api.Parameter; |
| 25 | +import org.apache.cloudstack.api.response.ClusterResponse; |
| 26 | +import org.apache.cloudstack.api.response.StoragePoolResponse; |
| 27 | +import org.apache.cloudstack.api.response.SuccessResponse; |
| 28 | +import org.apache.cloudstack.context.CallContext; |
| 29 | + |
| 30 | +import com.cloud.event.EventTypes; |
| 31 | +import com.cloud.storage.StoragePool; |
| 32 | + |
| 33 | +@APICommand(name = "changeStoragePoolScope", description = "Changes the scope of a storage pool when the pool is in Disabled state." + |
| 34 | + "This feature is officially tested and supported for Hypervisors: KVM and VMware, Protocols: NFS and Ceph, and Storage Provider: DefaultPrimary. " + |
| 35 | + "There might be extra steps involved to make this work for other hypervisors and storage options.", |
| 36 | + responseObject = SuccessResponse.class, since= "4.19.1", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) |
| 37 | +public class ChangeStoragePoolScopeCmd extends BaseAsyncCmd { |
| 38 | + |
| 39 | + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = StoragePoolResponse.class, required = true, description = "the Id of the storage pool") |
| 40 | + private Long id; |
| 41 | + |
| 42 | + @Parameter(name = ApiConstants.SCOPE, type = CommandType.STRING, required = true, description = "the scope of the storage: cluster or zone") |
| 43 | + private String scope; |
| 44 | + |
| 45 | + @Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.UUID, entityType = ClusterResponse.class, description = "the Id of the cluster to use if scope is being set to Cluster") |
| 46 | + private Long clusterId; |
| 47 | + |
| 48 | + @Override |
| 49 | + public ApiCommandResourceType getApiResourceType() { |
| 50 | + return ApiCommandResourceType.StoragePool; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public Long getApiResourceId() { |
| 55 | + return getId(); |
| 56 | + } |
| 57 | + |
| 58 | + public String getEventType() { |
| 59 | + return EventTypes.EVENT_CHANGE_STORAGE_POOL_SCOPE; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public String getEventDescription() { |
| 64 | + String description = "Change storage pool scope. Storage pool Id: "; |
| 65 | + StoragePool pool = _entityMgr.findById(StoragePool.class, getId()); |
| 66 | + if (pool != null) { |
| 67 | + description += pool.getUuid(); |
| 68 | + } else { |
| 69 | + description += getId(); |
| 70 | + } |
| 71 | + description += " to " + getScope(); |
| 72 | + return description; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void execute() { |
| 77 | + _storageService.changeStoragePoolScope(this); |
| 78 | + SuccessResponse response = new SuccessResponse(getCommandName()); |
| 79 | + this.setResponseObject(response); |
| 80 | + } |
| 81 | + |
| 82 | + @Override |
| 83 | + public long getEntityOwnerId() { |
| 84 | + return CallContext.current().getCallingAccountId(); |
| 85 | + } |
| 86 | + |
| 87 | + public Long getId() { |
| 88 | + return id; |
| 89 | + } |
| 90 | + |
| 91 | + public String getScope() { |
| 92 | + return scope; |
| 93 | + } |
| 94 | + |
| 95 | + public Long getClusterId() { |
| 96 | + return clusterId; |
| 97 | + } |
| 98 | +} |
0 commit comments