Skip to content

Commit 10de342

Browse files
kyubifireDavid Pickle
authored andcommitted
Add File commands and new Block commands
Cherrypick manual Block snapshot creation from iodine53's branch Additional code developed collaboratively by: ccorales95 Cristina Corales <[email protected]> kyubifire Nilo Lisboa <[email protected]> VuKevin Kevin Vu <[email protected]> dpickle2 David Pickle <[email protected]> * Add support for manual snapshots [Block & File] (cherrypick from iodine53's branch for Block, then based similar function for File on this code) * Add support for deleting snapshots [File] * Add support for listing snapshots [File] * Add snapshot schedule enable/disable [Block & File] * Add snapshot space ordering [Block & File] * Add restoring a volume to snapshots [Block & File] * Add cancelling snapshot space [Block & File] * Add storage host authorization [File] * Add listing hosts authorized to storage volumes [File] * Add ordering File volumes [File] * Add cancelling File volumes [File] * Add displaying File volume details and volume lists [File] * Add additional output for commands: Add used space (bytes) to detail view [File] Add LUN ID column for block volume-list [Block] Add "success output" for several commands [Block & File] Add transaction info to detail/list views [Block & File] * Fix block snapshot-list command error (The "snapshot-list" block command produced an error when the list of snapshots for a volume was not empty. Updating the object mask which is sent to the SLAPI fixed the problem.) * Create "storage_utils.py" files for duplicate code (To prevent duplicate code between File and Block commands, code was refactored into SoftLayer/managers/storage_utils.py and SoftLayer/CLI/storage_utils.py.)
1 parent 4932cac commit 10de342

46 files changed

Lines changed: 3021 additions & 358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SoftLayer/CLI/block/access/authorize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Create a block storage snapshot."""
1+
"""Authorizes hosts on a specific block volume."""
22
# :license: MIT, see LICENSE for more details.
33

44
import click
@@ -40,3 +40,6 @@ def cli(env, volume_id, hardware_id, virtual_id, ip_address_id, ip_address):
4040
hardware_id,
4141
virtual_id,
4242
ip_address_id_list)
43+
44+
# If no exception was raised, the command succeeded
45+
click.echo('The specified hosts were authorized to access %s' % volume_id)

SoftLayer/CLI/block/access/list.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""List hosts with access to block volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import columns as column_helper
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
from SoftLayer.CLI import storage_utils
10+
11+
12+
@click.command()
13+
@click.argument('volume_id')
14+
@click.option('--sortby', help='Column to sort by', default='name')
15+
@click.option('--columns',
16+
callback=column_helper.get_formatter(storage_utils.COLUMNS),
17+
help='Columns to display. Options: {0}'.format(
18+
', '.join(column.name for column in storage_utils.COLUMNS)),
19+
default=','.join(storage_utils.DEFAULT_COLUMNS))
20+
@environment.pass_env
21+
def cli(env, columns, sortby, volume_id):
22+
"""List ACLs."""
23+
block_manager = SoftLayer.BlockStorageManager(env.client)
24+
access_list = block_manager.get_block_volume_access_list(
25+
volume_id=volume_id)
26+
table = formatting.Table(columns.columns)
27+
table.sortby = sortby
28+
29+
for key, type_name in [('allowedVirtualGuests', 'VIRTUAL'),
30+
('allowedHardware', 'HARDWARE'),
31+
('allowedSubnets', 'SUBNET'),
32+
('allowedIpAddresses', 'IP')]:
33+
for obj in access_list.get(key, []):
34+
obj['type'] = type_name
35+
table.add_row([value or formatting.blank()
36+
for value in columns.row(obj)])
37+
38+
env.fout(table)

SoftLayer/CLI/block/access/revoke.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Create a block storage snapshot."""
1+
"""Revokes hosts' access on a specific block volume."""
22
# :license: MIT, see LICENSE for more details.
33

