コード例 #1
0
def init():
    """Return top level command handler."""

    @click.group(cls=cli.make_commands('treadmill.sproc'))
    @click.option('--cgroup',
                  help='Create separate cgroup for the service.')
    @click.option('--logging-conf', default='daemon.json',
                  help='Logging config file to use.')
    @click.option('--cell', required=True,
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False)
    @click.option('--zookeeper', required=False,
                  envvar='TREADMILL_ZOOKEEPER',
                  callback=cli.handle_context_opt,
                  expose_value=False)
    @click.pass_context
    def run(ctx, cgroup, logging_conf):
        """Run system processes"""
        # Default logging to daemon.conf, at CRITICAL, unless --debug
        cli.init_logger(logging_conf)

        log_level = None
        if ctx.obj.get('logging.debug'):
            log_level = logging.DEBUG
        else:
            log_level = logging.DEBUG

        tl.set_log_level(log_level)

        if cgroup:
            _configure_service_cgroups(cgroup)

    return run
コード例 #2
0
ファイル: __init__.py プロジェクト: naidu-kjml/treadmill-aws
def init():
    """Return top level command handler"""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--aws-region',
                  required=False,
                  envvar='AWS_REGION',
                  callback=treadmill_aws.cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--aws-profile',
                  required=False,
                  envvar='AWS_PROFILE',
                  callback=treadmill_aws.cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ipa-domain',
                  required=False,
                  envvar='IPA_DOMAIN',
                  callback=treadmill_aws.cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ipa-certs',
                  required=False,
                  default='/etc/ipa/ca.crt',
                  callback=treadmill_aws.cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    def aws():
        """Manage AWS"""
        pass

    return aws
コード例 #3
0
ファイル: __init__.py プロジェクト: vrautela/treadmill
def init():
    """Return top level command handler"""
    @click.group(cls=cli.make_commands(__name__))
    def ldap():
        """Manage Treadmill LDAP data"""
        pass

    return ldap
コード例 #4
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.pass_context
    def run(_ctxp):
        """Manage Kerberos tickets."""

    return run
コード例 #5
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    def run():
        """Cross-cell supervision tools."""
        cli.init_logger('daemon.conf')

    return run
コード例 #6
0
def init():
    """Top level command handler."""

    @click.group(cls=cli.make_commands(__name__,
                                       chain=True,
                                       invoke_without_command=True))
    @click.option('--cell', required=True,
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False)
    @click.option('-v', '--verbose', count=True)
    @click.option('--db', help='Path to output sqlite db.')
    def run(verbose, db):
        """Run interactive checkout."""
        del verbose
        del db

    @run.resultcallback()
    def run_checkouts(checkouts, verbose, db):
        """Run interactive checkout."""
        # Too many nested blocks, need to refactor.
        #
        # pylint: disable=R1702
        common_args = {}

        if not db:
            db = ':memory:'
        conn = sqlite3.connect(db)

        for checkout in checkouts:
            try:
                metadata = checkout(conn=conn, **common_args)

                index_col = metadata.get('index')
                all_query = metadata['query']

                conn.commit()

                print(checkout.__doc__)

                if verbose >= 2:
                    _print_query(
                        conn,
                        all_query,
                        index_col=index_col
                    )

                row_factory = conn.row_factory
                conn.row_factory = sqlite3.Row

                for check in metadata.get('checks', []):
                    _run_check(conn, check, verbose, index_col)

            except Exception as err:  # pylint: disable=W0703
                _LOGGER.exception('%s', str(err))

    del run_checkouts
    return run
コード例 #7
0
ファイル: __init__.py プロジェクト: tolsis/treadmill-aws
def init():
    """Return top level command handler"""

    @click.group(cls=cli.make_commands(__name__))
    def aws():
        """Manage AWS"""
        pass

    return aws
コード例 #8
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.pass_context
    def run(_ctxp):
        """Manage Local node and container diagnostics.
        """

    return run
