Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rhosqeauto/InfraRed into old_install
Browse files Browse the repository at this point in the history
  • Loading branch information
Yair Fried committed Mar 2, 2016
2 parents f82839d + bc86ce4 commit c4be975
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 97 deletions.
40 changes: 22 additions & 18 deletions cli/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ConfigParser

import clg
import os
import yaml

import clg
import yamlordereddictloader

from cli import exceptions
from cli import utils

Expand Down Expand Up @@ -43,38 +44,41 @@ class SpecManager(object):

SPEC_EXTENSION = '.spec'

def __init__(self, config):
self.config = config
@classmethod
def parse_args(cls, module_name, config, args=None):
"""
Looks for all the specs for specified module
and parses the commandline input arguments accordingly.
def get_specs(self, module_name):
:param module_name: the module name: installer|provisioner|tester
"""
cmd = clg.CommandLine(cls._get_specs(module_name, config))
return cmd.parse(args)

@classmethod
def _get_specs(cls, module_name, config):
"""
Gets specs files as a dict from settings/<module_name> folder.
:param module_name: the module name: installer|provisioner|tester
"""
res = {}
for spec_file in self.__get_all_specs(subfolder=module_name):
spec = yaml.load(open(spec_file))
for spec_file in cls._get_all_specs(config, subfolder=module_name):
spec = yaml.load(open(spec_file),
Loader=yamlordereddictloader.Loader)
utils.dict_merge(res, spec)
return res

def parse_args(self, module_name, args=None):
"""
Looks for all the specs for specified module
and parses the commandline input arguments accordingly.
"""
cmd = clg.CommandLine(self.get_specs(module_name))
return cmd.parse(args)

def __get_all_specs(self, subfolder=None):
@classmethod
def _get_all_specs(cls, config, subfolder=None):
root_dir = utils.validate_settings_dir(
self.config.get('defaults', 'settings'))
config.get('defaults', 'settings'))
if subfolder:
root_dir = os.path.join(root_dir, subfolder)

res = []
for dirpath, _, filenames in os.walk(root_dir):
for filename in [f for f in filenames
if f.endswith(self.SPEC_EXTENSION)]:
if f.endswith(cls.SPEC_EXTENSION)]:
res.append(os.path.join(dirpath, filename))

return res
Expand Down
18 changes: 15 additions & 3 deletions cli/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def __init__(self, env_var):


class IRPlaybookFailedException(IRException):
def __init__(self, playbook):
super(self.__class__, self).__init__(
'Playbook "%s" failed!' % playbook)
def __init__(self, playbook, message=""):
msg = 'Playbook "%s" failed!' % playbook
msg = msg + message if message else msg
super(self.__class__, self).__init__(msg)


class IRYAMLConstructorError(IRException):
Expand All @@ -57,3 +58,14 @@ def __init__(self, trace_message):

class IRNotImplemented(IRException):
pass


class IRUnknownApplicationException(IRException):
"""
This exceptions is raised when unknown application is
started by user.
"""
def __init__(self, app_name):
self.app_name = app_name
super(IRUnknownApplicationException, self).__init__(
"Application is unknown: '{}'".format(app_name))
6 changes: 4 additions & 2 deletions cli/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ def execute_ansible(playbook, args):

print ""
if len(failed_hosts) > 0:
raise Exception(2)
raise exceptions.IRPlaybookFailedException(
playbook, "Failed hosts: %s" % failed_hosts)
if len(unreachable_hosts) > 0:
raise Exception(3)
raise exceptions.IRPlaybookFailedException(
playbook, "Unreachable hosts: %s" % unreachable_hosts)


def ansible_wrapper(args):
Expand Down
5 changes: 2 additions & 3 deletions cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def get_args(entry_point, args=None):
"""
:return args: return loaded arguments from CLI
"""

spec_manager = conf.SpecManager(CONF)
args = spec_manager.parse_args(entry_point, args=args)
# todo(obaranov) remove one-line method.
args = conf.SpecManager.parse_args(entry_point, CONF, args=args)
return args


Expand Down
Loading

0 comments on commit c4be975

Please sign in to comment.