VMware: blacklist custom fields in vmware_inventory.py (#36877)

* Provide the ability to blacklist custom fields from having groups created for them.

* Updated configuration parameter name
pull/42865/head
tod-uma 6 years ago committed by Abhijeet Kasurde
parent 8d194fa5f7
commit 1a0330488f

@ -93,6 +93,13 @@ password=vmware
# vmware_tag_ prefix is the default and consistent with ec2_tag_
#custom_field_group_prefix = vmware_tag_
# You can blacklist custom fields so that they are not included in the
# groupby_custom_field option. This is useful when you have custom fields that
# have values that are unique to individual hosts. Timestamps for example.
# The groupby_custom_field_excludes option should be a comma separated list of custom
# field keys to be blacklisted.
#groupby_custom_field_excludes=<custom_field_1>,<custom_field_2>,<custom_field_3>
# The script attempts to recurse into virtualmachine objects and serialize
# all available data. The serialization is comprehensive but slow. If the
# vcenter environment is large and the desired properties are known, create

@ -99,6 +99,7 @@ class VMWareInventory(object):
host_filters = []
skip_keys = []
groupby_patterns = []
groupby_custom_field_excludes = []
safe_types = [bool, str, float, None] + list(integer_types)
iter_types = [dict, list]
@ -230,6 +231,7 @@ class VMWareInventory(object):
'groupby_patterns': '{{ guest.guestid }},{{ "templates" if config.template else "guests"}}',
'lower_var_keys': True,
'custom_field_group_prefix': 'vmware_tag_',
'groupby_custom_field_excludes': '',
'groupby_custom_field': False}
}
@ -304,8 +306,12 @@ class VMWareInventory(object):
groupby_pattern += "}}"
self.groupby_patterns.append(groupby_pattern)
self.debugl('groupby patterns are %s' % self.groupby_patterns)
temp_groupby_custom_field_excludes = config.get('vmware', 'groupby_custom_field_excludes')
self.groupby_custom_field_excludes = [x.strip('"') for x in [y.strip("'") for y in temp_groupby_custom_field_excludes.split(",")]]
self.debugl('groupby exclude strings are %s' % self.groupby_custom_field_excludes)
# Special feature to disable the brute force serialization of the
# virtulmachine objects. The key name for these properties does not
# virtual machine objects. The key name for these properties does not
# matter because the values are just items for a larger list.
if config.has_section('properties'):
self.guest_props = []
@ -496,6 +502,8 @@ class VMWareInventory(object):
for tv in v['customvalue']:
newkey = None
field_name = self.custom_fields[tv['key']] if tv['key'] in self.custom_fields else tv['key']
if field_name in self.groupby_custom_field_excludes:
continue
values = []
keylist = map(lambda x: x.strip(), tv['value'].split(','))
for kl in keylist:

Loading…
Cancel
Save