コード例 #9
0
def init():
    """Return top level command handler."""

    @click.group(cls=cli.make_commands(__name__))
    @click.option('--install-dir', required=True,
                  help='Target installation directory.',
                  envvar='TREADMILL_APPROOT')
    @click.option('--profile', required=False, help='Install profile.',
                  envvar='TREADMILL_PROFILE')
    @click.option('--cell', required=True, envvar='TREADMILL_CELL')
    @click.option('--config', required=False,
                  type=click.Path(exists=True, readable=True, allow_dash=True),
                  multiple=True)
    @click.option('--override', required=False, type=cli.DICT)
    @click.pass_context
    def install(ctx, install_dir, profile, cell, config, override):
        """Installs Treadmill."""
        if cell == '-':
            cell = None

        if cell:
            context.GLOBAL.cell = cell

        ctx.obj['PARAMS'] = {
            'cell': cell,
            'dns_domain': context.GLOBAL.dns_domain,
            'ldap_suffix': context.GLOBAL.ldap_suffix,
            'treadmill': dist.TREADMILL,
            'dir': install_dir,
            'profile': profile,
            'python': sys.executable,
            'python_path': os.getenv('PYTHONPATH', ''),
            'data': {},
        }

        for conf in config:
            if conf == '-':
                ctx.obj['PARAMS'].update(yaml.load(stream=sys.stdin))
            else:
                with io.open(conf, 'r') as fd:
                    ctx.obj['PARAMS'].update(yaml.load(stream=fd))

        if override:
            ctx.obj['PARAMS'].update(override)
            ctx.obj['PARAMS']['data'].update(override)

        # XXX: hack - templates use treadmillid, but it is defined as
        #      "username" in cell object.
        ctx.obj['PARAMS']['treadmillid'] = ctx.obj['PARAMS'].get('username')

        os.environ['TREADMILL'] = dist.TREADMILL

    return install
コード例 #10
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--aliases-path',
                  required=False,
                  envvar='TREADMILL_ALIASES_PATH',
                  help='Colon separated command alias paths')
    def node_group(aliases_path):
        """Manage Treadmill node data"""
        if aliases_path:
            os.environ['TREADMILL_ALIASES_PATH'] = aliases_path

    return node_group
コード例 #11
0
ファイル: __init__.py プロジェクト: vrautela/treadmill
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--cell',
                  help='Treadmill cell',
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False,
                  required=True)
    def run():
        """Report scheduler state."""
        pass

    return run
コード例 #12
0
def init():
    """Admin Cell CLI module"""
    @click.group(cls=cli.make_commands(__name__ + '.' +
                                       context.GLOBAL.get_profile_name()))
    @click.option('--cell',
                  required=True,
                  envvar='TREADMILL_CELL',
                  is_eager=True,
                  callback=cli.handle_context_opt,
                  expose_value=False)
    def cell_grp():
        """Manage treadmill cell.
        """

    return cell_grp
コード例 #13
0
def init():
    """Top level command handler."""
    @click.group(cls=cli.make_commands(__name__,
                                       chain=True,
                                       invoke_without_command=True))
    @click.option('--cell',
                  required=True,
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False)
    @click.option('--verbose', is_flag=True, default=False)
    @click.option('--html', is_flag=True, default=False)
    def run(verbose, html):
        """Run interactive checkout."""
        del verbose
        del html

    @run.resultcallback()
    def run_tests(tests, verbose, html):
        """Run interactive checkout."""
        verbosity = 1
        if verbose:
            verbosity = 2

        suite = unittest.TestSuite()
        loader = unittest.TestLoader()

        for factory in tests:
            tests = factory()
            if isinstance(tests, collections.Iterable):
                for test in tests:
                    suite.addTests(loader.loadTestsFromTestCase(test))
            else:
                suite.addTests(loader.loadTestsFromTestCase(tests))

        if html:
            runner = HtmlTestRunner.HtmlTestRunner(
                stream=sys.stdout,
                title='Treadmill cell checkout',
                description='Treamdill cell checkout tests')
        else:
            runner = unittest.TextTestRunner(verbosity=verbosity)

        runner.run(suite)

    del run_tests

    return run
コード例 #14
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--ldap',
                  required=False,
                  envvar='TREADMILL_LDAP',
                  type=cli.LIST,
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ldap-master',
                  required=False,
                  envvar='TREADMILL_LDAP_MASTER',
                  type=cli.LIST,
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ldap-user',
                  required=False,
                  envvar='TREADMILL_LDAP_USER',
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ldap-pwd',
                  required=False,
                  envvar='TREADMILL_LDAP_PWD',
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.option('--ldap-suffix',
                  required=False,
                  envvar='TREADMILL_LDAP_SUFFIX',
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.pass_context
    def run(ctx):
        """Admin commands."""
        cli.init_logger('admin.json')

        log_level = logging.WARN
        if ctx.obj.get('logging.debug'):
            log_level = logging.DEBUG

        tl.set_log_level(log_level)

    return run
コード例 #15
0
ファイル: __init__.py プロジェクト: bretttegartms/treadmill
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--cell',
                  help='Treadmill cell',
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False,
                  required=True)
    @click.option('--api-service-principal',
                  required=False,
                  envvar='TREADMILL_API_SERVICE_PRINCIPAL',
                  callback=cli.handle_context_opt,
                  help='API service principal for SPNEGO auth (default HTTP)',
                  expose_value=False)
    def run():
        """Report scheduler state.
        """

    return run
