Update to latest GCE inventory module

This commit is contained in:
Matthew Jones
2015-10-12 11:35:27 -04:00
parent e75f1890e1
commit d382bf6f4f

View File

@@ -66,7 +66,7 @@ Examples:
$ ansible -i gce.py us-central1-a -m shell -a "/bin/uname -a" $ ansible -i gce.py us-central1-a -m shell -a "/bin/uname -a"
Use the GCE inventory script to print out instance specific information Use the GCE inventory script to print out instance specific information
$ plugins/inventory/gce.py --host my_instance $ contrib/inventory/gce.py --host my_instance
Author: Eric Johnson <erjohnso@google.com> Author: Eric Johnson <erjohnso@google.com>
Version: 0.0.1 Version: 0.0.1
@@ -112,9 +112,9 @@ class GceInventory(object):
# Just display data for specific host # Just display data for specific host
if self.args.host: if self.args.host:
print self.json_format_dict(self.node_to_dict( print(self.json_format_dict(self.node_to_dict(
self.get_instance(self.args.host)), self.get_instance(self.args.host)),
pretty=self.args.pretty) pretty=self.args.pretty))
sys.exit(0) sys.exit(0)
# Otherwise, assume user wants all instances grouped # Otherwise, assume user wants all instances grouped
@@ -237,7 +237,7 @@ class GceInventory(object):
'''Gets details about a specific instance ''' '''Gets details about a specific instance '''
try: try:
return self.driver.ex_get_node(instance_name) return self.driver.ex_get_node(instance_name)
except Exception, e: except Exception as e:
return None return None
def group_instances(self): def group_instances(self):
@@ -257,7 +257,10 @@ class GceInventory(object):
tags = node.extra['tags'] tags = node.extra['tags']
for t in tags: for t in tags:
tag = 'tag_%s' % t if t.startswith('group-'):
tag = t[6:]
else:
tag = 'tag_%s' % t
if groups.has_key(tag): groups[tag].append(name) if groups.has_key(tag): groups[tag].append(name)
else: groups[tag] = [name] else: groups[tag] = [name]