|
| 1 | +"""Edit a subnet.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import click |
| 5 | + |
| 6 | +import SoftLayer |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from 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 |
| 18 | +def 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 | + |
| 34 | +def print_result(result, detail): |
| 35 | + if result: |
| 36 | + click.secho("{} successfully".format(detail), fg='green') |
| 37 | + else: |
| 38 | + click.secho("Failed to {}".format(detail.lower()), fg='red') |
0 commit comments