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