Skip to content

Commit 8a5e55b

Browse files
Merge branch 'caberos-issue1345' #1353
2 parents 48306c4 + d7254a0 commit 8a5e55b

File tree

18 files changed

+623
-222
lines changed

18 files changed

+623
-222
lines changed

SoftLayer/CLI/block/list.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
@click.command()
5959
@click.option('--username', '-u', help='Volume username')
6060
@click.option('--datacenter', '-d', help='Datacenter shortname')
61+
@click.option('--order', '-o', type=int, help='Filter by ID of the order that purchased the block storage')
6162
@click.option('--storage-type',
6263
help='Type of storage volume',
6364
type=click.Choice(['performance', 'endurance']))
@@ -68,12 +69,13 @@
6869
', '.join(column.name for column in COLUMNS)),
6970
default=','.join(DEFAULT_COLUMNS))
7071
@environment.pass_env
71-
def cli(env, sortby, columns, datacenter, username, storage_type):
72+
def cli(env, sortby, columns, datacenter, username, storage_type, order):
7273
"""List block storage."""
7374
block_manager = SoftLayer.BlockStorageManager(env.client)
7475
block_volumes = block_manager.list_block_volumes(datacenter=datacenter,
7576
username=username,
7677
storage_type=storage_type,
78+
order=order,
7779
mask=columns.mask())
7880

7981
table = formatting.Table(columns.columns)

SoftLayer/CLI/block/order.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from SoftLayer.CLI import environment
77
from SoftLayer.CLI import exceptions
88

9-
109
CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}
1110

1211

@@ -128,5 +127,8 @@ def cli(env, storage_type, size, iops, tier, os_type,
128127
order['placedOrder']['id']))
129128
for item in order['placedOrder']['items']:
130129
click.echo(" > %s" % item['description'])
130+
click.echo(
131+
'\nYou may run "slcli block volume-list --order {0}" to find this block volume after it '
132+
'is ready.'.format(order['placedOrder']['id']))
131133
else:
132134
click.echo("Order could not be placed! Please verify your options and try again.")

SoftLayer/CLI/file/list.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
@click.command()
5757
@click.option('--username', '-u', help='Volume username')
5858
@click.option('--datacenter', '-d', help='Datacenter shortname')
59+
@click.option('--order', '-o', type=int, help='Filter by ID of the order that purchased the block storage')
5960
@click.option('--storage-type',
6061
help='Type of storage volume',
6162
type=click.Choice(['performance', 'endurance']))
@@ -66,12 +67,13 @@
6667
', '.join(column.name for column in COLUMNS)),
6768
default=','.join(DEFAULT_COLUMNS))
6869
@environment.pass_env
69-
def cli(env, sortby, columns, datacenter, username, storage_type):
70+
def cli(env, sortby, columns, datacenter, username, storage_type, order):
7071
"""List file storage."""
7172
file_manager = SoftLayer.FileStorageManager(env.client)
7273
file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
7374
username=username,
7475
storage_type=storage_type,
76+
order=order,
7577
mask=columns.mask())
7678

7779
table = formatting.Table(columns.columns)

SoftLayer/CLI/file/order.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,8 @@ def cli(env, storage_type, size, iops, tier,
115115
order['placedOrder']['id']))
116116
for item in order['placedOrder']['items']:
117117
click.echo(" > %s" % item['description'])
118+
click.echo(
119+
'\nYou may run "slcli file volume-list --order {0}" to find this file volume after it '
120+
'is ready.'.format(order['placedOrder']['id']))
118121
else:
119122
click.echo("Order could not be placed! Please verify your options and try again.")

SoftLayer/CLI/hardware/create_options.py

Lines changed: 82 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -30,128 +30,110 @@ def cli(env, prices, location=None):
3030
dc_table.add_row([location_info['name'], location_info['key']])
3131
tables.append(dc_table)
3232

