Skip to content

Commit 179318c

Browse files
Merge branch 'master' of github.com:softlayer/softlayer-python into issues1862
2 parents 73338ec + 18ecf58 commit 179318c

File tree

21 files changed

+108
-77
lines changed

21 files changed

+108
-77
lines changed

SoftLayer/API.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def __init__(self, auth=None, transport=None, config_file=None):
177177
endpoint_url=url,
178178
proxy=self.settings['softlayer'].get('proxy'),
179179
# prevents an exception incase timeout is a float number.
180-
timeout=int(self.settings['softlayer'].getfloat('timeout')),
180+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
181181
user_agent=consts.USER_AGENT,
182182
verify=self.settings['softlayer'].getboolean('verify'),
183183
)
@@ -186,7 +186,7 @@ def __init__(self, auth=None, transport=None, config_file=None):
186186
transport = transports.XmlRpcTransport(
187187
endpoint_url=url,
188188
proxy=self.settings['softlayer'].get('proxy'),
189-
timeout=int(self.settings['softlayer'].getfloat('timeout')),
189+
timeout=int(self.settings['softlayer'].getfloat('timeout', 0)),
190190
user_agent=consts.USER_AGENT,
191191
verify=self.settings['softlayer'].getboolean('verify'),
192192
)

SoftLayer/CLI/block/options.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def cli(env, prices, location=None):
2222
"""List all options for ordering a block storage"""
2323

2424
order_manager = SoftLayer.OrderingManager(env.client)
25-
items = order_manager.get_items(PACKAGE_STORAGE)
25+
items = order_manager.get_items(PACKAGE_STORAGE, mask="mask[categories]")
2626
datacenters = order_manager.get_regions(PACKAGE_STORAGE, location)
2727

2828
tables = []
@@ -67,7 +67,7 @@ def _block_ios_get_table(items, prices):
6767
if block_item['itemCategory']['categoryCode'] == 'storage_tier_level':
6868
table.add_row([block_item.get('id'), block_item.get('description'),
6969
block_item.get('keyName')])
70-
table.sortby = 'Id'
70+
table.sortby = 'KeyName'
7171
table.align = 'l'
7272
return table
7373

@@ -86,7 +86,7 @@ def _block_storage_table(items, prices):
8686
if block_item['itemCategory']['categoryCode'] == 'performance_storage_space':
8787
table.add_row([block_item.get('id'), block_item.get('description'),
8888
block_item.get('keyName'), block_item.get('capacityMinimum') or '-', ])
89-
table.sortby = 'Id'
89+
table.sortby = 'KeyName'
9090
table.align = 'l'
9191
return table
9292

@@ -101,9 +101,16 @@ def _block_snapshot_get_table(items, prices):
101101
else:
102102
table = formatting.Table(['Id', 'Description', 'KeyName'], title='Snapshot')
103103
for block_item in items:
104-
if block_item['itemCategory']['categoryCode'] == 'storage_snapshot_space':
105-
table.add_row([block_item.get('id'), block_item.get('description'),
106-
block_item.get('keyName')])
107-
table.sortby = 'Id'
104+
if is_snapshot_category(block_item.get('categories', [])):
105+
table.add_row([block_item.get('id'), block_item.get('description'), block_item.get('keyName')])
106+
table.sortby = 'KeyName'
108107
table.align = 'l'
109108
return table
109+
110+
111+
def is_snapshot_category(categories):
112+
"""Checks if storage_snapshot_space is one of the categories"""
113+
for item in categories:
114+
if item.get('categoryCode') == "storage_snapshot_space":
115+
return True
116+
return False

SoftLayer/CLI/block/snapshot/cancel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1313
@click.argument('volume-id')
14-
@click.option('--reason', help="An optional reason for cancellation")
14+
@click.option('--reason', help="An optional reason for cancellation.")
1515
@click.option('--immediate',
1616
is_flag=True,
1717
help="Cancels the snapshot space immediately instead "
18-
"of on the billing anniversary")
18+
"of on the billing anniversary.")
1919
@environment.pass_env
2020
def cli(env, volume_id, reason, immediate):
2121
"""Cancel existing snapshot space for a given volume."""

SoftLayer/CLI/block/snapshot/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1010
@click.argument('volume_id')
1111
@click.option('--notes', '-n',
12-
help='Notes to set on the new snapshot')
12+
help='Notes to set on the new snapshot.')
1313
@environment.pass_env
1414
def cli(env, volume_id, notes):
15-
"""Creates a snapshot on a given volume"""
15+
"""Creates a snapshot on a given volume."""
1616
block_manager = SoftLayer.BlockStorageManager(env.client)
1717
snapshot = block_manager.create_snapshot(volume_id, notes=notes)
1818

SoftLayer/CLI/block/snapshot/delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@click.argument('snapshot_id')
1111
@environment.pass_env
1212
def cli(env, snapshot_id):
13-
"""Deletes a snapshot on a given volume"""
13+
"""Deletes a snapshot on a given volume."""
1414
block_manager = SoftLayer.BlockStorageManager(env.client)
1515
deleted = block_manager.delete_snapshot(snapshot_id)
1616

