VMware: Add cluster fact in vmware_vm_facts (#44292)

This fix adds an additional fact about cluster in VM facts.

Fixes: #44101

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/44347/head
Abhijeet Kasurde 6 years ago committed by GitHub
parent 66a8711ecb
commit adf3ab5e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,7 @@ module: vmware_vm_facts
short_description: Return basic facts pertaining to a vSphere virtual machine guest
description:
- Return basic facts pertaining to a vSphere virtual machine guest.
- Cluster name as fact is added in version 2.7.
version_added: '2.0'
author:
- Joseph Callen (@jcpowermac)
@ -84,6 +85,21 @@ virtual_machines:
description: dictionary of virtual machines and their facts
returned: success
type: dict
sample:
{
"ubuntu_t": {
"cluster": null,
"esxi_hostname": "10.76.33.226",
"guest_fullname": "Ubuntu Linux (64-bit)",
"ip_address": "",
"mac_address": [
"00:50:56:87:a5:9a"
],
"power_state": "poweredOff",
"uuid": "4207072c-edd8-3bd5-64dc-903fd3a0db04",
"vm_network": {}
}
}
'''
try:
@ -135,8 +151,14 @@ class VmwareVmFacts(PyVmomi):
net_dict[device.macAddress]['ipv4'].append(ip_addr)
esxi_hostname = None
esxi_parent = None
if summary.runtime.host:
esxi_hostname = summary.runtime.host.summary.config.name
esxi_parent = summary.runtime.host.parent
cluster_name = None
if esxi_parent and isinstance(esxi_parent, vim.ClusterComputeResource):
cluster_name = summary.runtime.host.parent.name
virtual_machine = {
summary.config.name: {
@ -147,6 +169,7 @@ class VmwareVmFacts(PyVmomi):
"uuid": summary.config.uuid,
"vm_network": net_dict,
"esxi_hostname": esxi_hostname,
"cluster": cluster_name,
}
}

@ -50,5 +50,13 @@
assert:
that:
- "{{ item | basename in vm_facts_0001['virtual_machines'].keys()}}"
- "vm_facts_0001['virtual_machines'][item | basename]['cluster'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['esxi_hostname'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['guest_fullname'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['ip_address'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['mac_address'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['power_state'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['uuid'] is defined"
- "vm_facts_0001['virtual_machines'][item | basename]['vm_network'] is defined"
with_items:
- "{{ host_info_result['json'] }}"

Loading…
Cancel
Save