33-
if prices:
34-
_preset_prices_table(options['sizes'], tables)
35-
_os_prices_table(options['operating_systems'], tables)
36-
_port_speed_prices_table(options['port_speeds'], tables)
37-
_extras_prices_table(options['extras'], tables)
38-
else:
39-
# Presets
40-
preset_table = formatting.Table(['Size', 'Value'], title="Sizes")
41-
preset_table.sortby = 'Value'
42-
preset_table.align = 'l'
43-
for size in options['sizes']:
44-
preset_table.add_row([size['name'], size['key']])
45-
tables.append(preset_table)
46-
47-
# Operating systems
48-
os_table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems")
49-
os_table.sortby = 'Key'
50-
os_table.align = 'l'
51-
for operating_system in options['operating_systems']:
52-
os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']])
53-
tables.append(os_table)
54-
55-
# Port speed
56-
port_speed_table = formatting.Table(['Network', 'Speed', 'Key'], title="Network Options")
57-
port_speed_table.sortby = 'Speed'
58-
port_speed_table.align = 'l'
59-
for speed in options['port_speeds']:
60-
port_speed_table.add_row([speed['name'], speed['speed'], speed['key']])
61-
tables.append(port_speed_table)
62-
63-
# Extras
64-
extras_table = formatting.Table(['Extra Option', 'Value'], title="Extras")
65-
extras_table.sortby = 'Value'
66-
extras_table.align = 'l'
67-
for extra in options['extras']:
68-
extras_table.add_row([extra['name'], extra['key']])
69-
tables.append(extras_table)
33+
tables.append(_preset_prices_table(options['sizes'], prices))
34+
tables.append(_os_prices_table(options['operating_systems'], prices))
35+
tables.append(_port_speed_prices_table(options['port_speeds'], prices))
36+
tables.append(_extras_prices_table(options['extras'], prices))
7037

38+
# since this is multiple tables, this is required for a valid JSON object to be rendered.
7139
env.fout(formatting.listing(tables, separator='\n'))
7240

7341

74-
def _preset_prices_table(sizes, tables):
42+
def _preset_prices_table(sizes, prices=False):
7543
"""Shows Server Preset options prices.
7644
7745
:param [] sizes: List of Hardware Server sizes.
78-
:param tables: Table formatting.
46+
:param prices: Create a price table or not
7947
"""
80-
preset_prices_table = formatting.Table(['Size', 'Value', 'Hourly', 'Monthly'], title="Sizes Prices")
81-
preset_prices_table.sortby = 'Value'
82-
preset_prices_table.align = 'l'
83-
for size in sizes:
84-
preset_prices_table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'],
85-
"%.4f" % size['recurringFee']])
86-
tables.append(preset_prices_table)
48+
if prices:
49+
table = formatting.Table(['Size', 'Value', 'Hourly', 'Monthly'], title="Sizes")
50+
for size in sizes:
51+
if size.get('hourlyRecurringFee', 0) + size.get('recurringFee', 0) + 1 > 0:
52+
table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'],
53+
"%.4f" % size['recurringFee']])
54+
else:
55+
table = formatting.Table(['Size', 'Value'], title="Sizes")
56+
for size in sizes:
57+
table.add_row([size['name'], size['key']])
58+
table.sortby = 'Value'
59+
table.align = 'l'
60+
return table
8761

8862

