1"""Edit a subnet."""
2# :license: MIT, see LICENSE for more details.
3
4import click
5
6import SoftLayer
7from SoftLayer.CLI import environment
8from SoftLayer.CLI import helpers
9
10
11@click.command(short_help="Edit note and tags of a subnet")
12@click.argument('identifier')
13@click.option('--tags', '-t', type=click.STRING,
14              help='Comma separated list of tags, enclosed in quotes. "tag1, tag2"')
15@click.option('--note', '-n', type=click.STRING,
16              help="The note")
17@environment.pass_env
18def cli(env, identifier, tags, note):
19    """Edit note and tags of a subnet."""
20
21    mgr = SoftLayer.NetworkManager(env.client)
22    subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
23                                   name='subnet')
24
25    if tags:
26        result = mgr.set_tags_subnet(subnet_id, tags)
27        print_result(result, "Set tags")
28
29    if note:
30        result = mgr.edit_note_subnet(subnet_id, note)
31        print_result(result, "Edit note")
32
33
34def print_result(result, detail):
35    """Prints a successfully or Failed message."""
36    if result:
37        click.secho("{} successfully".format(detail), fg='green')
38    else:
39        click.secho("Failed to {}".format(detail.lower()), fg='red')
40