예제 #1
0
def cli(ctx, force_refresh, droplet_id, create, destroy, show, name, snapshot):
    """
    Droplet CRUD
    """
    if ctx.verbose:
        click.echo("Droplet CRUD")

    ctx.droplet_id = droplet_id
    ctx.droplet_name = name

    if force_refresh:
        ctx.cache.delete('droplets')

    action = 'list'
    if create:
        action = 'create'
    elif destroy:
        action = 'destroy'
    elif show:
        action = 'show'
    elif snapshot:
        action = 'snapshot'

    response = DROPLET_ACTIONS[action](ctx)
    click.echo(format_response(response, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_droplets done ----')
예제 #2
0
def cli(ctx, force_refresh):
    """
    Generate Ansible inventory
    """
    if ctx.verbose:
        click.echo("Generate Ansible inventory")

    if force_refresh:
        ctx.cache.delete('inventory')
        ctx.cache.delete('droplets')

    inventory = ctx.cache.get_obj('inventory')
    droplets = {}
    if inventory is None:
        inventory = {}
        droplets = get_objects('droplets', ctx.cache_max_age, ctx.client, ctx.verbose)

        for droplet in droplets:
            dest = droplet['ip_address']

            inventory[droplet['id']] = [dest]
            inventory = push(inventory, droplet['name'], dest)
            inventory = push(inventory, 'region_{}'.format(droplet['region']['slug']), dest)

            components = droplet['name'].split('.')
            if len(components) == 3:
                inventory = push(inventory, components[0], dest)
                inventory = push(inventory, "{}_{}".format(components[0], components[1]), dest)

    inventory = byteify(inventory)
    ctx.cache.set_obj('inventory', inventory, ctx.cache_max_age)
    click.echo(format_response(inventory, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_ansible-inventory done ----')
예제 #3
0
def cli(ctx, force_refresh):
    """
    List SSH keys as JSON
    """
    if ctx.verbose:
        click.echo("List SSH keys as JSON")

    if force_refresh:
        ctx.cache.delete('ssh_keys')

    ssh_keys = get_objects('ssh_keys', ctx.cache_max_age, ctx.client, ctx.verbose)
    click.echo(format_response(ssh_keys, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_ssh-keys done ----')
예제 #4
0
def cli(ctx, force_refresh):
    """
    List Domains as JSON
    """
    if ctx.verbose:
        click.echo("List Domains as JSON")

    if force_refresh:
        ctx.cache.delete('domains')

    domains = get_objects('domains', ctx.cache_max_age, ctx.client, ctx.verbose)
    click.echo(format_response(domains, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_domains done ----')
예제 #5
0
파일: cmd_all.py 프로젝트: meganlkm/do-cli
def cli(ctx, force_refresh):
    """
    List all DigitalOcean information as JSON
    """
    if ctx.verbose:
        click.echo("List all DigitalOcean information as JSON")

    data = dict()
    for obj in ['regions', 'images', 'sizes', 'ssh_keys', 'domains', 'droplets']:
        if force_refresh:
            ctx.cache.delete(obj)
        data[obj] = get_objects(obj, ctx.cache_max_age, ctx.client, ctx.verbose)
    click.echo(format_response(data, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_all done ----')
예제 #6
0
def cli(ctx, force_refresh, *args, **kwargs):
    """
    List Images as JSON
    """
    if ctx.verbose:
        click.echo("List Images as JSON")

    if force_refresh:
        ctx.cache.delete('images')

    filter_opts = dict((k, v) for k, v in kwargs.iteritems() if v is not None)
    if 'regions' in filter_opts:
        filter_opts['regions'] = filter_opts['regions'].split(',')
    images = ctx.client.get_images(filter_opts)
    click.echo(format_response(images, ctx.pretty))

    if ctx.verbose:
        click.echo('---- cmd_images done ----')