From 4a2673482bf14583c40a3019dd5e94b55ec3f0c0 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 26 Mar 2013 22:28:35 -0400 Subject: [PATCH] Update the inventory script to follow the new variabledata schema. This is untested and may need revisions. --- lib/main/management/commands/acom_inventory.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/main/management/commands/acom_inventory.py b/lib/main/management/commands/acom_inventory.py index 831145f859..6c03d34a7c 100755 --- a/lib/main/management/commands/acom_inventory.py +++ b/lib/main/management/commands/acom_inventory.py @@ -44,12 +44,14 @@ class Command(NoArgsCommand): groups = {} for group in inventory.groups.all(): # FIXME: Check if group is active? + group_info = { 'hosts': list(group.hosts.values_list('name', flat=True)), - # FIXME: Include host vars here? - 'vars': dict(group.variable_data.values_list('name', 'data')), 'children': list(group.children.values_list('name', flat=True)), } + if group.variables is not None: + group_info['vars'] = json.loads(group.variables.data) + group_info = dict(filter(lambda x: bool(x[1]), group_info.items())) if group_info.keys() in ([], ['hosts']): groups[group.name] = group_info.get('hosts', []) @@ -65,9 +67,11 @@ class Command(NoArgsCommand): host = inventory.hosts.get(name=hostname) except Host.DoesNotExist: raise CommandError('Host %s not found in the given inventory' % hostname) - hostvars = dict(host.variable_data.values_list('name', 'data')) + hostvars = {} + if host.variables is not None: + hostvars = json.loads(host.variables.data) # FIXME: Do we also need to include variables defined for groups of which - # this host is a member? + # this host is a member? (MPD: pretty sure we don't!) self.stdout.write(json.dumps(hostvars, indent=indent)) def handle_noargs(self, **options):