Skip to content

Commit

Permalink
Added subnetwork parameter to inventory instance dictionary. (ansible…
Browse files Browse the repository at this point in the history
  • Loading branch information
supertom authored and gundalow committed Apr 26, 2017
1 parent dde383a commit 9d5c399
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contrib/inventory/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- gce_tags
- gce_metadata
- gce_network
- gce_subnetwork
When run in --list mode, instances are grouped by the following categories:
- zone:
Expand Down Expand Up @@ -292,6 +293,7 @@ def get_gce_driver(self):
secrets_found = True
except:
pass

if not secrets_found:
args = [
self.config.get('gce','gce_service_account_email_address'),
Expand Down Expand Up @@ -350,6 +352,9 @@ def node_to_dict(self, inst):
md[entry['key']] = entry['value']

net = inst.extra['networkInterfaces'][0]['network'].split('/')[-1]
subnet = None
if 'subnetwork' in inst.extra['networkInterfaces'][0]:
subnet = inst.extra['networkInterfaces'][0]['subnetwork'].split('/')[-1]
# default to exernal IP unless user has specified they prefer internal
if self.ip_type == 'internal':
ssh_host = inst.private_ips[0]
Expand All @@ -370,6 +375,7 @@ def node_to_dict(self, inst):
'gce_tags': inst.extra['tags'],
'gce_metadata': md,
'gce_network': net,
'gce_subnetwork': subnet,
# Hosts don't have a public name, so we add an IP
'ansible_ssh_host': ssh_host
}
Expand Down

0 comments on commit 9d5c399

Please sign in to comment.