summaryrefslogtreecommitdiffstats
path: root/bin/ohi
diff options
context:
space:
mode:
Diffstat (limited to 'bin/ohi')
-rwxr-xr-xbin/ohi87
1 files changed, 55 insertions, 32 deletions
diff --git a/bin/ohi b/bin/ohi
index d679edcfb..d71a4c4b1 100755
--- a/bin/ohi
+++ b/bin/ohi
@@ -1,14 +1,16 @@
#!/usr/bin/env python
+'''
+Ohi = Openshift Host Inventory
+
+This script provides an easy way to look at your host inventory.
+
+This depends on multi_inventory being setup correctly.
+'''
# vim: expandtab:tabstop=4:shiftwidth=4
import argparse
-import traceback
import sys
import os
-import re
-import tempfile
-import time
-import subprocess
import ConfigParser
from openshift_ansible import awsutil
@@ -20,6 +22,9 @@ CONFIG_HOST_TYPE_ALIAS_SECTION = 'host_type_aliases'
class Ohi(object):
+ '''
+ Class for managing openshift host inventory
+ '''
def __init__(self):
self.host_type_aliases = {}
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
@@ -35,26 +40,26 @@ class Ohi(object):
self.aws = awsutil.AwsUtil(self.host_type_aliases)
def run(self):
+ '''
+ Call into awsutil and retrieve the desired hosts and environments
+ '''
+
if self.args.list_host_types:
self.aws.print_host_types()
return 0
- hosts = None
- if self.args.host_type is not None and \
- self.args.env is not None:
- # Both env and host-type specified
- hosts = self.aws.get_host_list(host_type=self.args.host_type, \
- envs=self.args.env)
+ if self.args.v3:
+ version = '3'
+ elif self.args.all_versions:
+ version = 'all'
+ else:
+ version = '2'
- if self.args.host_type is None and \
- self.args.env is not None:
- # Only env specified
- hosts = self.aws.get_host_list(envs=self.args.env)
-
- if self.args.host_type is not None and \
- self.args.env is None:
- # Only host-type specified
- hosts = self.aws.get_host_list(host_type=self.args.host_type)
+ hosts = self.aws.get_host_list(clusters=self.args.cluster,
+ host_type=self.args.host_type,
+ envs=self.args.env,
+ version=version,
+ cached=self.args.cache_only)
if hosts is None:
# We weren't able to determine what they wanted to do
@@ -69,6 +74,9 @@ class Ohi(object):
return 0
def parse_config_file(self):
+ '''
+ Parse the config file for ohi
+ '''
if os.path.isfile(self.config_path):
config = ConfigParser.ConfigParser()
config.read(self.config_path)
@@ -85,23 +93,34 @@ class Ohi(object):
parser = argparse.ArgumentParser(description='OpenShift Host Inventory')
- parser.add_argument('--list-host-types', default=False, action='store_true',
- help='List all of the host types')
+ parser.add_argument('--list-host-types', default=False, action='store_true', help='List all of the host types')
+ parser.add_argument('--list', default=False, action='store_true', help='List all hosts')
- parser.add_argument('-e', '--env', action="store",
- help="Which environment to use")
+ parser.add_argument('-c', '--cluster', action="append", help="Which clusterid to use")
+ parser.add_argument('-e', '--env', action="append", help="Which environment to use")
- parser.add_argument('-t', '--host-type', action="store",
- help="Which host type to use")
+ parser.add_argument('-t', '--host-type', action="store", help="Which host type to use")
- parser.add_argument('-l', '--user', action='store', default=None,
- help='username')
+ parser.add_argument('-l', '--user', action='store', default=None, help='username')
+ parser.add_argument('--cache-only', action='store_true', default=False,
+ help='Retrieve the host inventory by cache only. Default is false.')
- self.args = parser.parse_args()
+ parser.add_argument('--v2', action='store_true', default=True,
+ help='Specify the openshift version. Default is 2')
+ parser.add_argument('--v3', action='store_true', default=False,
+ help='Specify the openshift version.')
-if __name__ == '__main__':
+ parser.add_argument('--all-versions', action='store_true', default=False,
+ help='Specify the openshift version. Return all versions')
+
+ self.args = parser.parse_args()
+
+def main():
+ '''
+ Ohi will do its work here
+ '''
if len(sys.argv) == 1:
print "\nError: No options given. Use --help to see the available options\n"
sys.exit(0)
@@ -110,5 +129,9 @@ if __name__ == '__main__':
ohi = Ohi()
exitcode = ohi.run()
sys.exit(exitcode)
- except ArgumentError as e:
- print "\nError: %s\n" % e.message
+ except ArgumentError as err:
+ print "\nError: %s\n" % err.message
+
+if __name__ == '__main__':
+ main()
+