1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Update vmware implementation to new agreements

This commit is contained in:
AlanCoding 2020-04-21 22:49:20 -04:00
parent 50197c6a12
commit 68f5482c42
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
4 changed files with 84 additions and 58 deletions

View File

@ -2265,42 +2265,50 @@ class vmware(PluginFileInjector):
def inventory_as_dict(self, inventory_update, private_data_dir): def inventory_as_dict(self, inventory_update, private_data_dir):
ret = super(vmware, self).inventory_as_dict(inventory_update, private_data_dir) ret = super(vmware, self).inventory_as_dict(inventory_update, private_data_dir)
ret['strict'] = False ret['strict'] = False
ret['properties'] = [ # Documentation of props, see
"name", # https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/scenario_guides/vmware_scenarios/vmware_inventory_vm_attributes.rst
UPPERCASE_PROPS = [
"ansible_ssh_host", "ansible_ssh_host",
"ansible_host", "ansible_host",
"ansible_uuid", "ansible_uuid",
"availablefield", "availableField", # optional?
"capability", # nested properties "configIssue", # optional?
"config", # nested properties "configStatus", # optional?
"configissue", "customValue", # optional?
"configstatus",
"customvalue",
"datastore", "datastore",
"effectiverole", "effectiveRole", # optional?
"guest", # nested properties "guestHeartbeatStatus", # optonal?
"guestheartbeatstatus", "layout", # optional?
"layout", "layoutEx", # optional?
"layoutex",
"name", "name",
"network", "network",
"overallstatus", "overallStatus", # optional?
"parentvapp", "parentVApp", # optional?
"permission", "permission",
"recenttask", "recentTask", # optional?
"resourcepool", "resourcePool",
"rootsnapshot", "rootSnapshot", # optional?
"runtime", # nested properties "snapshot", # optional
"snapshot",
"storage", # nested properties
"summary", # repeat of other properties
"tag", "tag",
"triggeredalarmstate", "triggeredAlarmState",
"value", "value"
] ]
# ret['properties'] = ["all"] # causes UnknownWsdlTypeError exception NESTED_PROPS = [
ret['with_nested_properties'] = True "capability",
ret['property_name_format'] = 'lower_case' "config",
"guest",
"runtime",
"storage",
"summary", # repeat of other properties
]
ret['properties'] = UPPERCASE_PROPS + NESTED_PROPS
ret['compose'] = {}
for prop in UPPERCASE_PROPS:
if prop == prop.lower():
continue
ret['compose'][prop.lower()] = prop
# ret['with_nested_properties'] = True # only dacrystal/topic/vmware-inventory-plugin-enhancements
# ret['property_name_format'] = 'lower_case' # only dacrystal/topic/vmware-inventory-plugin-property-format
# process custom options # process custom options
vmware_opts = dict(inventory_update.source_vars_dict.items()) vmware_opts = dict(inventory_update.source_vars_dict.items())
@ -2320,16 +2328,18 @@ class vmware(PluginFileInjector):
host_pattern = vmware_opts.get('host_pattern') # not working in script host_pattern = vmware_opts.get('host_pattern') # not working in script
if host_pattern: if host_pattern:
pass # does not appear to have an option for this stripped_hp = host_pattern.replace('{', '').replace('}', '').strip() # make best effort
ret['compose']['ansible_host'] = stripped_hp
ret['compose']['ansible_ssh_host'] = stripped_hp
host_filters = vmware_opts.get('host_filters') host_filters = vmware_opts.get('host_filters')
if host_filters: if host_filters:
ret.setdefault('host_filters', []) ret.setdefault('filters', [])
for hf in host_filters.split(','): for hf in host_filters.split(','):
striped_hf = hf.replace('{', '').replace('}', '').strip() # make best effort striped_hf = hf.replace('{', '').replace('}', '').strip() # make best effort
if not striped_hf: if not striped_hf:
continue continue
ret['host_filters'].append(striped_hf) ret['filters'].append(striped_hf)
groupby_patterns = vmware_opts.get('groupby_patterns') groupby_patterns = vmware_opts.get('groupby_patterns')
if groupby_patterns: if groupby_patterns:

View File

@ -1,43 +1,55 @@
host_filters: compose:
- config.name == "only_my_server" availablefield: availableField
- somevar == "bar" configissue: configIssue
configstatus: configStatus
customvalue: customValue
effectiverole: effectiveRole
guestheartbeatstatus: guestHeartbeatStatus
layoutex: layoutEx
overallstatus: overallStatus
parentvapp: parentVApp
recenttask: recentTask
resourcepool: resourcePool
rootsnapshot: rootSnapshot
triggeredalarmstate: triggeredAlarmState
filters:
- config.zoo == "DC0_H0_VM0"
hostnames:
- config.foo
keyed_groups: keyed_groups:
- key: fouo - key: config.asdf
prefix: '' prefix: ''
separator: '' separator: ''
plugin: community.vmware.vmware_vm_inventory plugin: community.vmware.vmware_vm_inventory
properties: properties:
- name
- ansible_ssh_host - ansible_ssh_host
- ansible_host - ansible_host
- ansible_uuid - ansible_uuid
- availablefield - availableField
- capability - configIssue
- config - configStatus
- configissue - customValue
- configstatus
- customvalue
- datastore - datastore
- effectiverole - effectiveRole
- guest - guestHeartbeatStatus
- guestheartbeatstatus
- layout - layout
- layoutex - layoutEx
- name - name
- network - network
- overallstatus - overallStatus
- parentvapp - parentVApp
- permission - permission
- recenttask - recentTask
- resourcepool - resourcePool
- rootsnapshot - rootSnapshot
- runtime
- snapshot - snapshot
- tag
- triggeredAlarmState
- value
- capability
- config
- guest
- runtime
- storage - storage
- summary - summary
- tag
- triggeredalarmstate
- value
property_name_format: lower_case
strict: false strict: false
with_nested_properties: true

View File

@ -5,6 +5,7 @@ username = fooo
password = fooo password = fooo
server = https://foo.invalid server = https://foo.invalid
base_source_var = value_of_var base_source_var = value_of_var
host_filters = {{ config.name == "only_my_server" }},{{ somevar == "bar"}} alias_pattern = {{ config.foo }}
groupby_patterns = fouo host_filters = {{ config.zoo == "DC0_H0_VM0" }}
groupby_patterns = {{ config.asdf }}

View File

@ -53,6 +53,9 @@ INI_TEST_VARS = {
'rhv': {}, # there are none 'rhv': {}, # there are none
'tower': {}, # there are none 'tower': {}, # there are none
'vmware': { 'vmware': {
'alias_pattern': "{{ config.foo }}",
'host_filters': '{{ config.zoo == "DC0_H0_VM0" }}',
'groupby_patterns': "{{ config.asdf }}",
# setting VMWARE_VALIDATE_CERTS is duplicated with env var # setting VMWARE_VALIDATE_CERTS is duplicated with env var
}, },
'azure_rm': { 'azure_rm': {