-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add the option to filter by host when retrieving of unregistered VMs #9925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
14f4956
c8cdaff
964fbdc
cff61f7
55dfe40
aac47c9
127d182
fba40d3
5c61ec4
0bf417e
ac8a0cf
1ae6166
cd6d42c
11ca518
f0f90dd
aa151c2
2bc09a5
290111f
f3085a6
e208bbb
3ba54bb
64a2edc
a6d9d70
d39e23e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| // 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.zone; | ||
|
|
||
| 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.hypervisor.Hypervisor; | ||
| import com.cloud.hypervisor.vmware.VmwareDatacenterService; | ||
| import com.cloud.hypervisor.vmware.mo.HostMO; | ||
| import com.cloud.user.Account; | ||
| import com.cloud.utils.exception.CloudRuntimeException; | ||
|
|
||
| import com.vmware.vim25.InvalidPropertyFaultMsg; | ||
| import com.vmware.vim25.RuntimeFaultFaultMsg; | ||
|
|
||
| import org.apache.cloudstack.api.APICommand; | ||
| import org.apache.cloudstack.api.ApiConstants; | ||
| import org.apache.cloudstack.api.ApiErrorCode; | ||
| import org.apache.cloudstack.api.BaseCmd; | ||
| import org.apache.cloudstack.api.BaseResponse; | ||
| import org.apache.cloudstack.api.Parameter; | ||
| import org.apache.cloudstack.api.ServerApiException; | ||
| import org.apache.cloudstack.api.response.HostResponse; | ||
| import org.apache.cloudstack.api.response.VmwareDatacenterResponse; | ||
| import org.apache.commons.collections.CollectionUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @APICommand(name = "listVmwareDcHosts", responseObject = VmwareRequestResponse.class, | ||
| description = "Lists the VMs in a Vmware Datacenter", | ||
| requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) | ||
| public class ListVmwareDcHostsCmd extends BaseCmd implements ListVmwareDcItems { | ||
|
|
||
| @Inject | ||
| public VmwareDatacenterService _vmwareDatacenterService; | ||
|
|
||
| @Parameter(name = ApiConstants.EXISTING_VCENTER_ID, | ||
| type = CommandType.UUID, | ||
| entityType = VmwareDatacenterResponse.class, | ||
| description = "UUID of a linked existing vCenter") | ||
| private Long existingVcenterId; | ||
|
|
||
| @Parameter(name = ApiConstants.VCENTER, | ||
| type = CommandType.STRING, | ||
| description = "The name/ip of vCenter. Make sure it is IP address or full qualified domain name for host running vCenter server.") | ||
| private String vcenter; | ||
|
|
||
| @Parameter(name = ApiConstants.DATACENTER_NAME, type = CommandType.STRING, description = "Name of Vmware datacenter.") | ||
| private String datacenterName; | ||
|
|
||
| @Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "The Username required to connect to resource.") | ||
| private String username; | ||
|
|
||
| @Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "The password for specified username.") | ||
| private String password; | ||
|
|
||
| public String getVcenter() { | ||
| return vcenter; | ||
| } | ||
|
Check warning on line 80 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| public String getUsername() { | ||
| return username; | ||
| } | ||
|
Check warning on line 84 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| public String getPassword() { | ||
| return password; | ||
| } | ||
|
Check warning on line 88 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| public String getDatacenterName() { | ||
| return datacenterName; | ||
| } | ||
|
Check warning on line 92 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| public Long getExistingVcenterId() { | ||
| return existingVcenterId; | ||
| } | ||
|
Check warning on line 96 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| checkParameters(); | ||
| try { | ||
| List<HostMO> hosts = _vmwareDatacenterService.listHostsInDatacenter(this); | ||
| List<BaseResponse> baseResponseList = new ArrayList<>(); | ||
|
Check warning on line 103 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| if (CollectionUtils.isNotEmpty(hosts)) { | ||
| for (HostMO vmwareHost : hosts) { | ||
| HostResponse resp = createHostResponse(vmwareHost); | ||
| baseResponseList.add(resp); | ||
| } | ||
| } | ||
| VmwareRequestResponse<BaseResponse> response = new VmwareRequestResponse<>(); | ||
| response.setResponses(baseResponseList, baseResponseList.size()); | ||
| response.setResponseName(getCommandName()); | ||
| setResponseObject(response); | ||
| } catch (CloudRuntimeException | InvalidPropertyFaultMsg | RuntimeFaultFaultMsg | InvocationTargetException | | ||
|
Check warning on line 114 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| NoSuchMethodException | IllegalAccessException e) { | ||
| String errorMsg = String.format("Error retrieving VMs from Vmware VC: %s", e.getMessage()); | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg); | ||
| } | ||
| } | ||
|
Check warning on line 119 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| private HostResponse createHostResponse(HostMO hostInstance) throws InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, InvocationTargetException, NoSuchMethodException, IllegalAccessException { | ||
| HostResponse response = new HostResponse(); | ||
| response.setHypervisor(Hypervisor.HypervisorType.VMware.toString()); | ||
| response.setName(hostInstance.getHostName()); | ||
| response.setObjectName("host"); | ||
| return response; | ||
| } | ||
|
Check warning on line 127 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| private void checkParameters() { | ||
|
Check warning on line 129 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| if ((existingVcenterId == null && vcenter == null) || (existingVcenterId != null && vcenter != null)) { | ||
| throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
|
Check warning on line 131 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| "Please provide an existing vCenter ID or a vCenter IP/Name, parameters are mutually exclusive"); | ||
| } | ||
| if (existingVcenterId == null && StringUtils.isAnyBlank(vcenter, datacenterName, username, password)) { | ||
| throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
|
Check warning on line 135 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| "Please set all the information for a vCenter IP/Name, datacenter, username and password"); | ||
| } | ||
| } | ||
|
Check warning on line 138 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
|
Check warning on line 143 in plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // 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.zone; | ||
|
|
||
| public interface ListVmwareDcItems { | ||
| String getVcenter(); | ||
|
|
||
| String getDatacenterName(); | ||
|
|
||
| String getUsername(); | ||
|
|
||
| String getPassword(); | ||
|
|
||
| Long getExistingVcenterId(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.