44
import click
@@ -14,7 +14,7 @@
1414
@click.option('--virtual-id', '-v', multiple=True,
1515
help='The id of one SoftLayer_Virtual_Guest'
1616
' to revoke authorization')
17-
@click.option('--ip_address-id', '-i', multiple=True,
17+
@click.option('--ip-address-id', '-i', multiple=True,
1818
help='The id of one SoftLayer_Network_Subnet_IpAddress'
1919
' to revoke authorization')
2020
@click.option('--ip-address', multiple=True,
@@ -36,3 +36,6 @@ def cli(env, volume_id, hardware_id, virtual_id, ip_address_id, ip_address):
3636
hardware_id,
3737
virtual_id,
3838
ip_address_id_list)
39+
40+
# If no exception was raised, the command succeeded
41+
click.echo('Access to %s was revoked for the specified hosts' % volume_id)

SoftLayer/CLI/block/cancel.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ def cli(env, volume_id, reason, immediate):
2525
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
2626
raise exceptions.CLIAbort('Aborted')
2727

28-
block_storage_manager.cancel_block_volume(volume_id, reason, immediate)
28+
cancelled = block_storage_manager.cancel_block_volume(volume_id,
29+
reason, immediate)
30+
31+
if cancelled:
32+
if immediate:
33+
click.echo('Block volume with id %s has been marked'
34+
' for immediate cancellation' % volume_id)
35+
else:
36+
click.echo('Block volume with id %s has been marked'
37+
' for cancellation' % volume_id)
38+
else:
39+
click.echo('Unable to cancle block volume %s' % volume_id)

SoftLayer/CLI/block/detail.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,19 @@ def cli(env, volume_id):
5151
'Snapshot Capacity (GB)',
5252
block_volume['snapshotCapacityGb'],
5353
])
54-
table.add_row([
55-
'Snapshot Used (Bytes)',
56-
block_volume['parentVolume']['snapshotSizeBytes'],
57-
])
54+
if 'snapshotSizeBytes' in block_volume['parentVolume']:
55+
table.add_row([
56+
'Snapshot Used (Bytes)',
57+
block_volume['parentVolume']['snapshotSizeBytes'],
58+
])
59+
60+
table.add_row(['# of Active Transactions', "%i"
61+
% block_volume['activeTransactionCount']])
62+
63+
if block_volume['activeTransactions']:
64+
for trans in block_volume['activeTransactions']:
65+
table.add_row([
66+
'Ongoing Transactions',
67+
trans['transactionStatus']['friendlyName']])
5868

5969
env.fout(table)

SoftLayer/CLI/block/list.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
column_helper.Column('bytes_used', ('bytesUsed',), mask="bytesUsed"),
2323
column_helper.Column('ip_addr', ('serviceResourceBackendIpAddress',),
2424
mask="serviceResourceBackendIpAddress"),
25+
column_helper.Column('lunId', ('lunId',), mask="lunId"),
26+
column_helper.Column('active_transactions', ('activeTransactionCount',),
27+
mask="activeTransactionCount"),
2528
]
2629

2730
DEFAULT_COLUMNS = [
@@ -31,7 +34,9 @@
3134
'storage_type',
3235
'capacity_gb',
3336
'bytes_used',
34-
'ip_addr'
37+
'ip_addr',
38+
'lunId',
39+
'active_transactions'
3540
]
3641

3742

SoftLayer/CLI/block/order.py

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

1313
@click.command(context_settings=CONTEXT_SETTINGS)
1414
@click.option('--storage-type',
15-
help='Type of storage volume',
15+
help='Type of block storage volume',
1616
type=click.Choice(['performance', 'endurance']),
1717
required=True)
1818
@click.option('--size',
1919
type=int,
20-
help='Size of storage volume in GB',
20+
help='Size of block storage volume in GB',
2121
required=True)
2222
@click.option('--iops',
2323
type=int,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Block Storage Snapshot Control."""
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Cancel a snapshot space subscription."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
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.argument('volume-id')
14+
@click.option('--reason', help="An optional reason for cancellation")
15+
@click.option('--immediate',
16+
is_flag=True,
17+
help="Cancels the snapshot space immediately instead "
18+
"of on the billing anniversary")
19+
@environment.pass_env
20+
def cli(env, volume_id, reason, immediate):
21+
"""Cancel existing snapshot space for a given volume."""
22+
23+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
24+
25+
if not (env.skip_confirmations or formatting.no_going_back(volume_id)):
26+
raise exceptions.CLIAbort('Aborted')
27+
28+
cancelled = block_storage_manager.cancel_snapshot_space(
29+
volume_id, reason, immediate)
30+
31+
if cancelled:
32+
if immediate:
33+
click.echo('Block volume with id %s has been marked'
34+
' for immediate snapshot cancellation' % volume_id)
35+
else:
36+
click.echo('Block volume with id %s has been marked'
37+
' for snapshot cancellation' % volume_id)
38+
else:
39+
click.echo('Unable to cancel snapshot space for block volume %s'
40+
% volume_id)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Create a block storage snapshot."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
8+
9+
@click.command()
10+
@click.argument('volume_id')
11+
@click.option('--notes', '-n',
12+
help='Notes to set on the new snapshot')
13+
@environment.pass_env
14+
def cli(env, volume_id, notes):
15+
"""Creates a snapshot on a given volume"""
16+
block_manager = SoftLayer.BlockStorageManager(env.client)
17+
snapshot = block_manager.create_snapshot(volume_id, notes=notes)
18+
19+
if snapshot['id']:
20+
click.echo('New snapshot created with id: %s' % snapshot['id'])

0 commit comments

Comments
 (0)