forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: Import volume from storage pool
- Loading branch information
1 parent
33dc746
commit 8b4b915
Showing
22 changed files
with
1,737 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
api/src/main/java/org/apache/cloudstack/api/command/admin/volume/ImportVolumeCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.volume; | ||
|
||
import com.cloud.event.EventTypes; | ||
import com.cloud.exception.ConcurrentOperationException; | ||
import com.cloud.exception.InsufficientCapacityException; | ||
import com.cloud.exception.NetworkRuleConflictException; | ||
import com.cloud.exception.ResourceAllocationException; | ||
import com.cloud.exception.ResourceUnavailableException; | ||
import com.cloud.user.Account; | ||
|
||
import org.apache.cloudstack.acl.RoleType; | ||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.BaseAsyncCmd; | ||
import org.apache.cloudstack.api.BaseCmd; | ||
import org.apache.cloudstack.api.Parameter; | ||
import org.apache.cloudstack.api.ResponseObject; | ||
import org.apache.cloudstack.api.ServerApiException; | ||
import org.apache.cloudstack.api.response.DiskOfferingResponse; | ||
import org.apache.cloudstack.api.response.DomainResponse; | ||
import org.apache.cloudstack.api.response.ProjectResponse; | ||
import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
import org.apache.cloudstack.api.response.VolumeResponse; | ||
import org.apache.cloudstack.context.CallContext; | ||
import org.apache.cloudstack.storage.volume.VolumeImportUnmanageService; | ||
|
||
import javax.inject.Inject; | ||
|
||
@APICommand(name = "importVolume", | ||
description = "Import an unmanaged volume from a storage pool on a host into CloudStack", | ||
responseObject = VolumeResponse.class, | ||
responseView = ResponseObject.ResponseView.Full, | ||
requestHasSensitiveInfo = false, | ||
responseHasSensitiveInfo = true, | ||
authorized = {RoleType.Admin}, | ||
since = "4.19.1") | ||
public class ImportVolumeCmd extends BaseAsyncCmd { | ||
|
||
@Inject | ||
public VolumeImportUnmanageService volumeImportService; | ||
|
||
///////////////////////////////////////////////////// | ||
//////////////// API parameters ///////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
|
||
@Parameter(name = ApiConstants.PATH, | ||
type = BaseCmd.CommandType.STRING, | ||
required = true, | ||
description = "the path of the volume") | ||
private String path; | ||
|
||
@Parameter(name = ApiConstants.STORAGE_ID, | ||
type = BaseCmd.CommandType.UUID, | ||
required = true, | ||
entityType = StoragePoolResponse.class, | ||
description = "the ID of the storage pool") | ||
private Long storageId; | ||
|
||
@Parameter(name = ApiConstants.DISK_OFFERING_ID, | ||
type = BaseCmd.CommandType.UUID, | ||
entityType = DiskOfferingResponse.class, | ||
description = "the ID of the disk offering linked to the volume") | ||
private Long diskOfferingId; | ||
|
||
@Parameter(name = ApiConstants.ACCOUNT, | ||
type = BaseCmd.CommandType.STRING, | ||
description = "an optional account for the virtual machine. Must be used with domainId.") | ||
private String accountName; | ||
|
||
@Parameter(name = ApiConstants.DOMAIN_ID, | ||
type = BaseCmd.CommandType.UUID, | ||
entityType = DomainResponse.class, | ||
description = "import instance to the domain specified") | ||
private Long domainId; | ||
|
||
@Parameter(name = ApiConstants.PROJECT_ID, | ||
type = BaseCmd.CommandType.UUID, | ||
entityType = ProjectResponse.class, | ||
description = "import instance for the project") | ||
private Long projectId; | ||
|
||
///////////////////////////////////////////////////// | ||
/////////////////// Accessors /////////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
public String getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(String path) { | ||
this.path = path; | ||
} | ||
|
||
public Long getStorageId() { | ||
return storageId; | ||
} | ||
|
||
public void setStorageId(Long storageId) { | ||
this.storageId = storageId; | ||
} | ||
|
||
public Long getDiskOfferingId() { | ||
return diskOfferingId; | ||
} | ||
|
||
public void setDiskOfferingId(Long diskOfferingId) { | ||
this.diskOfferingId = diskOfferingId; | ||
} | ||
|
||
public String getAccountName() { | ||
return accountName; | ||
} | ||
|
||
public void setAccountName(String accountName) { | ||
this.accountName = accountName; | ||
} | ||
|
||
public Long getDomainId() { | ||
return domainId; | ||
} | ||
|
||
public void setDomainId(Long domainId) { | ||
this.domainId = domainId; | ||
} | ||
|
||
public Long getProjectId() { | ||
return projectId; | ||
} | ||
|
||
public void setProjectId(Long projectId) { | ||
this.projectId = projectId; | ||
} | ||
|
||
@Override | ||
public String getEventType() { | ||
return EventTypes.EVENT_VOLUME_IMPORT; | ||
} | ||
|
||
@Override | ||
public String getEventDescription() { | ||
return String.format("Importing unmanaged Volume with path: %s", path); | ||
} | ||
|
||
///////////////////////////////////////////////////// | ||
/////////////// API Implementation/////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
@Override | ||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
VolumeResponse response = volumeImportService.importVolume(this); | ||
response.setResponseName(getCommandName()); | ||
setResponseObject(response); | ||
} | ||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
Account caller = CallContext.current().getCallingAccount(); | ||
return caller.getAccountId(); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...src/main/java/org/apache/cloudstack/api/command/admin/volume/ListVolumesForImportCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.volume; | ||
|
||
import com.cloud.exception.ConcurrentOperationException; | ||
import com.cloud.exception.InsufficientCapacityException; | ||
import com.cloud.exception.NetworkRuleConflictException; | ||
import com.cloud.exception.ResourceAllocationException; | ||
import com.cloud.exception.ResourceUnavailableException; | ||
import com.cloud.user.Account; | ||
import org.apache.cloudstack.acl.RoleType; | ||
import org.apache.cloudstack.api.APICommand; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.BaseCmd; | ||
import org.apache.cloudstack.api.BaseListCmd; | ||
import org.apache.cloudstack.api.Parameter; | ||
import org.apache.cloudstack.api.ResponseObject; | ||
import org.apache.cloudstack.api.ServerApiException; | ||
import org.apache.cloudstack.api.response.ListResponse; | ||
import org.apache.cloudstack.api.response.StoragePoolResponse; | ||
import org.apache.cloudstack.api.response.VolumeForImportResponse; | ||
import org.apache.cloudstack.context.CallContext; | ||
import org.apache.cloudstack.storage.volume.VolumeImportUnmanageService; | ||
import org.apache.cloudstack.storage.volume.VolumeOnStorageTO; | ||
|
||
import javax.inject.Inject; | ||
|
||
@APICommand(name = "listVolumesForImport", | ||
description = "Lists unmanaged volumes on a storage pool", | ||
responseObject = VolumeForImportResponse.class, | ||
responseView = ResponseObject.ResponseView.Full, | ||
entityType = {VolumeOnStorageTO.class}, | ||
requestHasSensitiveInfo = false, | ||
responseHasSensitiveInfo = true, | ||
authorized = {RoleType.Admin}, | ||
since = "4.19.1") | ||
public class ListVolumesForImportCmd extends BaseListCmd { | ||
|
||
@Inject | ||
public VolumeImportUnmanageService volumeImportService; | ||
|
||
///////////////////////////////////////////////////// | ||
//////////////// API parameters ///////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
@Parameter(name = ApiConstants.STORAGE_ID, | ||
type = BaseCmd.CommandType.UUID, | ||
required = true, | ||
entityType = StoragePoolResponse.class, | ||
description = "the ID of the storage pool") | ||
private Long storageId; | ||
|
||
///////////////////////////////////////////////////// | ||
/////////////////// Accessors /////////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
public Long getStorageId() { | ||
return storageId; | ||
} | ||
|
||
///////////////////////////////////////////////////// | ||
/////////////// API Implementation/////////////////// | ||
///////////////////////////////////////////////////// | ||
|
||
@Override | ||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
ListResponse<VolumeForImportResponse> response = volumeImportService.listVolumesForImport(this); | ||
response.setResponseName(getCommandName()); | ||
setResponseObject(response); | ||
} | ||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
Account account = CallContext.current().getCallingAccount(); | ||
if (account != null) { | ||
return account.getId(); | ||
} | ||
return Account.ACCOUNT_ID_SYSTEM; | ||
} | ||
} |
Oops, something went wrong.