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

Adds get method for vm with optional properties #311

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions src/saltext/vmware/modules/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,60 @@ def list_(service_instance=None, profile=None):
return utils_vm.list_vms(service_instance)


def get(
name,
service_instance=None,
datacenter_name=None,
vm_properties=None,
parent_ref=None,
traversal_spec=None,
profile=None,
):
"""
Get virtual machine properties based on the traversal specs and properties list,
returns Virtual Machine object with properties.

service_instance
Service instance object to access vCenter

name
Name of the virtual machine.

datacenter
Datacenter name

vm_properties
List of vm properties.

traversal_spec
Traversal Spec object(s) for searching.

parent_ref
Container Reference object for searching under a given object.

CLI Example:

.. code-block:: bash

salt '*' vmware_vm.get vm-01
"""
if service_instance is None:
service_instance = connect.get_service_instance(config=__opts__, profile=profile)

virtual_machine = utils_vm.get_vm_by_property(
service_instance,
name,
datacenter=datacenter_name,
vm_properties=vm_properties,
traversal_spec=traversal_spec,
parent_ref=parent_ref,
)

virtual_machine = json.loads(json.dumps(virtual_machine, cls=VmomiSupport.VmomiJSONEncoder))

return virtual_machine


def list_templates(service_instance=None, profile=None):
"""
Returns virtual machines tempates.
Expand Down