| // 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.ListResponse; |
| import org.apache.cloudstack.api.response.UnmanagedInstanceResponse; |
| import org.apache.cloudstack.api.response.ZoneResponse; |
| import org.apache.cloudstack.context.CallContext; |
| import org.apache.cloudstack.vm.UnmanagedInstanceTO; |
| import org.apache.cloudstack.vm.VmImportService; |
| |
| import javax.inject.Inject; |
| |
| @APICommand(name = "listVmsForImport", |
| description = "Lists virtual machines on a unmanaged host", |
| responseObject = UnmanagedInstanceResponse.class, |
| responseView = ResponseObject.ResponseView.Full, |
| entityType = {UnmanagedInstanceTO.class}, |
| requestHasSensitiveInfo = false, |
| responseHasSensitiveInfo = true, |
| authorized = {RoleType.Admin}, |
| since = "4.19.0") |
| public class ListVmsForImportCmd extends BaseListCmd { |
| |
| @Inject |
| public VmImportService vmImportService; |
| |
| ///////////////////////////////////////////////////// |
| //////////////// API parameters ///////////////////// |
| ///////////////////////////////////////////////////// |
| |
| @Parameter(name = ApiConstants.ZONE_ID, |
| type = CommandType.UUID, |
| entityType = ZoneResponse.class, |
| required = true, |
| description = "the zone ID") |
| private Long zoneId; |
| |
| @Parameter(name = ApiConstants.USERNAME, |
| type = CommandType.STRING, |
| description = "the username for the host") |
| private String username; |
| |
| @Parameter(name = ApiConstants.PASSWORD, |
| type = CommandType.STRING, |
| description = "the password for the host") |
| private String password; |
| |
| @Parameter(name = ApiConstants.HOST, |
| type = CommandType.STRING, |
| required = true, |
| description = "the host name or IP address") |
| private String host; |
| |
| @Parameter(name = ApiConstants.HYPERVISOR, |
| type = CommandType.STRING, |
| required = true, |
| description = "hypervisor type of the host") |
| private String hypervisor; |
| |
| ///////////////////////////////////////////////////// |
| /////////////////// Accessors /////////////////////// |
| ///////////////////////////////////////////////////// |
| |
| public Long getZoneId() { |
| return zoneId; |
| } |
| |
| public String getUsername() { |
| return username; |
| } |
| |
| public String getPassword() { |
| return password; |
| } |
| |
| public String getHost() { |
| return host; |
| } |
| |
| public String getHypervisor() { |
| return hypervisor; |
| } |
| |
| ///////////////////////////////////////////////////// |
| /////////////// API Implementation/////////////////// |
| ///////////////////////////////////////////////////// |
| |
| @Override |
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { |
| ListResponse<UnmanagedInstanceResponse> response = vmImportService.listVmsForImport(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; |
| } |
| } |