|
| 1 | +"""Edit bandwidth pool.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | +import click |
| 4 | + |
| 5 | +from SoftLayer import BandwidthManager |
| 6 | +from SoftLayer.CLI.command import SLCommand as SLCommand |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import formatting |
| 9 | +from SoftLayer import utils |
| 10 | + |
| 11 | +location_groups = { |
| 12 | + "SJC/DAL/WDC/TOR/MON": "US/Canada", |
| 13 | + "AMS/LON/MAD/PAR": "AMS/LON/MAD/PAR", |
| 14 | + "SNG/HKG/OSA/TOK": "SNG/HKG/JPN", |
| 15 | + "SYD": "AUS", |
| 16 | + "MEX": "MEX", |
| 17 | + "SAO": "BRA", |
| 18 | + "CHE": "IND", |
| 19 | + "MIL": "ITA", |
| 20 | + "SEO": "KOR", |
| 21 | + "FRA": "FRA" |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +@click.command(cls=SLCommand) |
| 26 | +@click.argument('identifier') |
| 27 | +@click.option('--name', required=True, help="Pool name") |
| 28 | +@environment.pass_env |
| 29 | +def cli(env, identifier, name): |
| 30 | + """Edit bandwidth pool.""" |
| 31 | + |
| 32 | + manager = BandwidthManager(env.client) |
| 33 | + bandwidth_pool = manager.edit_pool(identifier, name) |
| 34 | + |
| 35 | + if bandwidth_pool: |
| 36 | + |
| 37 | + edited_pool = manager.get_bandwidth_detail(identifier) |
| 38 | + locations = manager.get_location_group() |
| 39 | + |
| 40 | + location = next( |
| 41 | + (location for location in locations if location['id'] == edited_pool.get('locationGroupId')), None) |
| 42 | + |
| 43 | + region_name = next((key for key, value in location_groups.items() if value == location.get('name')), None) |
| 44 | + |
| 45 | + table = formatting.KeyValueTable(['Name', 'Value']) |
| 46 | + table.add_row(['Id', edited_pool.get('id')]) |
| 47 | + table.add_row(['Name Pool', name]) |
| 48 | + table.add_row(['Region', region_name]) |
| 49 | + table.add_row(['Created Date', utils.clean_time(edited_pool.get('createDate'))]) |
| 50 | + env.fout(table) |
0 commit comments