-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathcreate_options.py
61 lines (51 loc) · 2.27 KB
/
create_options.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Options for ordering a dedicated host"""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.option('--datacenter', '-d',
help="Router hostname (requires --flavor) "
"ex. ams01",
show_default=True)
@click.option('--flavor', '-f',
help="Dedicated Virtual Host flavor (requires --datacenter)"
" ex. 56_CORES_X_242_RAM_X_1_4_TB",
show_default=True)
@environment.pass_env
def cli(env, **kwargs):
"""host order options for a given dedicated host.
To get a list of available backend routers see example:
slcli dh create-options --datacenter dal05 --flavor 56_CORES_X_242_RAM_X_1_4_TB
"""
mgr = SoftLayer.DedicatedHostManager(env.client)
tables = []
if not kwargs['flavor'] and not kwargs['datacenter']:
options = mgr.get_create_options()
# Datacenters
dc_table = formatting.Table(['datacenter', 'value'])
dc_table.sortby = 'value'
for location in options['locations']:
dc_table.add_row([location['name'], location['key']])
tables.append(dc_table)
dh_table = formatting.Table(['Dedicated Virtual Host Flavor(s)', 'value'])
dh_table.sortby = 'value'
for item in options['dedicated_host']:
dh_table.add_row([item['name'], item['key']])
tables.append(dh_table)
else:
if kwargs['flavor'] is None or kwargs['datacenter'] is None:
raise exceptions.ArgumentError('Both a flavor and datacenter need '
'to be passed as arguments '
'ex. slcli dh create-options -d '
'ams01 -f '
'56_CORES_X_242_RAM_X_1_4_TB')
router_opt = mgr.get_router_options(kwargs['datacenter'], kwargs['flavor'])
br_table = formatting.Table(
['Available Backend Routers'])
for router in router_opt:
br_table.add_row([router['hostname']])
tables.append(br_table)
env.fout(tables)