Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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.vm;

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.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ImportVMTaskResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.vm.ImportVmTasksManager;
import org.apache.commons.lang3.BooleanUtils;

import javax.inject.Inject;

@APICommand(name = "executeImportVmTaskAction",
description = "Execute a generic action on an import virtual machine task",
responseObject = ImportVMTaskResponse.class,
responseView = ResponseObject.ResponseView.Full,
requestHasSensitiveInfo = false,
responseHasSensitiveInfo = false,
authorized = {RoleType.Admin},
since = "4.22")
public class ExecuteImportVMTaskActionCmd extends BaseCmd {

@Inject
public ImportVmTasksManager importVmTasksManager;

@Parameter(name = ApiConstants.IMPORT_VM_TASK_ID,
type = CommandType.STRING,
required = true,
description = "the import VM task ID")
private String importVmTaskId;

@Parameter(name = ApiConstants.ACTION,
type = CommandType.STRING,
required = true,
description = "the task action to execute. Supported values are: refresh, phase2, resume, retryfromstart, cancel, delete, clearcredentials")
private String action;

@Parameter(name = "cleanup",
type = CommandType.BOOLEAN,
description = "whether to cleanup runtime artifacts such as workdir when the selected action supports cleanup")
private Boolean cleanup;

@Parameter(name = "removecredentials",
type = CommandType.BOOLEAN,
description = "whether to remove stored encrypted source credentials when the selected action supports credential cleanup")
private Boolean removeCredentials;

@Parameter(name = "force",
type = CommandType.BOOLEAN,
description = "force the selected action when it is otherwise restricted")
private Boolean force;

public String getImportVmTaskId() {
return importVmTaskId;
}

public String getAction() {
return action;
}

public boolean isCleanup() {
return BooleanUtils.toBooleanDefaultIfNull(cleanup, false);
}

public boolean isRemoveCredentials() {
return BooleanUtils.toBooleanDefaultIfNull(removeCredentials, false);
}

public boolean isForced() {
return BooleanUtils.toBooleanDefaultIfNull(force, false);
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
ImportVMTaskResponse response = importVmTasksManager.executeImportVMTaskAction(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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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.vm;

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 org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

@APICommand(name = "importUnmanagedInstanceForAblestackN2K",
description = "Import virtual machine from Nutanix into CloudStack using ablestack-n2k workflow",
responseObject = UserVmResponse.class,
responseView = ResponseObject.ResponseView.Full,
requestHasSensitiveInfo = true,
responseHasSensitiveInfo = true,
authorized = {RoleType.Admin},
since = "4.22")
public class ImportUnmanagedInstanceForAblestackN2KCmd extends ImportVmCmd {

private static final String DEFAULT_SPLIT_MODE = "phase1";
private static final String DEFAULT_SOURCE_API = "v3";
private static final Long DEFAULT_RETENTION_SECONDS = 1209600L;

@Parameter(name = "split",
type = CommandType.STRING,
description = "(only for importing VMs from Nutanix to KVM with ablestack-n2k) split-run mode: phase1, phase2 or full")
private String splitMode;

@Parameter(name = ApiConstants.IMPORT_VM_TASK_ID,
type = CommandType.STRING,
description = "(only for task continuation) existing import VM task ID to continue on the original conversion host")
private String importVmTaskId;

@Parameter(name = "taskaction",
type = CommandType.STRING,
description = "(only with importvmtaskid) task action to execute: phase2, resume, or retryfromstart")
private String taskAction;

@Parameter(name = "sourceapi",
type = CommandType.STRING,
description = "source API for ablestack-n2k run. Current Cloud-managed execution uses v3 snapshot/NFS data path")
private String sourceApi;

@Parameter(name = "insecure",
type = CommandType.BOOLEAN,
description = "skip TLS verification for Nutanix Prism when true")
private Boolean insecure;

@Parameter(name = "retentionseconds",
type = CommandType.LONG,
description = "source snapshot/recovery point retention time in seconds for ablestack-n2k. Default is 1209600 seconds (14 days)")
private Long retentionSeconds;

public String getSplitMode() {
return StringUtils.defaultIfBlank(splitMode, DEFAULT_SPLIT_MODE);
}

public String getImportVmTaskId() {
return importVmTaskId;
}

public String getTaskAction() {
return taskAction;
}

public String getSourceApi() {
return StringUtils.defaultIfBlank(sourceApi, DEFAULT_SOURCE_API);
}

public boolean isInsecure() {
return BooleanUtils.toBooleanDefaultIfNull(insecure, true);
}

public Long getRequestedRetentionSeconds() {
return retentionSeconds;
}

public long getRetentionSeconds() {
return retentionSeconds != null ? retentionSeconds : DEFAULT_RETENTION_SECONDS;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
UserVmResponse response = vmImportService.importVmForAblestackN2K(this);
response.setResponseName(getCommandName());
setResponseObject(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
description = "Import virtual machine from VMware into CloudStack using ablestack-v2k workflow",
responseObject = UserVmResponse.class,
responseView = ResponseObject.ResponseView.Full,
requestHasSensitiveInfo = false,
requestHasSensitiveInfo = true,
responseHasSensitiveInfo = true,
authorized = {RoleType.Admin},
since = "4.19.0")
Expand All @@ -49,9 +49,14 @@ public class ImportUnmanagedInstanceForAblestackV2KCmd extends ImportVmCmd {

@Parameter(name = ApiConstants.IMPORT_VM_TASK_ID,
type = CommandType.STRING,
description = "(only for phase2 execution) existing import VM task ID to continue on the original conversion host")
description = "(only for task continuation) existing import VM task ID to continue on the original conversion host")
private String importVmTaskId;

@Parameter(name = "taskaction",
type = CommandType.STRING,
description = "(only with importvmtaskid) task action to execute: phase2, resume, or retryfromstart")
private String taskAction;

public String getSplitMode() {
return StringUtils.defaultIfBlank(splitMode, DEFAULT_SPLIT_MODE);
}
Expand All @@ -60,6 +65,10 @@ public String getImportVmTaskId() {
return importVmTaskId;
}

public String getTaskAction() {
return taskAction;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
UserVmResponse response = vmImportService.importVmForAblestackV2K(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
description = "Import virtual machine from a unmanaged host into CloudStack",
responseObject = UserVmResponse.class,
responseView = ResponseObject.ResponseView.Full,
requestHasSensitiveInfo = false,
requestHasSensitiveInfo = true,
responseHasSensitiveInfo = true,
authorized = {RoleType.Admin},
since = "4.19.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// 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.vm;

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.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.ImportVMTaskEventResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.vm.ImportVmTasksManager;

import javax.inject.Inject;

@APICommand(name = "listImportVmTaskEvents",
description = "List events for an import virtual machine task",
responseObject = ImportVMTaskEventResponse.class,
responseView = ResponseObject.ResponseView.Full,
requestHasSensitiveInfo = false,
authorized = {RoleType.Admin},
since = "4.22")
public class ListImportVMTaskEventsCmd extends BaseListCmd {

@Inject
public ImportVmTasksManager importVmTasksManager;

@Parameter(name = ApiConstants.IMPORT_VM_TASK_ID,
type = CommandType.STRING,
required = true,
description = "the import VM task ID")
private String importVmTaskId;

public String getImportVmTaskId() {
return importVmTaskId;
}

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
ListResponse<ImportVMTaskEventResponse> response = importVmTasksManager.listImportVMTaskEvents(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;
}
}
Loading
Loading