diff options
Diffstat (limited to 'bin/openshift_ansible/awsutil.py')
-rw-r--r-- | bin/openshift_ansible/awsutil.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/bin/openshift_ansible/awsutil.py b/bin/openshift_ansible/awsutil.py index 945e6a20c..11651f087 100644 --- a/bin/openshift_ansible/awsutil.py +++ b/bin/openshift_ansible/awsutil.py @@ -31,6 +31,7 @@ class AwsUtil(object): host_type_aliases -- a list of aliases to common host-types (e.g. ex-node) """ + self.alias_lookup = {} host_type_aliases = host_type_aliases or {} self.host_type_aliases = host_type_aliases @@ -40,7 +41,6 @@ class AwsUtil(object): def setup_host_type_alias_lookup(self): """Sets up the alias to host-type lookup table.""" - self.alias_lookup = {} for key, values in self.host_type_aliases.iteritems(): for value in values: self.alias_lookup[value] = key @@ -101,6 +101,20 @@ class AwsUtil(object): host_types.sort() return host_types + def get_sub_host_types(self): + """Searches for sub-host-type tags in the inventory and returns all sub-host-types found.""" + pattern = re.compile(r'^oo_subhosttype_(.*)') + + sub_host_types = [] + inv = self.get_inventory() + for key in inv.keys(): + matched = pattern.match(key) + if matched: + sub_host_types.append(matched.group(1)) + + sub_host_types.sort() + return sub_host_types + def get_security_groups(self): """Searches for security_groups in the inventory and returns all SGs found.""" pattern = re.compile(r'^security_group_(.*)') @@ -123,13 +137,13 @@ class AwsUtil(object): inst_by_env = {} for _, host in inv['_meta']['hostvars'].items(): # If you don't have an environment tag, we're going to ignore you - if 'ec2_tag_environment' not in host: + if 'oo_environment' not in host: continue - if host['ec2_tag_environment'] not in inst_by_env: - inst_by_env[host['ec2_tag_environment']] = {} - host_id = "%s:%s" % (host['ec2_tag_Name'], host['ec2_id']) - inst_by_env[host['ec2_tag_environment']][host_id] = host + if host['oo_environment'] not in inst_by_env: + inst_by_env[host['oo_environment']] = {} + host_id = "%s:%s" % (host['oo_name'], host['oo_id']) + inst_by_env[host['oo_environment']][host_id] = host return inst_by_env @@ -192,9 +206,15 @@ class AwsUtil(object): host_type = self.resolve_host_type(host_type) return "oo_hosttype_%s" % host_type + @staticmethod + def gen_sub_host_type_tag(sub_host_type): + """Generate the host type tag + """ + return "oo_subhosttype_%s" % sub_host_type + # This function uses all of these params to perform a filters on our host inventory. # pylint: disable=too-many-arguments - def get_host_list(self, clusters=None, host_type=None, envs=None, version=None, cached=False): + def get_host_list(self, clusters=None, host_type=None, sub_host_type=None, envs=None, version=None, cached=False): """Get the list of hosts from the inventory using host-type and environment """ retval = set([]) @@ -229,6 +249,9 @@ class AwsUtil(object): if host_type: retval.intersection_update(inv.get(self.gen_host_type_tag(host_type, version), [])) + if sub_host_type: + retval.intersection_update(inv.get(self.gen_sub_host_type_tag(sub_host_type), [])) + if version != 'all': retval.intersection_update(inv.get(AwsUtil.gen_version_tag(version), [])) |