mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 22:16:00 -03:30
Set the GCE_ZONE env variable to source_regions.
Fix when an empty key is provided and add tests for validate_ssh_private_key
This commit is contained in:
@@ -117,8 +117,10 @@ class GceInventory(object):
|
||||
pretty=self.args.pretty))
|
||||
sys.exit(0)
|
||||
|
||||
zones = self.parse_env_zones()
|
||||
|
||||
# Otherwise, assume user wants all instances grouped
|
||||
print(self.json_format_dict(self.group_instances(),
|
||||
print(self.json_format_dict(self.group_instances(zones),
|
||||
pretty=self.args.pretty))
|
||||
sys.exit(0)
|
||||
|
||||
@@ -190,6 +192,14 @@ class GceInventory(object):
|
||||
)
|
||||
return gce
|
||||
|
||||
def parse_env_zones(self):
|
||||
'''returns a list of comma seperated zones parsed from the GCE_ZONE environment variable.
|
||||
If provided, this will be used to filter the results of the grouped_instances call'''
|
||||
import csv
|
||||
reader = csv.reader([os.environ.get('GCE_ZONE',"")], skipinitialspace=True)
|
||||
zones = [r for r in reader]
|
||||
return [z for z in zones[0]]
|
||||
|
||||
def parse_cli_args(self):
|
||||
''' Command line argument processing '''
|
||||
|
||||
@@ -240,7 +250,7 @@ class GceInventory(object):
|
||||
except Exception as e:
|
||||
return None
|
||||
|
||||
def group_instances(self):
|
||||
def group_instances(self, zones=None):
|
||||
'''Group all instances'''
|
||||
groups = {}
|
||||
meta = {}
|
||||
@@ -252,6 +262,12 @@ class GceInventory(object):
|
||||
meta["hostvars"][name] = self.node_to_dict(node)
|
||||
|
||||
zone = node.extra['zone'].name
|
||||
|
||||
# To avoid making multiple requests per zone
|
||||
# we list all nodes and then filter the results
|
||||
if zones and zone not in zones:
|
||||
continue
|
||||
|
||||
if groups.has_key(zone): groups[zone].append(name)
|
||||
else: groups[zone] = [name]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user