summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2015-05-14 17:19:55 -0400
committerKenny Woodson <kwoodson@redhat.com>2015-05-14 17:19:55 -0400
commit3f97a57f0c862976b4fd1570eb00c22c8484c137 (patch)
tree8e0e0f28c9614c154da597adf572fd7ab0e97cda
parentff96174e119f0b176580249ec2d022b46b63e074 (diff)
parent88c7ed4ad437f6705d91e4c1ffb2e88c71fb7db4 (diff)
downloadopenshift-3f97a57f0c862976b4fd1570eb00c22c8484c137.tar.gz
openshift-3f97a57f0c862976b4fd1570eb00c22c8484c137.tar.bz2
openshift-3f97a57f0c862976b4fd1570eb00c22c8484c137.tar.xz
openshift-3f97a57f0c862976b4fd1570eb00c22c8484c137.zip
Merge pull request #227 from kwoodson/ec2_library
Update to call multi_ec2 as library for command line tools.
-rwxr-xr-xbin/ohi9
-rw-r--r--bin/openshift_ansible/awsutil.py40
l---------bin/openshift_ansible/multi_ec2.py1
-rwxr-xr-xbin/oscp8
-rwxr-xr-xbin/ossh8
5 files changed, 11 insertions, 55 deletions
diff --git a/bin/ohi b/bin/ohi
index 24a027be2..6f162ac13 100755
--- a/bin/ohi
+++ b/bin/ohi
@@ -17,13 +17,10 @@ from openshift_ansible.awsutil import ArgumentError
CONFIG_MAIN_SECTION = 'main'
CONFIG_HOST_TYPE_ALIAS_SECTION = 'host_type_aliases'
-CONFIG_INVENTORY_OPTION = 'inventory'
-
class Ohi(object):
def __init__(self):
- self.inventory = None
self.host_type_aliases = {}
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
@@ -35,7 +32,7 @@ class Ohi(object):
self.parse_cli_args()
self.parse_config_file()
- self.aws = awsutil.AwsUtil(self.inventory, self.host_type_aliases)
+ self.aws = awsutil.AwsUtil(self.host_type_aliases)
def run(self):
if self.args.list_host_types:
@@ -76,10 +73,6 @@ class Ohi(object):
config = ConfigParser.ConfigParser()
config.read(self.config_path)
- if config.has_section(CONFIG_MAIN_SECTION) and \
- config.has_option(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION):
- self.inventory = config.get(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION)
-
self.host_type_aliases = {}
if config.has_section(CONFIG_HOST_TYPE_ALIAS_SECTION):
for alias in config.options(CONFIG_HOST_TYPE_ALIAS_SECTION):
diff --git a/bin/openshift_ansible/awsutil.py b/bin/openshift_ansible/awsutil.py
index 8b365faa9..9df034f57 100644
--- a/bin/openshift_ansible/awsutil.py
+++ b/bin/openshift_ansible/awsutil.py
@@ -2,10 +2,9 @@
"""This module comprises Aws specific utility functions."""
-import subprocess
import os
-import json
import re
+from openshift_ansible import multi_ec2
class ArgumentError(Exception):
"""This class is raised when improper arguments are passed."""
@@ -22,11 +21,10 @@ class ArgumentError(Exception):
class AwsUtil(object):
"""This class contains the AWS utility functions."""
- def __init__(self, inventory_path=None, host_type_aliases=None):
+ def __init__(self, host_type_aliases=None):
"""Initialize the AWS utility class.
Keyword arguments:
- inventory_path -- the path to find the inventory script
host_type_aliases -- a list of aliases to common host-types (e.g. ex-node)
"""
@@ -35,15 +33,6 @@ class AwsUtil(object):
self.host_type_aliases = host_type_aliases
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
- if inventory_path is None:
- inventory_path = os.path.realpath(os.path.join(self.file_path, \
- '..', '..', 'inventory', \
- 'multi_ec2.py'))
-
- if not os.path.isfile(inventory_path):
- raise Exception("Inventory file not found [%s]" % inventory_path)
-
- self.inventory_path = inventory_path
self.setup_host_type_alias_lookup()
def setup_host_type_alias_lookup(self):
@@ -53,31 +42,16 @@ class AwsUtil(object):
for value in values:
self.alias_lookup[value] = key
-
-
- def get_inventory(self, args=None):
+ @staticmethod
+ def get_inventory(args=None):
"""Calls the inventory script and returns a dictionary containing the inventory."
Keyword arguments:
args -- optional arguments to pass to the inventory script
"""
- args = args or []
- cmd = [self.inventory_path]
-
- if args:
- cmd.extend(args)
-
- env = os.environ
-
- proc = subprocess.Popen(cmd, stderr=subprocess.PIPE,
- stdout=subprocess.PIPE, env=env)
-
- out, err = proc.communicate()
-
- if proc.returncode != 0:
- raise RuntimeError(err)
-
- return json.loads(out.strip())
+ mec2 = multi_ec2.MultiEc2(args)
+ mec2.run()
+ return mec2.result
def get_environments(self):
"""Searches for env tags in the inventory and returns all of the envs found."""
diff --git a/bin/openshift_ansible/multi_ec2.py b/bin/openshift_ansible/multi_ec2.py
new file mode 120000
index 000000000..660a0418e
--- /dev/null
+++ b/bin/openshift_ansible/multi_ec2.py
@@ -0,0 +1 @@
+../../inventory/multi_ec2.py \ No newline at end of file
diff --git a/bin/oscp b/bin/oscp
index 68691ec22..f6dd2ad88 100755
--- a/bin/oscp
+++ b/bin/oscp
@@ -11,11 +11,9 @@ import ConfigParser
from openshift_ansible import awsutil
CONFIG_MAIN_SECTION = 'main'
-CONFIG_INVENTORY_OPTION = 'inventory'
class Oscp(object):
def __init__(self):
- self.inventory = None
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
# Default the config path to /etc
@@ -29,7 +27,7 @@ class Oscp(object):
# parse host and user
self.process_host()
- self.aws = awsutil.AwsUtil(self.inventory)
+ self.aws = awsutil.AwsUtil()
# get a dict of host inventory
if self.args.refresh_cache:
@@ -56,10 +54,6 @@ class Oscp(object):
config = ConfigParser.ConfigParser()
config.read(self.config_path)
- if config.has_section(CONFIG_MAIN_SECTION) and \
- config.has_option(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION):
- self.inventory = config.get(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION)
-
def parse_cli_args(self):
parser = argparse.ArgumentParser(description='Openshift Online SSH Tool.')
parser.add_argument('-e', '--env',
diff --git a/bin/ossh b/bin/ossh
index 196430e13..855c5d8b4 100755
--- a/bin/ossh
+++ b/bin/ossh
@@ -11,11 +11,9 @@ import ConfigParser
from openshift_ansible import awsutil
CONFIG_MAIN_SECTION = 'main'
-CONFIG_INVENTORY_OPTION = 'inventory'
class Ossh(object):
def __init__(self):
- self.inventory = None
self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))
# Default the config path to /etc
@@ -26,7 +24,7 @@ class Ossh(object):
self.parse_cli_args()
self.parse_config_file()
- self.aws = awsutil.AwsUtil(self.inventory)
+ self.aws = awsutil.AwsUtil()
if self.args.refresh_cache:
self.get_hosts(True)
@@ -54,10 +52,6 @@ class Ossh(object):
config = ConfigParser.ConfigParser()
config.read(self.config_path)
- if config.has_section(CONFIG_MAIN_SECTION) and \
- config.has_option(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION):
- self.inventory = config.get(CONFIG_MAIN_SECTION, CONFIG_INVENTORY_OPTION)
-
def parse_cli_args(self):
parser = argparse.ArgumentParser(description='Openshift Online SSH Tool.')
parser.add_argument('-e', '--env', action="store",