diff options
author | Jhon Honce <jhonce@redhat.com> | 2015-02-13 12:14:13 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2015-02-13 12:14:13 -0700 |
commit | 2a179f6cdfb7ae39ab8dc9605418310da4dc4271 (patch) | |
tree | c4778da0441215356eaac09b3027ef4a2ea3bda1 | |
parent | 698acd553375caf64cee821d8c1af3e468f9f4dd (diff) | |
parent | 4a1e5c0b18260355a258384b8510db4361b83f1c (diff) | |
download | openshift-2a179f6cdfb7ae39ab8dc9605418310da4dc4271.tar.gz openshift-2a179f6cdfb7ae39ab8dc9605418310da4dc4271.tar.bz2 openshift-2a179f6cdfb7ae39ab8dc9605418310da4dc4271.tar.xz openshift-2a179f6cdfb7ae39ab8dc9605418310da4dc4271.zip |
Merge pull request #59 from twiest/pr
Updated to the latest gce.py from upstream. It includes _meta and hostvars!!!
-rwxr-xr-x | inventory/gce/gce.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/inventory/gce/gce.py b/inventory/gce/gce.py index c8eeb43ab..e77178c16 100755 --- a/inventory/gce/gce.py +++ b/inventory/gce/gce.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Copyright 2013 Google Inc. # # This file is part of Ansible @@ -103,11 +103,13 @@ class GceInventory(object): # Just display data for specific host if self.args.host: 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) sys.exit(0) # Otherwise, assume user wants all instances grouped - print(self.json_format_dict(self.group_instances())) + print(self.json_format_dict(self.group_instances(), + pretty=self.args.pretty)) sys.exit(0) def get_gce_driver(self): @@ -187,6 +189,8 @@ class GceInventory(object): help='List instances (default: True)') parser.add_argument('--host', action='store', help='Get all information about an instance') + parser.add_argument('--pretty', action='store_true', default=False, + help='Pretty format (default: False)') self.args = parser.parse_args() @@ -229,9 +233,14 @@ class GceInventory(object): def group_instances(self): '''Group all instances''' groups = {} + meta = {} + meta["hostvars"] = {} + for node in self.driver.list_nodes(): name = node.name + meta["hostvars"][name] = self.node_to_dict(node) + zone = node.extra['zone'].name if groups.has_key(zone): groups[zone].append(name) else: groups[zone] = [name] @@ -259,6 +268,9 @@ class GceInventory(object): stat = 'status_%s' % status.lower() if groups.has_key(stat): groups[stat].append(name) else: groups[stat] = [name] + + groups["_meta"] = meta + return groups def json_format_dict(self, data, pretty=False): |