[GCE] inventory script supports paginated API results. (#18554)
The inventory script now supports paginated results. This means that inventory may exceed 500 instances.
This commit is contained in:
parent
7d3e2b2121
commit
9400ba1728
1 changed files with 10 additions and 1 deletions
|
@ -390,13 +390,22 @@ class GceInventory(object):
|
||||||
self.cache.write_to_cache(data)
|
self.cache.write_to_cache(data)
|
||||||
self.inventory = 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):
|
def group_instances(self, zones=None):
|
||||||
'''Group all instances'''
|
'''Group all instances'''
|
||||||
groups = {}
|
groups = {}
|
||||||
meta = {}
|
meta = {}
|
||||||
meta["hostvars"] = {}
|
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
|
# This check filters on the desired instance states defined in the
|
||||||
# config file with the instance_states config option.
|
# config file with the instance_states config option.
|
||||||
|
|
Loading…
Reference in a new issue