예제 #1
0
import socket
import sys

import click

from treadmill import cli
from treadmill import context
from treadmill import dnsutils
from treadmill import exc
from treadmill import restclient
from treadmill import subproc

_LOGGER = logging.getLogger(__name__)

_ON_EXCEPTIONS = cli.handle_exceptions([
    (exc.InvalidInputError, None),
])


def _run(command):
    """Run command."""
    success = False
    try:
        output = subproc.check_output(command, )
        _LOGGER.info('Success.')
        success = True

    except subproc.CalledProcessError as err:
        output = str(err)
        _LOGGER.error('Failure.')
        cli.out(output)
예제 #2
0
import logging

import click

from treadmill import cli
from treadmill import context
from treadmill import restclient


_LOGGER = logging.getLogger(__name__)

_EXCEPTIONS = []
_EXCEPTIONS.extend(restclient.CLI_REST_EXCEPTIONS)

_ON_EXCEPTIONS = cli.handle_exceptions(_EXCEPTIONS)

_REST_PATH = '/image/'


def init():  # pylint: disable=R0912
    """Configures application monitor"""
    formatter = cli.make_formatter('aws_image')
    ctx = {}

    @click.group()
    @click.option('--api', help='API url to use.',
                  metavar='URL',
                  envvar='TREADMILL_RESTAPI')
    def image_group(api):
        """Manage Treadmill app monitor configuration"""
예제 #3
0
    elif err.dn.find('ou=dns-servers') != -1:
        rsrc_type = 'dns configuration'
    else:
        rsrc_type = None

    if rsrc_type is None:
        rsrc_type = 'resource [%s]' % err.dn
    click.echo('Error: %s does not exist.' % rsrc_type, err=True)


ON_EXCEPTIONS = cli.handle_exceptions([
    (ldap3.LDAPInsufficientAccessRightsResult, 'Error: access denied.'),
    (ldap3.LDAPNoSuchObjectResult, _handle_no_such_ldap_obj),
    (kazoo.exceptions.NoAuthError, 'Error: not authorized.'),
    (kazoo.exceptions.NoNodeError, 'Error: resource does not exist.'),
    (restclient.NotAuthorizedError, cli.handle_not_authorized),
    (restclient.MaxRequestRetriesError, None),
    (dns.exception.Timeout, 'Error: DNS server timeout.'),
    (dns.resolver.NXDOMAIN, 'Error: Could not resolve DNS record.'),
    (dns.resolver.YXDOMAIN, 'Error: DNS error.'),
    (context.ContextError, None),
])


def init():
    """Return top level command handler."""

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