-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Merged
DaanHoogland
merged 24 commits into
apache:4.19
from
shapeblue:ghi9782-paginateVmwareVMs
Feb 10, 2025
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
14f4956
add maximum results number to retrieval of unregistered VMs on vmware
DaanHoogland c8cdaff
add paging indicator
DaanHoogland 964fbdc
continue retrieving method added
DaanHoogland cff61f7
cleanup
DaanHoogland 55dfe40
propagate token to user/UI
DaanHoogland aac47c9
some suggestions applied and initial batch size in UI
DaanHoogland 127d182
extra logging
DaanHoogland fba40d3
cleanup and comments applied
DaanHoogland 5c61ec4
response object
DaanHoogland 0bf417e
response object
DaanHoogland ac8a0cf
log token
DaanHoogland 1ae6166
get hosts for dc
DaanHoogland cd6d42c
get all vms for a host
DaanHoogland 11ca518
use host to list vms
DaanHoogland f0f90dd
header
DaanHoogland aa151c2
fix UI and cleanup
DaanHoogland 2bc09a5
cleanup
DaanHoogland 290111f
stop loading
DaanHoogland f3085a6
host choice for external datacenters
DaanHoogland e208bbb
sugested log message improvement
DaanHoogland 3ba54bb
lower case API standard in response
DaanHoogland 64a2edc
more specific exceptions thrown
DaanHoogland a6d9d70
deal with globbing in marvin test data
DaanHoogland d39e23e
something fishy going on with case sensitifity in dynamic roles
DaanHoogland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
294 changes: 168 additions & 126 deletions
294
...pervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
...ware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcHostsCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| public String getUsername() { | ||
| return username; | ||
| } | ||
|
|
||
| public String getPassword() { | ||
| return password; | ||
| } | ||
|
|
||
| public String getDatacenterName() { | ||
| return datacenterName; | ||
| } | ||
|
|
||
| public Long getExistingVcenterId() { | ||
| return existingVcenterId; | ||
| } | ||
|
|
||
| @Override | ||
| public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { | ||
| checkParameters(); | ||
| try { | ||
| List<HostMO> hosts = _vmwareDatacenterService.listHostsInDatacenter(this); | ||
| List<BaseResponse> baseResponseList = new ArrayList<>(); | ||
| 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 | | ||
| NoSuchMethodException | IllegalAccessException e) { | ||
| String errorMsg = String.format("Error retrieving VMs from Vmware VC: %s", e.getMessage()); | ||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg); | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| private void checkParameters() { | ||
| if ((existingVcenterId == null && vcenter == null) || (existingVcenterId != null && vcenter != null)) { | ||
| throw new ServerApiException(ApiErrorCode.PARAM_ERROR, | ||
| "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, | ||
| "Please set all the information for a vCenter IP/Name, datacenter, username and password"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public long getEntityOwnerId() { | ||
| return Account.ACCOUNT_ID_SYSTEM; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
.../vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcItems.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.