VMware: Add managed object id in VM facts (#53523)
Fixes: #53372 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
ae373d5a10
commit
2007a79952
4 changed files with 34 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- Add managed object identifier (moId) and vim reference (vimref) of virtual machine in guest facts (https://github.com/ansible/ansible/issues/53372).
|
|
@ -302,6 +302,8 @@ def gather_vm_facts(content, vm):
|
|||
'snapshots': [],
|
||||
'current_snapshot': None,
|
||||
'vnc': {},
|
||||
'moid': vm._moId,
|
||||
'vimref': "vim.VirtualMachine:%s" % vm._moId,
|
||||
}
|
||||
|
||||
# facts that may or may not exist
|
||||
|
@ -1378,6 +1380,13 @@ class PyVmomi(object):
|
|||
self._deepmerge(result, tmp)
|
||||
else:
|
||||
result[prop] = self._jsonify(getattr(obj, prop))
|
||||
# To match gather_vm_facts output
|
||||
prop_name = prop
|
||||
if prop.lower() == '_moid':
|
||||
prop_name = 'moid'
|
||||
elif prop.lower() == '_vimref':
|
||||
prop_name = 'vimref'
|
||||
result[prop_name] = result[prop]
|
||||
except (AttributeError, KeyError):
|
||||
self.module.fail_json(msg="Property '{0}' not found.".format(prop))
|
||||
else:
|
||||
|
|
|
@ -133,6 +133,20 @@ EXAMPLES = '''
|
|||
properties: ["config.hardware.memoryMB", "guest.disk", "overallStatus"]
|
||||
delegate_to: localhost
|
||||
register: facts
|
||||
|
||||
- name: Gather Managed object ID (moid) from a guest using the vSphere API output schema for REST Calls
|
||||
vmware_guest_facts:
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
validate_certs: no
|
||||
datacenter: "{{ datacenter_name }}"
|
||||
name: "{{ vm_name }}"
|
||||
schema: "vsphere"
|
||||
properties:
|
||||
- _moId
|
||||
delegate_to: localhost
|
||||
register: moid_facts
|
||||
'''
|
||||
|
||||
RETURN = """
|
||||
|
@ -192,7 +206,9 @@ instance:
|
|||
"tags": [
|
||||
"backup"
|
||||
],
|
||||
"vnc": {}
|
||||
"vnc": {},
|
||||
"moid": "vm-42",
|
||||
"vimref": "vim.VirtualMachine:vm-42"
|
||||
}
|
||||
"""
|
||||
|
||||
|
@ -251,7 +267,6 @@ def main():
|
|||
instance = pyv.gather_facts(vm)
|
||||
else:
|
||||
instance = pyv.to_json(vm, module.params['properties'])
|
||||
|
||||
if module.params.get('tags'):
|
||||
if not HAS_VCLOUD:
|
||||
module.fail_json(msg="Unable to find 'vCloud Suite SDK' Python library which is required."
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
- "guest_facts_0001['instance']['hw_folder'] is defined"
|
||||
- "guest_facts_0001['instance']['guest_question'] is defined"
|
||||
- "guest_facts_0001['instance']['guest_consolidation_needed'] is defined"
|
||||
- "guest_facts_0001['instance']['moid'] is defined"
|
||||
- "guest_facts_0001['instance']['vimref'] is defined"
|
||||
- "'portgroup_portkey' in guest_facts_0001['instance']['hw_eth0']"
|
||||
- "'portgroup_key' in guest_facts_0001['instance']['hw_eth0']"
|
||||
- "guest_facts_0001['instance']['instance_uuid'] is defined"
|
||||
|
@ -91,6 +93,8 @@
|
|||
- "guest_facts_0002b['instance']['config']['hardware']['memoryMB'] is defined"
|
||||
- "guest_facts_0002b['instance']['config']['hardware']['numCoresPerSocket'] is not defined"
|
||||
- "guest_facts_0002b['instance']['guest']['toolsVersion'] is defined"
|
||||
- "guest_facts_0001['instance']['moid'] is defined"
|
||||
- "guest_facts_0001['instance']['vimref'] is defined"
|
||||
- "guest_facts_0002b['instance']['overallStatus'] is not defined"
|
||||
|
||||
# Testcase 0003: Get details about virtual machines without snapshots using UUID
|
||||
|
@ -182,3 +186,5 @@
|
|||
- "guest_facts_0005['instance']['guest_consolidation_needed'] is defined"
|
||||
- "guest_facts_0005['instance']['instance_uuid'] is defined"
|
||||
- "guest_facts_0005['instance']['instance_uuid'] == vm1_instance_uuid"
|
||||
- "guest_facts_0001['instance']['moid'] is defined"
|
||||
- "guest_facts_0001['instance']['vimref'] is defined"
|
Loading…
Reference in a new issue