SoftLayer/CLI/block/snapshot/disable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1111
@click.argument('volume_id')
1212
@click.option('--schedule-type',
13-
help='Snapshot schedule [INTERVAL|HOURLY|DAILY|WEEKLY]',
13+
help='Snapshot schedule [INTERVAL|HOURLY|DAILY|WEEKLY].',
1414
required=True)
1515
@environment.pass_env
1616
def cli(env, volume_id, schedule_type):
17-
"""Disables snapshots on the specified schedule for a given volume"""
17+
"""Disables snapshots on the specified schedule for a given volume."""
1818

1919
if (schedule_type not in ['INTERVAL', 'HOURLY', 'DAILY', 'WEEKLY']):
2020
raise exceptions.CLIAbort(

SoftLayer/CLI/block/snapshot/enable.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@
1010
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1111
@click.argument('volume_id')
1212
@click.option('--schedule-type',
13-
help='Snapshot schedule [INTERVAL|HOURLY|DAILY|WEEKLY]',
13+
help='Snapshot schedule [INTERVAL|HOURLY|DAILY|WEEKLY].',
1414
required=True)
1515
@click.option('--retention-count',
16-
help='Number of snapshots to retain',
16+
help='Number of snapshots to retain.',
1717
required=True)
1818
@click.option('--minute',
19-
help='Minute of the day when snapshots should be taken',
19+
help='Minute of the day when snapshots should be taken.',
2020
default=0)
2121
@click.option('--hour',
22-
help='Hour of the day when snapshots should be taken',
22+
help='Hour of the day when snapshots should be taken.',
2323
default=0)
2424
@click.option('--day-of-week',
25-
help='Day of the week when snapshots should be taken',
25+
help='Day of the week when snapshots should be taken.',
2626
default='SUNDAY')
2727
@environment.pass_env
2828
def cli(env, volume_id, schedule_type, retention_count,
2929
minute, hour, day_of_week):
30-
"""Enables snapshots for a given volume on the specified schedule"""
30+
"""Enables snapshots for a given volume on the specified schedule."""
3131
block_manager = SoftLayer.BlockStorageManager(env.client)
3232

3333
valid_schedule_types = {'INTERVAL', 'HOURLY', 'DAILY', 'WEEKLY'}

SoftLayer/CLI/block/snapshot/get_notify_status.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@click.argument('volume_id')
1111
@environment.pass_env
1212
def cli(env, volume_id):
13-
"""Get snapshots space usage threshold warning flag setting for a given volume"""
13+
"""Get snapshots space usage threshold warning flag setting for a given volume."""
1414
block_manager = SoftLayer.BlockStorageManager(env.client)
1515
enabled = block_manager.get_volume_snapshot_notification_status(volume_id)
1616

SoftLayer/CLI/block/snapshot/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
3030
@click.argument('volume_id')
31-
@click.option('--sortby', help='Column to sort by',
31+
@click.option('--sortby', help='Column to sort by.',
3232
default='created')
3333
@click.option('--columns',
3434
callback=column_helper.get_formatter(COLUMNS),

SoftLayer/CLI/block/snapshot/order.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,45 @@
99

1010
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1111
@click.argument('volume_id')
12-
@click.option('--capacity',
12+
@click.option('--iops',
1313
type=int,
14-
help='Size of snapshot space to create in GB',
14+
help='Performance Storage IOPs, between 100 and 6000 in multiples of 100.')
15+
@click.option('--size',
16+
type=int,
17+
help='Size of snapshot space to create in GB.',
1518
required=True)
1619
@click.option('--tier',
1720
help='Endurance Storage Tier (IOPS per GB) of the block'
1821
' volume for which space is ordered [optional, and only'
19-
' valid for endurance storage volumes]',
22+
' valid for endurance storage volumes].',
2023
type=click.Choice(['0.25', '2', '4', '10']))
2124
@click.option('--upgrade',
2225
type=bool,
23-
help='Flag to indicate that the order is an upgrade',
26+
help='Flag to indicate that the order is an upgrade.',
2427
default=False,
2528
is_flag=True)
2629
@environment.pass_env
27-
def cli(env, volume_id, capacity, tier, upgrade):
30+
def cli(env, volume_id, size, tier, upgrade, iops):
2831
"""Order snapshot space for a block storage volume."""
2932
block_manager = SoftLayer.BlockStorageManager(env.client)
3033

3134
if tier is not None:
3235
tier = float(tier)
3336

37+
if iops is not None:
38+
if iops < 100 or iops > 6000:
39+
raise exceptions.ArgumentError(f"Invalid value for '--iops' / '-i': '{iops}' is not one "
40+
"of between 100 and 6000.")
41+
if iops % 100 != 0:
42+
raise exceptions.ArgumentError(f"Invalid value for '--iops' / '-i': '{iops}' is not a multiple of 100.")
43+
3444
try:
3545
order = block_manager.order_snapshot_space(
3646
volume_id,
37-
capacity=capacity,
47+
capacity=size,
3848
tier=tier,
39-
upgrade=upgrade
49+
upgrade=upgrade,
50+
iops=iops
4051
)
4152
except ValueError as ex:
4253
raise exceptions.ArgumentError(str(ex))

0 commit comments

Comments
 (0)