89-
def _os_prices_table(operating_systems, tables):
63+
def _os_prices_table(operating_systems, prices=False):
9064
"""Shows Server Operating Systems prices cost and capacity restriction.
9165
9266
:param [] operating_systems: List of Hardware Server operating systems.
93-
:param tables: Table formatting.
67+
:param prices: Create a price table or not
9468
"""
95-
os_prices_table = formatting.Table(['OS Key', 'Hourly', 'Monthly', 'Restriction'],
96-
title="Operating Systems Prices")
97-
os_prices_table.sortby = 'OS Key'
98-
os_prices_table.align = 'l'
99-
for operating_system in operating_systems:
100-
for price in operating_system['prices']:
101-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
102-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
103-
cr_type = _get_price_data(price, 'capacityRestrictionType')
104-
os_prices_table.add_row(
105-
[operating_system['key'],
106-
_get_price_data(price, 'hourlyRecurringFee'),
107-
_get_price_data(price, 'recurringFee'),
108-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
109-
tables.append(os_prices_table)
110-
111-
112-
def _port_speed_prices_table(port_speeds, tables):
69+
if prices:
70+
table = formatting.Table(['Key', 'Hourly', 'Monthly', 'Restriction'],
71+
title="Operating Systems")
72+
for operating_system in operating_systems:
73+
for price in operating_system['prices']:
74+
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
75+
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
76+
cr_type = _get_price_data(price, 'capacityRestrictionType')
77+
table.add_row(
78+
[operating_system['key'],
79+
_get_price_data(price, 'hourlyRecurringFee'),
80+
_get_price_data(price, 'recurringFee'),
81+
"%s - %s %s" % (cr_min, cr_max, cr_type)])
82+
else:
83+
table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems")
84+
for operating_system in operating_systems:
85+
table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']])
86+
87+
table.sortby = 'Key'
88+
table.align = 'l'
89+
return table
90+
91+
92+
def _port_speed_prices_table(port_speeds, prices=False):
11393
"""Shows Server Port Speeds prices cost and capacity restriction.
11494
11595
:param [] port_speeds: List of Hardware Server Port Speeds.
116-
:param tables: Table formatting.
96+
:param prices: Create a price table or not
11797
"""
118-
port_speed_prices_table = formatting.Table(['Key', 'Speed', 'Hourly', 'Monthly', 'Restriction'],
119-
title="Network Options Prices")
120-
port_speed_prices_table.sortby = 'Speed'
121-
port_speed_prices_table.align = 'l'
122-
for speed in port_speeds:
123-
for price in speed['prices']:
124-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
125-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
126-
cr_type = _get_price_data(price, 'capacityRestrictionType')
127-
port_speed_prices_table.add_row(
128-
[speed['key'], speed['speed'],
129-
_get_price_data(price, 'hourlyRecurringFee'),
130-
_get_price_data(price, 'recurringFee'),
131-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
132-
tables.append(port_speed_prices_table)
133-
134-
135-
def _extras_prices_table(extras, tables):
98+
if prices:
99+
table = formatting.Table(['Key', 'Speed', 'Hourly', 'Monthly'], title="Network Options")
100+
for speed in port_speeds:
101+
for price in speed['prices']:
102+
table.add_row(
103+
[speed['key'], speed['speed'],
104+
_get_price_data(price, 'hourlyRecurringFee'),
105+
_get_price_data(price, 'recurringFee')])
106+
else:
107+
table = formatting.Table(['Network', 'Speed', 'Key'], title="Network Options")
108+
for speed in port_speeds:
109+
table.add_row([speed['name'], speed['speed'], speed['key']])
110+
table.sortby = 'Speed'
111+
table.align = 'l'
112+
return table
113+
114+
115+
def _extras_prices_table(extras, prices=False):
136116
"""Shows Server extras prices cost and capacity restriction.
137117
138118
:param [] extras: List of Hardware Server Extras.
139-
:param tables: Table formatting.
119+
:param prices: Create a price table or not
140120
"""
141-
extras_prices_table = formatting.Table(['Extra Option Key', 'Hourly', 'Monthly', 'Restriction'],
142-
title="Extras Prices")
143-
extras_prices_table.align = 'l'
144-
for extra in extras:
145-
for price in extra['prices']:
146-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
147-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
148-
cr_type = _get_price_data(price, 'capacityRestrictionType')
149-
extras_prices_table.add_row(
150-
[extra['key'],
151-
_get_price_data(price, 'hourlyRecurringFee'),
152-
_get_price_data(price, 'recurringFee'),
153-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
154-
tables.append(extras_prices_table)
121+
if prices:
122+
table = formatting.Table(['Key', 'Hourly', 'Monthly'], title="Extras")
123+
124+
for extra in extras:
125+
for price in extra['prices']:
126+
table.add_row(
127+
[extra['key'],
128+
_get_price_data(price, 'hourlyRecurringFee'),
129+
_get_price_data(price, 'recurringFee')])
130+
else:
131+
table = formatting.Table(['Extra Option', 'Key'], title="Extras")
132+
for extra in extras:
133+
table.add_row([extra['name'], extra['key']])
134+
table.sortby = 'Key'
135+
table.align = 'l'
136+
return table
155137

156138

157139
def _get_price_data(price, item):
@@ -164,24 +146,3 @@ def _get_price_data(price, item):
164146
if item in price:
165147
result = price[item]
166148
return result
167-
168-
169-
def _location_item_prices(location_prices, tables):
170-
"""Get a specific data from HS price.
171-
172-
:param price: Hardware Server price.
173-
:param string item: Hardware Server price data.
174-
"""
175-
location_prices_table = formatting.Table(['keyName', 'priceId', 'Hourly', 'Monthly', 'Restriction'])
176-
location_prices_table.sortby = 'keyName'
177-
location_prices_table.align = 'l'
178-
for price in location_prices:
179-
cr_max = _get_price_data(price, 'capacityRestrictionMaximum')
180-
cr_min = _get_price_data(price, 'capacityRestrictionMinimum')
181-
cr_type = _get_price_data(price, 'capacityRestrictionType')
182-
location_prices_table.add_row(
183-
[price['item']['keyName'], price['id'],
184-
_get_price_data(price, 'hourlyRecurringFee'),
185-
_get_price_data(price, 'recurringFee'),
186-
"%s - %s %s" % (cr_min, cr_max, cr_type)])
187-
tables.append(location_prices_table)

0 commit comments

Comments
 (0)