Update EC2 inventory to include changes from ansible/devel, add tag_none to tags group, update vpc group naming to match ansible/devel.

This commit is contained in:
Chris Church 2015-02-11 01:45:47 -05:00
parent bb3732b2c1
commit 2d6986bb53
3 changed files with 16 additions and 7 deletions

View File

@ -1669,7 +1669,8 @@ class InventoryUpdatesTest(BaseTransactionTest):
self.assertTrue('security_groups' in child_names)
self.assertTrue('tags' in child_names)
self.assertTrue('images' in child_names)
self.assertTrue('tag_none' in child_names)
self.assertFalse('tag_none' in child_names)
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
self.assertFalse('instances' in child_names)
# Make sure we clean up the cache path when finished (when one is not
# provided explicitly via source_vars).
@ -1708,7 +1709,7 @@ class InventoryUpdatesTest(BaseTransactionTest):
# Skip vpcs as selected inventory may or may not have any.
child_names = self.group.children.filter(active=True).values_list('name', flat=True)
self.assertTrue('ec2' in child_names)
self.assertTrue('tag_none' in child_names)
self.assertFalse('tag_none' in child_names)
self.assertTrue('regions' in child_names)
self.assertTrue(self.group.children.get(name='regions').children.filter(active=True).count())
self.assertTrue('types' in child_names)
@ -1719,6 +1720,7 @@ class InventoryUpdatesTest(BaseTransactionTest):
self.assertTrue(self.group.children.get(name='security_groups').children.filter(active=True).count())
self.assertTrue('tags' in child_names)
self.assertTrue(self.group.children.get(name='tags').children.filter(active=True).count())
self.assertTrue('tag_none' in self.group.children.get(name='tags').children.values_list('name', flat=True))
self.assertTrue('images' in child_names)
self.assertTrue(self.group.children.get(name='images').children.filter(active=True).count())
self.assertTrue('instances' in child_names)

View File

@ -79,6 +79,7 @@ group_by_key_pair = True
group_by_vpc_id = True
group_by_security_group = True
group_by_tag_keys = True
group_by_tag_none = True
group_by_route53_names = True
group_by_rds_engine = True
group_by_rds_parameter_group = True

View File

@ -412,9 +412,13 @@ class Ec2Inventory(object):
# Select the best destination address
if instance.subnet_id:
dest = getattr(instance, self.vpc_destination_variable)
dest = getattr(instance, self.vpc_destination_variable, None)
if dest is None:
dest = getattr(instance, 'tags').get(self.vpc_destination_variable, None)
else:
dest = getattr(instance, self.destination_variable)
dest = getattr(instance, self.destination_variable, None)
if dest is None:
dest = getattr(instance, 'tags').get(self.destination_variable, None)
if not dest:
# Skip instances we cannot address (e.g. private VPC subnet)
@ -474,7 +478,7 @@ class Ec2Inventory(object):
# Inventory: Group by VPC
if self.group_by_vpc_id and instance.vpc_id:
vpc_id_name = self.to_safe(instance.vpc_id)
vpc_id_name = self.to_safe('vpc_id_' + instance.vpc_id)
self.push(self.inventory, vpc_id_name, dest)
if self.nested_groups:
self.push_group(self.inventory, 'vpcs', vpc_id_name)
@ -512,6 +516,8 @@ class Ec2Inventory(object):
# Global Tag: instances without tags
if self.group_by_tag_none and len(instance.tags) == 0:
self.push(self.inventory, 'tag_none', dest)
if self.nested_groups:
self.push_group(self.inventory, 'tags', 'tag_none')
# Global Tag: tag all EC2 instances
self.push(self.inventory, 'ec2', dest)
@ -566,7 +572,7 @@ class Ec2Inventory(object):
# Inventory: Group by VPC
if self.group_by_vpc_id and instance.subnet_group and instance.subnet_group.vpc_id:
vpc_id_name = self.to_safe(instance.subnet_group.vpc_id)
vpc_id_name = self.to_safe('vpc_id_' + instance.subnet_group.vpc_id)
self.push(self.inventory, vpc_id_name, dest)
if self.nested_groups:
self.push_group(self.inventory, 'vpcs', vpc_id_name)
@ -707,7 +713,7 @@ class Ec2Inventory(object):
# try updating the cache
self.do_api_calls_update_cache()
if not self.args.host in self.index:
# host migh not exist anymore
# host might not exist anymore
return self.json_format_dict({}, True)
(region, instance_id) = self.index[self.args.host]