Skip to content
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

Powershell get-view in pyvmomi #746

Open
RalfAlbers opened this issue Feb 22, 2024 · 3 comments
Open

Powershell get-view in pyvmomi #746

RalfAlbers opened this issue Feb 22, 2024 · 3 comments

Comments

@RalfAlbers
Copy link

Is your feature request related to a problem? Please describe.

In VMware PowerCLI I can retrieve very quick with get-view with -filter and -property data from our large vCenter. With using -filter and -property, the data is filtered on vCenter side, not on client side. This reduces a lot of network traffic with each API Call.
This is an example:
Get-View -ViewType VirtualMachine -Filter @{'Runtime.PowerState'='poweredOn';'Guest.ToolsState'='ToolsOk'} -property Name

Describe the solution you'd like

How can In get this done with pyvmomi?

Describe alternatives you've considered

Additional context

@prziborowski
Copy link
Contributor

I think https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/vminfo_quick.py is the best example for what you want.
view = pchelper.get_container_view(si, obj_type=[vim.VirtualMachine]) part is for getting a view (note that you are responsible for calling view.Destroy() on it when you are done, which this sample doesn't.

vm_data = pchelper.collect_properties(si,
                                      view_ref=view,
                                      obj_type=vim.VirtualMachine,
                                      path_set=vm_properties,
                                      include_mors=True)

fetches the properties for the VM.

This sample doesn't have a filter in it. But you can add something like https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/filter_vms.py#L44 to it (that example is just made for 1 property filtering, so you'd have to compare arrays rather than [0] index).

@RalfAlbers
Copy link
Author

https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/filter_vms.py#L44 is an filter after you had transfered the data from vcenter to your client.
If I'm not wrong, the PowerCLI option -filter does a filtering on vCenter side. I'm looking for a way to achieve this with pyvmomi too.

@prziborowski
Copy link
Contributor

I don't have any easy way to confirm if powercli does the filtering on the client or on the server (likely the easiest way would be to make vCenter config changes to log communication, or using something like wireshark).

The only reason I am thinking powercli does client filtering is that I haven't yet found anything in the PropertyCollector's FilterSpec that would provide server-side filtering based on values. It just allows setting the properties and objects that one is interested in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants