|
| 1 | +"""Create 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.option('--name', required=True, help="Pool name") |
| 27 | +@click.option('--region', required=True, |
| 28 | + type=click.Choice(['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR', 'SNG/HKG/OSA/TOK', |
| 29 | + 'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']), |
| 30 | + help="Region selected") |
| 31 | +@environment.pass_env |
| 32 | +def cli(env, name, region): |
| 33 | + """Create bandwidth pool.""" |
| 34 | + |
| 35 | + manager = BandwidthManager(env.client) |
| 36 | + locations = manager.get_location_group() |
| 37 | + id_location_group = get_id_from_location_group(locations, location_groups[region]) |
| 38 | + created_pool = manager.create_pool(name, id_location_group) |
| 39 | + |
| 40 | + table = formatting.KeyValueTable(['Name', 'Value']) |
| 41 | + table.add_row(['Id', created_pool.get('id')]) |
| 42 | + table.add_row(['Name Pool', name]) |
| 43 | + table.add_row(['Region', region]) |
| 44 | + table.add_row(['Created Date', utils.clean_time(created_pool.get('createDate'))]) |
| 45 | + env.fout(table) |
| 46 | + |
| 47 | + |
| 48 | +def get_id_from_location_group(locations, name): |
| 49 | + """Gets the ID location group, from name""" |
| 50 | + for location in locations: |
| 51 | + if location['name'] == name: |
| 52 | + return location['id'] |
| 53 | + |
| 54 | + return None |
0 commit comments