Skip to content

Commit

Permalink
[GCE] inventory script supports paginated API results. (ansible#18554)
Browse files Browse the repository at this point in the history
The inventory script now supports paginated results.  This means that inventory may exceed 500 instances.
  • Loading branch information
supertom authored and mattclay committed Dec 8, 2016
1 parent 7d3e2b2 commit 9400ba1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion contrib/inventory/gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,22 @@ def do_api_calls_update_cache(self):
self.cache.write_to_cache(data)
self.inventory = data

def list_nodes(self):
all_nodes = []
params, more_results = {'maxResults': 500}, True
while more_results:
self.driver.connection.gce_params=params
all_nodes.extend(self.driver.list_nodes())
more_results = 'pageToken' in params
return all_nodes

def group_instances(self, zones=None):
'''Group all instances'''
groups = {}
meta = {}
meta["hostvars"] = {}

for node in self.driver.list_nodes():
for node in self.list_nodes():

# This check filters on the desired instance states defined in the
# config file with the instance_states config option.
Expand Down

0 comments on commit 9400ba1

Please sign in to comment.