VMware: make properties configurable (#53050)

This allows user to control set of properties which can be included
in the hostvars.

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/59534/head
Abhijeet Kasurde 5 years ago committed by GitHub
parent 1010363c0b
commit 281307b492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,6 +60,19 @@ DOCUMENTATION = '''
- 'https://code.vmware.com/web/sdk/65/vsphere-automation-python'
default: False
type: boolean
properties:
description:
- Specify the list of VMware schema properties associated with the VM.
- These properties will be populated in hostvars of the given VM.
- Each value in the list specifies the path to a specific property in VM object.
type: list
default: [ 'name', 'config.cpuHotAddEnabled', 'config.cpuHotRemoveEnabled',
'config.instanceUuid', 'config.hardware.numCPU', 'config.template',
'config.name', 'guest.hostName', 'guest.ipAddress',
'guest.guestId', 'guest.guestState', 'runtime.maxMemoryUsage',
'customValue'
]
version_added: "2.9"
'''
EXAMPLES = '''
@ -71,6 +84,18 @@ EXAMPLES = '''
password: Esxi@123$%
validate_certs: False
with_tags: True
# Gather minimum set of properties for VMware guest
plugin: vmware_vm_inventory
strict: False
hostname: 10.65.223.31
username: administrator@vsphere.local
password: Esxi@123$%
validate_certs: False
with_tags: False
properties:
- 'name'
- 'guest.ipAddress'
'''
import ssl
@ -432,24 +457,9 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
def _populate_host_properties(self, vm_obj, current_host):
# Load VM properties in host_vars
vm_properties = [
'name',
'config.cpuHotAddEnabled',
'config.cpuHotRemoveEnabled',
'config.instanceUuid',
'config.hardware.numCPU',
'config.template',
'config.name',
'guest.hostName',
'guest.ipAddress',
'guest.guestId',
'guest.guestState',
'runtime.maxMemoryUsage',
'customValue',
]
field_mgr = []
if self.pyv.content.customFieldsManager:
field_mgr = self.pyv.content.customFieldsManager.field
vm_properties = self.get_option('properties') or []
field_mgr = self.pyv.content.customFieldsManager.field
for vm_prop in vm_properties:
if vm_prop == 'customValue':

Loading…
Cancel
Save