Beispiel #1
0
def cmd_complete(out, name, cmd, level=1):
    ctx = click.Context(cmd)

    cmpl = {
        'name': name,
        'cmd': cmd,
        'level': level,
        'flags': [opts for param in cmd.params for opts in param.opts
                  if isinstance(param, click.Option)],
        'complete_cmd': complete_cmd
    }

    params = [opts for param in cmd.params for opts in param.opts
              if isinstance(param, click.Parameter) and
              not isinstance(param, click.Option)]

    if isinstance(cmd, click.MultiCommand):
        cmds = cmd.list_commands(ctx)

        for cmd_name in cmds:
            cmd_complete(
                out,
                name + '_' + cmd_name,
                cmd.get_command(ctx, cmd_name),
                level + 1
            )

        cmpl['cmds'] = cmds

        out.write(render_cli('autocomplete-multi', **cmpl))
    else:
        # TODO: we might want to move that list of params somewhere else
        completable = [
            'command',
            'direction',
            'endpoint',
            'env',
            'host',
            'inventory',
            'inventory_name',
            'job',
            'limit',
            'organization_name',
            'platform',
            'project',
            'server',
        ]
        if len(params) == 1 and params[0] in completable:
            cmpl['param'] = params[0]
        elif len(params) > 1:
            cmpl['params'] = [el for el in params if el in completable]

        out.write(render_cli('autocomplete-single', **cmpl))

    if level == 1:
        out.write('complete -F _{0}_completion {0}\n'.format(name))
Beispiel #2
0
def cli(box, extra):
    """
    Provision a box
    """
    res = box.vagrant('provision', *extra)

    if res == 0:
        timestamp(render_cli('provision-success', box=box))
    else:
        timestamp(render_cli('provision-failure'))
Beispiel #3
0
def cli(box, force, command):
    """
    Launch a ssh shell on the box
    """
    if not box.is_running():
        click.secho('warning: box %s is not running' % (box.name()),
                    fg='yellow', err=True)
        sys.exit(0)

    if command and len(command):
        res = box.ssh_shell(command)
    else:
        click.echo(render_cli('services', box=box))

        if box.project.name() != 'aeriscloud':
            res = box.ssh_shell('${SHELL}')
        else:
            res = box.ssh_shell()

    if res == box.NO_PROJECT_DIR:
        if force:
            click.secho('warning: project folder does not exists!',
                        fg='yellow')
            res = box.ssh_shell()
        else:
            click.secho('error: project folder does not exists!',
                        fg='red')

    # forward exit code to the console
    sys.exit(res)
Beispiel #4
0
def cli(is_json):
    """
    See the aeriscloud version information
    """
    versions = {
        'aeriscloud': {'version': ac_version},
        'ansible': {'version': ansible_version},
        'vagrant': {'version': vagrant_version()},
        'virtualbox': {'version': virtualbox_version()},
        'ruby': _ruby_version(),
        'python': {'version': _python_version()},
        'git': {'version': str(sh.git('--version'))[12:].strip()}
    }

    # aeriscloud get information
    if os.path.exists(os.path.join(aeriscloud_path, '.git')):
        repo = Repo(aeriscloud_path)
        rev = str(repo.head.commit)[:8]
        branch = str(repo.active_branch)

        versions['aeriscloud']['revision'] = rev
        versions['aeriscloud']['branch'] = branch

    # operating system
    linux_version = _linux_version()
    if linux_version:
        versions['linux'] = linux_version
    else:
        try:
            # this is for osx
            sw_vers = dict([map(unicode.strip, line.split(':'))
                            for line in sh.sw_vers()])
            versions['osx'] = {
                'name': sw_vers['ProductName'],
                'version': sw_vers['ProductVersion'],
                'build': sw_vers['BuildVersion']
            }
        except sh.CommandNotFound:
            pass

    try:
        uname = str(sh.uname('-sr')).strip()
        versions['kernel'] = {'version': uname}
    except sh.CommandNotFound:
        pass

    if is_json:
        click.echo(json.dumps(versions))
    else:
        click.echo(render_cli('version', **versions))
Beispiel #5
0
def cli(box, quiet):
    """
    Shows provisioning history for a box
    """
    if not box.is_running():
        click.secho('error: box %s is not running' % box.name(), fg='red')
        sys.exit(1)

    history = box.history()

    # cleanup ansible output
    av = re.compile(r'ansible (\d+\.\d+\.\d+)( \(detached HEAD (\w+)\) '
                    'last updated (.*))?$')
    mv = re.compile(r'([A-Za-z0-9/_-]+): \(detached HEAD (\w+)\) '
                    'last updated (.*)$')

    for deployment in history:
        ansible = {'extra': [], 'modules': {}}
        for line in deployment['ansible_version'].split('\n'):
            line = line.strip()

            match = av.match(line)
            if match:
                ansible['version'] = match.group(1)
                if match.group(2):
                    ansible['rev'] = match.group(3)
                    ansible['last_update'] = arrow.get(match.group(4),
                                                       'YYYY/MM/DD HH:mm:ss')
                continue

            match = mv.match(line)
            if match:
                ansible['modules'][match.group(1)] = {
                    'rev': match.group(2),
                    'last_update': arrow.get(match.group(3),
                                             'YYYY/MM/DD HH:mm:ss')
                }
                continue

            ansible['extra'].append(line)

        deployment['date'] = arrow.get(deployment['date'],
                                       'DD MMM YYYY HH:mm:ss Z')
        deployment['ansible_version'] = ansible

    click.echo(render_cli('history', history=history, quiet=quiet), nl=False)