コード例 #16
0
ファイル: __init__.py プロジェクト: sattvic108/treadmill
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--cell',
                  help='Treadmill cell',
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False,
                  required=True)
    @click.option('--api',
                  help='Cell API URL',
                  metavar='URL',
                  envvar='TREADMILL_CELLAPI')
    @click.pass_context
    def run(ctx, api):
        """Report scheduler state."""
        if not ctx.obj:
            ctx.obj = {}  # Doesn't seem to exist in testing
        ctx.obj['api'] = api

    return run
コード例 #17
0
def init():
    """Return top level command handler."""

    @click.group(cls=cli.make_commands(__name__))
    @click.option('--ldap', envvar='TREADMILL_LDAP')
    @click.pass_context
    def run(ctx, ldap):
        """Admin commands."""
        cli.init_logger('admin.conf')

        log_level = logging.WARN
        if ctx.obj.get('logging.debug'):
            log_level = logging.DEBUG

        logging.getLogger('treadmill').setLevel(log_level)
        logging.getLogger().setLevel(log_level)

        if ldap:
            context.GLOBAL.ldap.url = ldap

    return run
コード例 #18
0
ファイル: __init__.py プロジェクト: sarveshsparab/treadmill
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands('treadmill.cli.admin.checkout',
                                       chain=True,
                                       invoke_without_command=True))
    @click.option('--outdir',
                  help='Output directory.',
                  required=True,
                  type=click.Path(exists=True))
    @click.option('--interval',
                  help='Interval between tests.',
                  required=False,
                  type=int,
                  default=60 * 5)
    @click.option('--randomize',
                  help='Optional random interval between tests.',
                  required=False,
                  type=int,
                  default=60 * 5)
    @click.option('--age', help='Max report age to keep.', default='1d')
    @click.option('--processor',
                  help='Result processing plugin.',
                  type=cli.LIST)
    def run(outdir, interval, randomize, age, processor):
        """Test treadmill infrastructure."""
        del outdir
        del interval
        del randomize
        del age
        del processor

    @run.resultcallback()
    def run_tests(tests, outdir, interval, randomize, age, processor):
        """Test treadmill infrastructure."""

        _LOGGER.info('Starting tests: %s', outdir)
        fs.mkdir_safe(outdir)

        while True:

            report_name = '%s.html' % datetime.datetime.isoformat(
                datetime.datetime.now())
            report_file = os.path.join(outdir, report_name)
            _LOGGER.info('Running checkout suite: %s', report_file)

            try:
                loader = unittest.TestLoader()
                suite = unittest.TestSuite()
                for factory in tests:

                    testcases = factory()
                    if not isinstance(testcases, collections.Iterable):
                        testcases = [testcases]

                    for test in testcases:
                        suite.addTests(loader.loadTestsFromTestCase(test))

                with io.open(report_file, 'wb') as stream:
                    runner = HTMLTestRunner.HTMLTestRunner(
                        stream=stream,
                        title='Treadmill cell checkout',
                        description='Treamdill cell checkout tests')
                    result = runner.run(suite)

            except Exception as err:  # pylint: disable=W0703
                _LOGGER.exception('Unhandled exception during checkout')

                result = None
                with io.open(report_file, 'wb') as stream:
                    stream.write(str(err).encode('utf8'))
                    traceback.print_exc(file=stream)

            for name in processor:
                plugin_manager.load('treadmill.checkout.processors',
                                    name).process(context.GLOBAL.cell,
                                                  report_file, result)

            _cleanup(outdir, age)

            total_interval = interval + random.randint(0, randomize)
            _LOGGER.info('Sleep for %s sec.', total_interval)
            time.sleep(total_interval)

    del run_tests
    return run
コード例 #19
0
ファイル: console.py プロジェクト: sarveshsparab/treadmill
from __future__ import print_function
from __future__ import unicode_literals

import logging
import logging.config

import click

from treadmill import cli

# Disable click warning for importing unicode_literals in python 2
click.disable_unicode_literals_warning = True


# TODO: add options to configure logging.
@click.group(cls=cli.make_commands('treadmill.cli'))
@click.option('--dns-domain',
              required=False,
              envvar='TREADMILL_DNS_DOMAIN',
              callback=cli.handle_context_opt,
              is_eager=True,
              expose_value=False)
@click.option('--dns-server',
              required=False,
              envvar='TREADMILL_DNS_SERVER',
              callback=cli.handle_context_opt,
              is_eager=True,
              expose_value=False)
