From c903e64ad5d6fb2c36fa35ec87ecf75a4518b115 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Wed, 11 Feb 2015 03:24:17 -0500 Subject: [PATCH] Remove tags, add group for templates to VMware inventory script. --- awx/main/tests/inventory.py | 2 +- awx/plugins/inventory/vmware.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/awx/main/tests/inventory.py b/awx/main/tests/inventory.py index 0d685de289..5fb75bffd5 100644 --- a/awx/main/tests/inventory.py +++ b/awx/main/tests/inventory.py @@ -1811,7 +1811,7 @@ class InventoryUpdatesTest(BaseTransactionTest): # in host variables. for host in self.inventory.hosts.all(): self.assertFalse(host.instance_id, host.instance_id) - if host.enabled: + if host.enabled and host.variables_dict.get('vmware_ipAddress', ''): self.assertTrue(host.variables_dict.get('ansible_ssh_host', '')) # Test a field that should be present for host systems, not VMs. self.assertFalse(host.variables_dict.get('vmware_product_name', '')) diff --git a/awx/plugins/inventory/vmware.py b/awx/plugins/inventory/vmware.py index d72bed09b6..92030d66e5 100755 --- a/awx/plugins/inventory/vmware.py +++ b/awx/plugins/inventory/vmware.py @@ -192,7 +192,6 @@ class VMwareInventory(object): ''' host_info = { 'name': host.name, - 'tag': host.tag, } for attr in ('datastore', 'network', 'vm'): try: @@ -221,7 +220,6 @@ class VMwareInventory(object): ''' vm_info = { 'name': vm.name, - 'tag': vm.tag, } for attr in ('datastore', 'network'): try: @@ -313,10 +311,6 @@ class VMwareInventory(object): if not self.guests_only: self._add_host(inv, 'all', host.name) self._add_host(inv, hw_group, host.name) - if host.tag: # FIXME: Is this always a string? - host_tag = 'vmware_%s' % host.tag - self._add_host(inv, host_tag, host.name) - host_info = self._get_host_info(host) if meta_hostvars: inv['_meta']['hostvars'][host.name] = host_info @@ -326,9 +320,6 @@ class VMwareInventory(object): for vm in host.vm: self._add_host(inv, 'all', vm.name) self._add_host(inv, vm_group, vm.name) - if vm.tag: # FIXME: Is this always a string? - vm_tag = 'vmware_%s' % vm.tag - self._add_host(inv, vm_tag, vm.name) vm_info = self._get_vm_info(vm) if meta_hostvars: inv['_meta']['hostvars'][vm.name] = vm_info @@ -360,6 +351,12 @@ class VMwareInventory(object): self._add_child(inv, 'guests', vm_guestId) self._add_host(inv, vm_guestId, vm.name) + # Group all VM templates. + vm_template = vm_info.get('vmware_template', False) + if vm_template: + self._add_child(inv, vm_group, 'templates') + self._add_host(inv, 'templates', vm.name) + self._put_cache(cache_name, inv) return inv