示例#1
0
文件: commands.py 项目: rmoorman/noel
def logs_command(args):
    """Gets (or streams) the logs for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')
    pods = k8s.pods(params={'labelSelector': 'noel-app={}'.format(args.app)})

    if not pods['items']:
        logger.error('No running pods found for app {}'.format(args.app))
        return False

    pod = pods['items'].pop()
    logger.info('Using pod {}'.format(pod['metadata']['name']))

    if args.follow:
        logger.warning('Streaming logs. Press ctrl+c to quit.')

    try:
        it = k8s.logs(pod['metadata']['name'],
                      container='noel-app',
                      lines=args.lines,
                      follow=args.follow)

        for log in it:
            print(log)

    except KeyboardInterrupt:
        pass
示例#2
0
文件: main.py 项目: CodeJuan/noel
def run(args):
    k8s = Kubernetes(args.kubernetes_url, namespace='noel')
    wait_for_kubernetes(k8s)

    keys = get_host_keys(k8s)

    if keys:
        logger.info('Existing ssh host keys found.')
        write_ssh_host_keys(args.destination, keys)
        return

    logger.warning('No existing ssh host keys. Generating keys.')
    keys = generate_ssh_host_keys(args.destination)

    try:
        put_host_keys(k8s, keys)
        logger.info('Host keys saved to Kubernetes.')
    except KubernetesError as e:
        if e.httperror.response.status_code == 409:
            logger.error(
                'Conflict while writing ssh keys to Kubernetes, retrying...')
            return run(args)
        else:
            logger.exception('Unexpected error while writing ssh host keys.')
            raise
示例#3
0
文件: commands.py 项目: CodeJuan/noel
def logs_command(args):
    """Gets (or streams) the logs for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')
    pods = k8s.pods(params={
        'labelSelector': 'noel-app={}'.format(args.app)})

    if not pods['items']:
        logger.error('No running pods found for app {}'.format(args.app))
        return False

    pod = pods['items'].pop()
    logger.info('Using pod {}'.format(pod['metadata']['name']))

    if args.follow:
        logger.warning('Streaming logs. Press ctrl+c to quit.')

    try:
        it = k8s.logs(
            pod['metadata']['name'],
            container='noel-app',
            lines=args.lines,
            follow=args.follow)

        for log in it:
            print(log)

    except KeyboardInterrupt:
        pass
示例#4
0
文件: commands.py 项目: rmoorman/noel
def get_config_command(args):
    """Gets the current configuration values for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')
    config = deployer.get_config(k8s, args.app)

    if not config:
        logger.error('No config for app {}'.format(args.app))
        return False

    for k, v in config['data'].iteritems():
        print('{}: {}'.format(k, v))
示例#5
0
文件: commands.py 项目: CodeJuan/noel
def get_config_command(args):
    """Gets the current configuration values for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')
    config = deployer.get_config(k8s, args.app)

    if not config:
        logger.error('No config for app {}'.format(args.app))
        return False

    for k, v in config['data'].iteritems():
        print('{}: {}'.format(k, v))
示例#6
0
文件: commands.py 项目: rmoorman/noel
def scale_command(args):
    """Scales the number of replicas for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')

    rc = deployer.get_replication_controller(k8s, args.app)

    if not rc:
        logger.error('No replication controller found for app {}.'.format(
            args.app))
        return False

    k8s.scale(rc['metadata']['name'], replicas=args.replicas)

    logger.info('Scaled app {} to {} replicas.'.format(args.app,
                                                       args.replicas))
示例#7
0
文件: commands.py 项目: CodeJuan/noel
def scale_command(args):
    """Scales the number of replicas for an application."""
    args.app = args.app.lower()

    k8s = Kubernetes(args.kubernetes_url, namespace='noelapp')

    rc = deployer.get_replication_controller(k8s, args.app)

    if not rc:
        logger.error(
            'No replication controller found for app {}.'.format(args.app))
        return False

    k8s.scale(rc['metadata']['name'], replicas=args.replicas)

    logger.info(
        'Scaled app {} to {} replicas.'.format(args.app, args.replicas))
示例#8
0
def post_receive_hook_command():
    repo_name = os.path.basename(os.getcwd())
    _, sha, ref = read_push_info_from_stdin()

    if ref != 'refs/heads/master':
        logger.error('Received ref {}, not deploying. \n'
                     'Please push master to deploy.'.format(ref))
        return False

    logger.info('Got request to build project {}.'.format(repo_name))

    staging_dir = os.path.join(STAGING_ROOT, repo_name)

    logger.info('Staging code at {}'.format(staging_dir))

    checkout_repo(staging_dir)

    args = argparse.Namespace(
        dir=staging_dir,
        app=repo_name,
        version=sha[:6],
        kubernetes_url='http://localhost:8001')

    return build_and_deploy_command(args)