@click.option('--ldap',
              required=False,
              envvar='TREADMILL_LDAP',
コード例 #20
0
ファイル: __init__.py プロジェクト: sarveshsparab/treadmill
def make_manage_multi_command(module_name, **click_args):
    """Make a Click multicommand from all submodules of the module."""

    old_multi = cli.make_multi_command(module_name, **click_args)
    new_multi = cli.make_commands(module_name, **click_args)

    class MCommand(click.MultiCommand):
        """Treadmill CLI driver."""

        def __init__(self, *args, **kwargs):
            self.old_multi = old_multi(*args, **kwargs)
            self.new_multi = new_multi(*args, **kwargs)
            if kwargs and click_args:
                kwargs.update(click_args)

            click.MultiCommand.__init__(self, *args, **kwargs)

        def list_commands(self, ctx):
            old_commands = set(self.old_multi.list_commands(ctx))
            new_commands = set(self.new_multi.list_commands(ctx))
            return sorted(old_commands | new_commands)

        def invoke(self, ctx):
            """
            invoke the command in a subprocess if it is executable
            otherwise use it in process
            """
            name = ctx.protected_args[0]
            try:
                module = plugin_manager.load(module_name, name)
            except KeyError:
                return super(MCommand, self).invoke(ctx)

            module_path = module.__file__
            if module_path.endswith('pyc'):
                module_path = module_path[:-1]
            # shebang doesn't work on windows
            # we use .cmd or a hardcoded default interpreter
            if os.name == 'nt':
                nt_path = module_path[:-2] + 'cmd'
                if os.path.exists(nt_path):
                    utils.sane_execvp(nt_path, [nt_path] + ctx.args)
                else:
                    _LOGGER.critical(
                        "%s cli is not supported on windows", name)
            else:
                is_exec = os.access(module_path, os.X_OK)
                if not is_exec:
                    return super(MCommand, self).invoke(ctx)
                utils.sane_execvp(module_path,
                                  [os.path.basename(module_path)] + ctx.args)

        def get_command(self, ctx, cmd_name):
            try:
                return self.new_multi.get_command(ctx, cmd_name)
            except click.UsageError:
                pass
            return self.old_multi.get_command(ctx, cmd_name)

        def format_commands(self, ctx, formatter):
            rows = []
            for subcommand in self.list_commands(ctx):
                entry_points = list(pkg_resources.iter_entry_points(
                    module_name, subcommand))
                # Try get the help with importlib if entry_point not found
                if not entry_points:
                    cmd = self.old_multi.get_command(ctx, subcommand)
                    if cmd is None:
                        continue
                    rows.append((subcommand, cmd.short_help or ''))
                else:
                    dist = entry_points[0].dist
                    if dist.has_metadata('cli_help'):
                        help_text = dist.get_metadata('cli_help')
                    else:
                        help_text = ''
                    rows.append((subcommand, help_text))

            if rows:
                with formatter.section('Commands'):
                    formatter.write_dl(rows)

    return MCommand
コード例 #21
0
def init():
    """Return top level command handler."""
    @click.group(cls=cli.make_commands(__name__))
    @click.option('--distro',
                  required=True,
                  help='Path to treadmill distro.',
                  envvar='TREADMILL_DISTRO')
    @click.option('--install-dir',
                  required=True,
                  help='Target installation directory.',
                  envvar='TREADMILL_APPROOT')
    @click.option('--cell',
                  required=True,
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=True)
    @click.option('--config',
                  required=False,
                  type=click.Path(exists=True, readable=True, allow_dash=True),
                  multiple=True)
    @click.option('--override', required=False, type=cli.DICT)
    @click.option('--profile',
                  required=True,
                  envvar='TREADMILL_PROFILE',
                  callback=cli.handle_context_opt,
                  is_eager=True,
                  expose_value=False)
    @click.pass_context
    def install(ctx, cell, distro, install_dir, config, override):
        """Installs Treadmill."""

        profile = context.GLOBAL.get_profile_name()

        ctx.obj['PARAMS'] = {
            'dns_domain': context.GLOBAL.dns_domain,
            'ldap_suffix': context.GLOBAL.ldap_suffix,
            'treadmill': distro,
            'dir': install_dir,
            'profile': profile,
            'python': sys.executable,
            'python_path': os.getenv('PYTHONPATH', ''),
        }
        if cell is not None:
            ctx.obj['PARAMS']['cell'] = context.GLOBAL.cell

        install_data = {}

        for conf in config:
            if conf == '-':
                conf_dict = yaml.load(stream=sys.stdin)
            else:
                with io.open(conf, 'r') as fd:
                    conf_dict = yaml.load(stream=fd)

            ctx.obj['PARAMS'].update(conf_dict)
            install_data.update(conf_dict.get('data', {}))

        if override:
            ctx.obj['PARAMS'].update(override)
            install_data.update(override)

        # Store the intall data in the context.
        # TODO: This is a terrible terrible mess.
        ctx.obj['PARAMS'].update(install_data)
        ctx.obj['PARAMS']['data'] = install_data

        # XXX: templates use treadmillid, but it is defined as "username" in
        #      cell object.
        ctx.obj['PARAMS']['treadmillid'] = ctx.obj['PARAMS'].get('username')

        os.environ['TREADMILL'] = distro

    return install