Exemplo n.º 1
0
def cli(env, tags, key_name, resource_id):
    """Set Tags."""

    tag_manager = TagManager(env.client)
    tags = tag_manager.set_tags(tags, key_name, resource_id)

    if tags:
        click.secho("Set tags successfully", fg='green')
    else:
        click.secho("Failed to set tags", fg='red')
Exemplo n.º 2
0
def cli(env, detail):
    """List Tags."""

    tag_manager = TagManager(env.client)

    if detail:
        tables = detailed_table(tag_manager, tag_manager.get_attached_tags())
        for table in tables:
            env.fout(table)
    else:
        table = simple_table(tag_manager)
        env.fout(table)
Exemplo n.º 3
0
def cli(env, identifier, name):
    """Get details for a Tag. Identifier can be either a name or tag-id"""

    tag_manager = TagManager(env.client)

    # If the identifier is a int, and user didn't tell us it was a name.
    if str.isdigit(identifier) and not name:
        tags = [tag_manager.get_tag(identifier)]
    else:
        tags = tag_manager.get_tag_by_name(identifier)
    table = detailed_table(tag_manager, tags)
    env.fout(table)
Exemplo n.º 4
0
def cli(env, dry_run):
    """Removes all empty tags."""

    tag_manager = TagManager(env.client)
    empty_tags = tag_manager.get_unattached_tags()

    for tag in empty_tags:
        if dry_run:
            click.secho("(Dry Run) Removing {}".format(tag.get('name')), fg='yellow')
        else:
            result = tag_manager.delete_tag(tag.get('name'))
            color = 'green' if result else 'red'
            click.secho("Removing {}".format(tag.get('name')), fg=color)
Exemplo n.º 5
0
def cli(env, identifier, name):
    """Delete a Tag. Tag names that contain spaces need to be encased in quotes"""

    tag_manager = TagManager(env.client)
    tag_name = identifier
    # If the identifier is a int, and user didn't tell us it was a name.
    if str.isdigit(identifier) and not name:
        tag = tag_manager.get_tag(identifier)
        tag_name = tag.get('name', None)

    result = tag_manager.delete_tag(tag_name)
    if result:
        click.secho("Tag {} has been removed".format(tag_name), fg='green')
    else:
        click.secho("Failed to remove tag {}".format(tag_name), fg='red')
Exemplo n.º 6
0
def cli(env):
    """List everything that could be tagged."""

    tag_manager = TagManager(env.client)
    tag_types = tag_manager.get_all_tag_types()
    for tag_type in tag_types:
        title = "{} ({})".format(tag_type['description'], tag_type['keyName'])
        table = formatting.Table(['Id', 'Name'], title=title)
        resources = tag_manager.taggable_by_type(tag_type['keyName'])
        for resource in resources:
            table.add_row([
                resource['resource']['id'],
                tag_manager.get_resource_name(resource['resource'],
                                              tag_type['keyName'])
            ])
        env.fout(table)