Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ public class ApiConstants {
public static final String QUALIFIERS = "qualifiers";
public static final String QUERY_FILTER = "queryfilter";
public static final String QUIESCE_VM = "quiescevm";
public static final String STAGING_DISK_PATHS = "stagingdiskpaths";
public static final String VEEAM_RESTORE_POINT_ID = "veeamrestorepointid";
public static final String SOURCE_DISK_FORMAT = "sourcediskformat";
public static final String BOOTSTRAP_CHECKPOINT = "bootstrapcheckpoint";
public static final String SCHEDULE = "schedule";
public static final String SCHEDULE_ID = "scheduleid";
public static final String SCOPE = "scope";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// 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.user.backup;

import javax.inject.Inject;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.context.CallContext;

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.utils.exception.CloudRuntimeException;

@APICommand(name = "createAblestackVeeamBackup",
description = "Create an incremental NAS backup for a VM assigned to the ablestack-veeam offering "
+ "(typically after a Veeam job completes)",
responseObject = SuccessResponse.class,
since = "4.22.0.0",
authorized = {RoleType.Admin, RoleType.ResourceAdmin})
public class CreateAblestackVeeamBackupCmd extends BaseAsyncCreateCmd {

@Inject
private BackupManager backupManager;

@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "KVM instance ID")
private Long vmId;

@Parameter(name = ApiConstants.QUIESCE_VM,
type = CommandType.BOOLEAN,
required = false,
description = "Quiesce VM via QEMU guest agent before backup")
private Boolean quiesceVM;

@Parameter(name = ApiConstants.NAME,
type = CommandType.STRING,
description = "the name of the backup (default: VM hostname + ISO-8601 timestamp)",
since = "4.22.0.0")
private String name;

public Long getVmId() {
return vmId;
}

public Boolean getQuiesceVM() {
return quiesceVM;
}

public String getName() {
return name;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
boolean result = backupManager.createAblestackVeeamBackup(this, getJob());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new CloudRuntimeException("Failed to create Ablestack Veeam backup");
}
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.Backup;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}

@Override
public String getEventType() {
return EventTypes.EVENT_VM_BACKUP_CREATE;
}

@Override
public String getEventDescription() {
return "Creating Ablestack Veeam NAS backup for Instance " + getResourceUuid(ApiConstants.VIRTUAL_MACHINE_ID);
}

@Override
public void create() throws ResourceAllocationException {
}

@Override
public Long getEntityId() {
return vmId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// 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.user.backup;

import javax.inject.Inject;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCreateCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.context.CallContext;

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;

@APICommand(name = "importAblestackVeeamBackupSeed",
description = "Import a Veeam restore point as a NAS backup seed for Ablestack Veeam incremental KVM backups",
responseObject = BackupResponse.class,
since = "4.22.0.0",
authorized = {RoleType.Admin, RoleType.ResourceAdmin})
public class ImportAblestackVeeamBackupSeedCmd extends BaseAsyncCreateCmd {

@Inject
private BackupManager backupManager;

@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "KVM instance to register the seed backup for")
private Long vmId;

@Parameter(name = ApiConstants.VEEAM_RESTORE_POINT_ID,
type = CommandType.STRING,
required = false,
description = "Veeam restore point ID. If omitted, stagingdiskpaths must be provided.")
private String veeamRestorePointId;

@Parameter(name = ApiConstants.STAGING_DISK_PATHS,
type = CommandType.STRING,
required = false,
description = "Comma-separated disk file paths on the KVM host (from shared staging). "
+ "If omitted, disks are exported from Veeam using veeamrestorepointid.")
private String stagingDiskPaths;

@Parameter(name = ApiConstants.SOURCE_DISK_FORMAT,
type = CommandType.STRING,
required = false,
description = "Staging disk format: vmdk, flat, qcow2, or raw. Default: vmdk")
private String sourceDiskFormat;

@Parameter(name = ApiConstants.BOOTSTRAP_CHECKPOINT,
type = CommandType.BOOLEAN,
required = false,
description = "Create libvirt checkpoint on the KVM VM after import. Default: true")
private Boolean bootstrapCheckpoint;

@Parameter(name = ApiConstants.NAME,
type = CommandType.STRING,
description = "the name of the backup (default: VM hostname + ISO-8601 timestamp)",
since = "4.22.0.0")
private String name;

public Long getVmId() {
return vmId;
}

public String getVeeamRestorePointId() {
return veeamRestorePointId;
}

public String getStagingDiskPaths() {
return stagingDiskPaths;
}

public String getSourceDiskFormat() {
return sourceDiskFormat;
}

public Boolean getBootstrapCheckpoint() {
return bootstrapCheckpoint;
}

public String getName() {
return name;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
Backup backup = backupManager.importAblestackVeeamBackupSeed(this);
BackupResponse response = backupManager.createBackupResponse(backup, false);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.Backup;
}

@Override
public String getEventType() {
return EventTypes.EVENT_VM_BACKUP_CREATE;
}

@Override
public String getEventDescription() {
return "Importing Ablestack Veeam backup seed for Instance " + getResourceUuid(ApiConstants.VIRTUAL_MACHINE_ID);
}

@Override
public void create() throws ResourceAllocationException {
}

@Override
public Long getEntityId() {
return vmId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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.user.backup;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.BackupResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.backup.Backup;
import org.apache.cloudstack.backup.BackupManager;
import org.apache.cloudstack.context.CallContext;

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.utils.Pair;

@APICommand(name = "listAblestackVeeamBackups",
description = "List NAS backups for a VM using the ablestack-veeam backup offering",
responseObject = BackupResponse.class,
since = "4.22.0.0",
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
public class ListAblestackVeeamBackupsCmd extends BaseListCmd {

@Inject
private BackupManager backupManager;

@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID,
type = CommandType.UUID,
entityType = UserVmResponse.class,
required = true,
description = "KVM instance ID")
private Long vmId;

public Long getVmId() {
return vmId;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
Pair<List<Backup>, Integer> result = backupManager.listAblestackVeeamBackups(this);
ListResponse<BackupResponse> response = new ListResponse<>();
List<BackupResponse> backupResponses = new ArrayList<>();
for (Backup backup : result.first()) {
backupResponses.add(backupManager.createBackupResponse(backup, false));
}
response.setResponses(backupResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (Exception e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}
Loading
Loading