Skip to content
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
53 changes: 44 additions & 9 deletions src/saltext/vmware/modules/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,18 +680,12 @@ def relocate(
return {"virtual_machine": "failed to move"}


def get_mks_ticket(vm_name, ticket_type, service_instance=None, profile=None):
def network(vm_name, service_instance=None, profile=None):
"""
Get ticket of virtual machine of passed object type.
Retreives the networking for a virtual machine.

vm_name
The name of the virtual machine which has tickets. VM names can be
found in ``vmware_vm.list``.

ticket_type
Type of ticket - device, guestControl, guestIntegrity, mks, or webmks.

See https://vdc-download.vmware.com/vmwb-repository/dcr-public/3325c370-b58c-4799-99ff-58ae3baac1bd/45789cc5-aba1-48bc-a320-5e35142b50af/doc/vim.VirtualMachine.TicketType.html
The name of the virtual machine to relocate.

service_instance
(optional) The Service Instance from which to obtain managed object references.
Expand All @@ -703,6 +697,47 @@ def get_mks_ticket(vm_name, ticket_type, service_instance=None, profile=None):

.. code-block:: bash

salt '*' vmware_vm.network vm_name=vm01
"""
ret = {}

service_instance = service_instance or connect.get_service_instance(
config=__opts__, profile=profile
)
vm_ref = utils_common.get_mor_by_property(service_instance, vim.VirtualMachine, vm_name)

network_refs = vm_ref.network

for network in network_refs:
ret[network.name] = {}

try:
ret[network.name]["config"] = network.config
except AttributeError:
# Fetch the port groups via host configuration attached to the virtual machine
host = vm_ref.summary.runtime.host
if host.config:
for portgroup in host.config.network.portgroup:
if network.name == portgroup.spec.name:
ret[network.name]["config"] = portgroup.spec

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

return ret

def get_mks_ticket(vm_name, ticket_type, service_instance=None, profile=None):
"""
Get ticket of virtual machine of passed object type.

vm_name
The name of the virtual machine which has tickets. VM names can be
found in ``vmware_vm.list``.

ticket_type
Type of ticket - device, guestControl, guestIntegrity, mks, or webmks.

See https://vdc-download.vmware.com/vmwb-repository/dcr-public/3325c370-b58c-4799-99ff-58ae3baac1bd/45789cc5-aba1-48bc-a320-5e35142b50af/doc/vim.VirtualMachine.TicketType.html

salt '*' vmware_vm.get_mks_ticket vm_name=vm01 ticket_type=webmks
"""
if service_instance is None:
Expand Down