|
| 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 | +//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.backup; |
| 19 | + |
| 20 | +import javax.inject.Inject; |
| 21 | + |
| 22 | +import org.apache.cloudstack.acl.RoleType; |
| 23 | +import org.apache.cloudstack.api.APICommand; |
| 24 | +import org.apache.cloudstack.api.ApiConstants; |
| 25 | +import org.apache.cloudstack.api.BaseCmd; |
| 26 | +import org.apache.cloudstack.api.Parameter; |
| 27 | +import org.apache.cloudstack.api.command.admin.AdminCmd; |
| 28 | +import org.apache.cloudstack.api.response.BackupResponse; |
| 29 | +import org.apache.cloudstack.api.response.ImageTransferResponse; |
| 30 | +import org.apache.cloudstack.api.response.VolumeResponse; |
| 31 | +import org.apache.cloudstack.backup.ImageTransfer; |
| 32 | +import org.apache.cloudstack.backup.KVMBackupExportService; |
| 33 | +import org.apache.cloudstack.context.CallContext; |
| 34 | + |
| 35 | +import com.cloud.utils.EnumUtils; |
| 36 | + |
| 37 | +@APICommand(name = "createImageTransfer", |
| 38 | + description = "Create image transfer for a disk in backup. This API is intended for testing only and is disabled by default.", |
| 39 | + responseObject = ImageTransferResponse.class, |
| 40 | + since = "4.23.0", |
| 41 | + authorized = {RoleType.Admin}) |
| 42 | +public class CreateImageTransferCmd extends BaseCmd implements AdminCmd { |
| 43 | + |
| 44 | + @Inject |
| 45 | + private KVMBackupExportService kvmBackupExportService; |
| 46 | + |
| 47 | + @Parameter(name = ApiConstants.BACKUP_ID, |
| 48 | + type = CommandType.UUID, |
| 49 | + entityType = BackupResponse.class, |
| 50 | + description = "ID of the backup") |
| 51 | + private Long backupId; |
| 52 | + |
| 53 | + @Parameter(name = ApiConstants.VOLUME_ID, |
| 54 | + type = CommandType.UUID, |
| 55 | + entityType = VolumeResponse.class, |
| 56 | + required = true, |
| 57 | + description = "ID of the disk/volume") |
| 58 | + private Long volumeId; |
| 59 | + |
| 60 | + @Parameter(name = ApiConstants.DIRECTION, |
| 61 | + type = CommandType.STRING, |
| 62 | + required = true, |
| 63 | + description = "Direction of the transfer: upload, download") |
| 64 | + private String direction; |
| 65 | + |
| 66 | + @Parameter(name = ApiConstants.FORMAT, |
| 67 | + type = CommandType.STRING, |
| 68 | + description = "Format for the image transfer: raw/cow. 'raw' will create an NBD backend. 'cow' will use the File backend." + |
| 69 | + "For download, only the 'raw' format is supported. Default: raw") |
| 70 | + private String format; |
| 71 | + |
| 72 | + public Long getBackupId() { |
| 73 | + return backupId; |
| 74 | + } |
| 75 | + |
| 76 | + public Long getVolumeId() { |
| 77 | + return volumeId; |
| 78 | + } |
| 79 | + |
| 80 | + public ImageTransfer.Direction getDirection() { |
| 81 | + return ImageTransfer.Direction.valueOf(direction); |
| 82 | + } |
| 83 | + |
| 84 | + public ImageTransfer.Format getFormat() { |
| 85 | + return EnumUtils.getEnum(ImageTransfer.Format.class, format); |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void execute() { |
| 90 | + ImageTransferResponse response = kvmBackupExportService.createImageTransfer(this); |
| 91 | + response.setObjectName(ImageTransfer.class.getSimpleName().toLowerCase()); |
| 92 | + response.setResponseName(getCommandName()); |
| 93 | + setResponseObject(response); |
| 94 | + } |
| 95 | + |
| 96 | + @Override |
| 97 | + public long getEntityOwnerId() { |
| 98 | + return CallContext.current().getCallingAccount().getId(); |
| 99 | + } |
| 100 | +} |
0 commit comments