Add additional facts to the fact gathering of vmware (#31632)
Adds facts about datastores, esxi_host, vm files, ha state, question, is_template, consolidation status and hw_files. Also, adds integration tests for vmware fact enhancement.
This commit is contained in:
parent
bf7f56f413
commit
5962337332
2 changed files with 59 additions and 0 deletions
|
@ -277,8 +277,16 @@ def gather_vm_facts(content, vm):
|
||||||
'hw_cores_per_socket': vm.config.hardware.numCoresPerSocket,
|
'hw_cores_per_socket': vm.config.hardware.numCoresPerSocket,
|
||||||
'hw_memtotal_mb': vm.config.hardware.memoryMB,
|
'hw_memtotal_mb': vm.config.hardware.memoryMB,
|
||||||
'hw_interfaces': [],
|
'hw_interfaces': [],
|
||||||
|
'hw_datastores': [],
|
||||||
|
'hw_files': [],
|
||||||
|
'hw_esxi_host': None,
|
||||||
|
'hw_guest_ha_state': vm.summary.runtime.dasVmProtection,
|
||||||
|
'hw_is_template': vm.config.template,
|
||||||
|
'hw_folder': None,
|
||||||
'guest_tools_status': _get_vm_prop(vm, ('guest', 'toolsRunningStatus')),
|
'guest_tools_status': _get_vm_prop(vm, ('guest', 'toolsRunningStatus')),
|
||||||
'guest_tools_version': _get_vm_prop(vm, ('guest', 'toolsVersion')),
|
'guest_tools_version': _get_vm_prop(vm, ('guest', 'toolsVersion')),
|
||||||
|
'guest_question': vm.summary.runtime.question,
|
||||||
|
'guest_consolidation_needed': vm.summary.runtime.consolidationNeeded,
|
||||||
'ipv4': None,
|
'ipv4': None,
|
||||||
'ipv6': None,
|
'ipv6': None,
|
||||||
'annotation': vm.config.annotation,
|
'annotation': vm.config.annotation,
|
||||||
|
@ -287,6 +295,47 @@ def gather_vm_facts(content, vm):
|
||||||
'current_snapshot': None,
|
'current_snapshot': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# facts that may or may not exist
|
||||||
|
if vm.summary.runtime.host:
|
||||||
|
host = vm.summary.runtime.host
|
||||||
|
facts['hw_esxi_host'] = host.summary.config.name
|
||||||
|
|
||||||
|
datastores = vm.datastore
|
||||||
|
for ds in datastores:
|
||||||
|
facts['hw_datastores'].append(ds.info.name)
|
||||||
|
|
||||||
|
try:
|
||||||
|
files = vm.config.files
|
||||||
|
layout = vm.layout
|
||||||
|
if files:
|
||||||
|
facts['hw_files'] = [files.vmPathName]
|
||||||
|
for item in layout.snapshot:
|
||||||
|
for snap in item.snapshotFile:
|
||||||
|
facts['hw_files'].append(files.snapshotDirectory + snap)
|
||||||
|
for item in layout.configFile:
|
||||||
|
facts['hw_files'].append(os.path.dirname(files.vmPathName) + '/' + item)
|
||||||
|
for item in vm.layout.logFile:
|
||||||
|
facts['hw_files'].append(files.logDirectory + item)
|
||||||
|
for item in vm.layout.disk:
|
||||||
|
for disk in item.diskFile:
|
||||||
|
facts['hw_files'].append(disk)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
folder = vm.parent
|
||||||
|
if folder:
|
||||||
|
foldername = folder.name
|
||||||
|
fp = folder.parent
|
||||||
|
# climb back up the tree to find our path, stop before the root folder
|
||||||
|
while fp is not None and fp.name is not None and fp != content.rootFolder:
|
||||||
|
foldername = fp.name + '/' + foldername
|
||||||
|
try:
|
||||||
|
fp = fp.parent
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
foldername = '/' + foldername
|
||||||
|
facts['hw_folder'] = foldername
|
||||||
|
|
||||||
cfm = content.customFieldsManager
|
cfm = content.customFieldsManager
|
||||||
# Resolve custom values
|
# Resolve custom values
|
||||||
for value_obj in vm.summary.customValue:
|
for value_obj in vm.summary.customValue:
|
||||||
|
|
|
@ -42,6 +42,13 @@
|
||||||
|
|
||||||
- set_fact: dc1="{{ datacenters['json'][0] }}"
|
- set_fact: dc1="{{ datacenters['json'][0] }}"
|
||||||
|
|
||||||
|
- name: get a list of hosts from vcsim
|
||||||
|
uri:
|
||||||
|
url: http://{{ vcsim }}:5000/govc_find?filter=H
|
||||||
|
register: hosts
|
||||||
|
|
||||||
|
- set_fact: h1="{{ hosts['json'][0] }}"
|
||||||
|
|
||||||
- name: get a list of virtual machines from vcsim
|
- name: get a list of virtual machines from vcsim
|
||||||
uri:
|
uri:
|
||||||
url: http://{{ vcsim }}:5000/govc_find?filter=VM
|
url: http://{{ vcsim }}:5000/govc_find?filter=VM
|
||||||
|
@ -68,6 +75,8 @@
|
||||||
- "guest_facts_0001['instance']['hw_name'] == vm1 | basename"
|
- "guest_facts_0001['instance']['hw_name'] == vm1 | basename"
|
||||||
- "guest_facts_0001['instance']['hw_product_uuid'] is defined"
|
- "guest_facts_0001['instance']['hw_product_uuid'] is defined"
|
||||||
- "guest_facts_0001['instance']['hw_cores_per_socket'] is defined"
|
- "guest_facts_0001['instance']['hw_cores_per_socket'] is defined"
|
||||||
|
- "guest_facts_0001['instance']['hw_datastores'] is defined"
|
||||||
|
- "guest_facts_0001['instance']['hw_esxi_host'] == h1 | basename"
|
||||||
|
|
||||||
- set_fact: vm1_uuid="{{ guest_facts_0001['instance']['hw_product_uuid'] }}"
|
- set_fact: vm1_uuid="{{ guest_facts_0001['instance']['hw_product_uuid'] }}"
|
||||||
|
|
||||||
|
@ -154,3 +163,4 @@
|
||||||
- "guest_facts_0004['instance']['snapshots'][0]['name'] == 'snap1'"
|
- "guest_facts_0004['instance']['snapshots'][0]['name'] == 'snap1'"
|
||||||
- "guest_facts_0004['instance']['snapshots'][1]['name'] == 'snap2'"
|
- "guest_facts_0004['instance']['snapshots'][1]['name'] == 'snap2'"
|
||||||
- "guest_facts_0004['instance']['current_snapshot']['name'] == 'snap2'"
|
- "guest_facts_0004['instance']['current_snapshot']['name'] == 'snap2'"
|
||||||
|
- "guest_facts_0002['instance']['hw_folder'] == vm1 | dirname"
|
||||||
|
|
Loading…
Reference in a new issue