diff options
author | Thomas Wiest <twiest@users.noreply.github.com> | 2015-03-11 17:10:39 -0400 |
---|---|---|
committer | Thomas Wiest <twiest@users.noreply.github.com> | 2015-03-11 17:10:39 -0400 |
commit | a14cfe60471b053175d0bc225caa4fe1353b4873 (patch) | |
tree | d6eddf119b4c3557f91f1cbc6bbf201c803dd7de /bin/ansibleutil.py | |
parent | fc2dd1cd305077ab9b6ee20fffb1bfe472c25985 (diff) | |
parent | 492a196b1c5449eaa04f8398a63f3f70baf608f9 (diff) | |
download | openshift-a14cfe60471b053175d0bc225caa4fe1353b4873.tar.gz openshift-a14cfe60471b053175d0bc225caa4fe1353b4873.tar.bz2 openshift-a14cfe60471b053175d0bc225caa4fe1353b4873.tar.xz openshift-a14cfe60471b053175d0bc225caa4fe1353b4873.zip |
Merge pull request #111 from twiest/opssh
added opssh
Diffstat (limited to 'bin/ansibleutil.py')
-rw-r--r-- | bin/ansibleutil.py | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/bin/ansibleutil.py b/bin/ansibleutil.py index b9f37726e..b527ab140 100644 --- a/bin/ansibleutil.py +++ b/bin/ansibleutil.py @@ -1,13 +1,27 @@ # vim: expandtab:tabstop=4:shiftwidth=4 import subprocess -import sys import os import json import re class AnsibleUtil(object): def __init__(self): + self.host_type_aliases = { + 'legacy-openshift-broker': ['broker', 'ex-srv'], + 'openshift-node': ['node', 'ex-node'], + 'openshift-messagebus': ['msg'], + 'openshift-customer-database': ['mongo'], + 'openshift-website-proxy': ['proxy'], + 'openshift-community-website': ['drupal'], + 'package-mirror': ['mirror'], + } + + self.alias_lookup = {} + for key, values in self.host_type_aliases.iteritems(): + for value in values: + self.alias_lookup[value] = key + self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) self.multi_ec2_path = os.path.realpath(os.path.join(self.file_path, '..','inventory','multi_ec2.py')) @@ -39,8 +53,22 @@ class AnsibleUtil(object): if m: envs.append(m.group(1)) + envs.sort() return envs + def get_host_types(self): + pattern = re.compile(r'^tag_host-type_(.*)') + + host_types = [] + inv = self.get_inventory() + for key in inv.keys(): + m = pattern.match(key) + if m: + host_types.append(m.group(1)) + + host_types.sort() + return host_types + def get_security_groups(self): pattern = re.compile(r'^security_group_(.*)') @@ -51,6 +79,7 @@ class AnsibleUtil(object): if m: groups.append(m.group(1)) + groups.sort() return groups def build_host_dict_by_env(self, args=[]): @@ -65,3 +94,41 @@ class AnsibleUtil(object): return inst_by_env + # Display host_types + def print_host_types(self): + host_types = self.get_host_types() + ht_format_str = "%35s" + alias_format_str = "%-20s" + combined_format_str = ht_format_str + " " + alias_format_str + + print + print combined_format_str % ('Host Types', 'Aliases') + print combined_format_str % ('----------', '-------') + + for ht in host_types: + aliases = [] + if ht in self.host_type_aliases: + aliases = self.host_type_aliases[ht] + print combined_format_str % (ht, ", ".join(aliases)) + else: + print ht_format_str % ht + print + + # Convert host-type aliases to real a host-type + def resolve_host_type(self, host_type): + if self.alias_lookup.has_key(host_type): + return self.alias_lookup[host_type] + return host_type + + def gen_env_host_type_tag(self, host_type, env): + """Generate the environment host type tag + """ + host_type = self.resolve_host_type(host_type) + return "tag_env-host-type_%s-%s" % (env, host_type) + + def get_host_list(self, host_type, env): + """Get the list of hosts from the inventory using host-type and environment + """ + inv = self.get_inventory() + host_type_tag = self.gen_env_host_type_tag(host_type, env) + return inv[host_type_tag] |