From 9400ba17284958e23012afdcb180fb65e753e5fd Mon Sep 17 00:00:00 2001 From: Tom Melendez Date: Tue, 6 Dec 2016 13:22:01 -0800 Subject: [PATCH] [GCE] inventory script supports paginated API results. (#18554) The inventory script now supports paginated results. This means that inventory may exceed 500 instances. --- contrib/inventory/gce.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/inventory/gce.py b/contrib/inventory/gce.py index bbb2426660..87f1e8e811 100755 --- a/contrib/inventory/gce.py +++ b/contrib/inventory/gce.py @@ -390,13 +390,22 @@ class GceInventory(object): 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.