|
| 1 | +"""Order/create a VLAN instance.""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | +import click |
| 4 | +import SoftLayer |
| 5 | +from SoftLayer.managers import ordering |
| 6 | + |
| 7 | +from SoftLayer.CLI import environment |
| 8 | +from SoftLayer.CLI import exceptions |
| 9 | +from SoftLayer.CLI import formatting |
| 10 | + |
| 11 | + |
| 12 | +@click.command() |
| 13 | +@click.option('--name', required=False, prompt=True, help="Vlan name") |
| 14 | +@click.option('--datacenter', '-d', required=False, help="Datacenter shortname") |
| 15 | +@click.option('--pod', '-p', required=False, help="Pod name. E.g dal05.pod01") |
| 16 | +@click.option('--network', default='public', show_default=True, type=click.Choice(['public', 'private']), |
| 17 | + help='Network vlan type') |
| 18 | +@click.option('--billing', default='hourly', show_default=True, type=click.Choice(['hourly', 'monthly']), |
| 19 | + help="Billing rate") |
| 20 | +@environment.pass_env |
| 21 | +def cli(env, name, datacenter, pod, network, billing): |
| 22 | + """Order/create a VLAN instance.""" |
| 23 | + |
| 24 | + item_package = ['PUBLIC_NETWORK_VLAN'] |
| 25 | + complex_type = 'SoftLayer_Container_Product_Order_Network_Vlan' |
| 26 | + extras = {'name': name} |
| 27 | + if pod: |
| 28 | + datacenter = pod.split('.')[0] |
| 29 | + mgr = SoftLayer.NetworkManager(env.client) |
| 30 | + pods = mgr.get_pods() |
| 31 | + for router in pods: |
| 32 | + if router.get('name') == pod: |
| 33 | + if network == 'public': |
| 34 | + extras['routerId'] = router.get('frontendRouterId') |
| 35 | + elif network == 'private': |
| 36 | + extras['routerId'] = router.get('backendRouterId') |
| 37 | + break |
| 38 | + if not extras.get('routerId'): |
| 39 | + raise exceptions.CLIAbort( |
| 40 | + "Unable to find pod name: {}".format(pod)) |
| 41 | + if network == 'private': |
| 42 | + item_package = ['PRIVATE_NETWORK_VLAN'] |
| 43 | + |
| 44 | + ordering_manager = ordering.OrderingManager(env.client) |
| 45 | + result = ordering_manager.place_order(package_keyname='NETWORK_VLAN', |
| 46 | + location=datacenter, |
| 47 | + item_keynames=item_package, |
| 48 | + complex_type=complex_type, |
| 49 | + hourly=billing, |
| 50 | + extras=extras) |
| 51 | + table = formatting.KeyValueTable(['name', 'value']) |
| 52 | + table.align['name'] = 'r' |
| 53 | + table.align['value'] = 'l' |
| 54 | + table.add_row(['id', result['orderId']]) |
| 55 | + table.add_row(['created', result['orderDate']]) |
| 56 | + table.add_row(['name', result['orderDetails']['orderContainers'][0]['name']]) |
| 57 | + |
| 58 | + env.fout(table) |
0 commit comments