Skip to content

Commit e504d43

Browse files
Merge pull request #748 from kyubifire/file-and-block-commands
Add File commands and new Block commands
2 parents 4932cac + 71e15dd commit e504d43

46 files changed

Lines changed: 3028 additions & 359 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 cancel 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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@
1616
mask="serviceResource.datacenter.name"),
1717
column_helper.Column(
1818
'storage_type',
19-
lambda b: b['storageType']['keyName'].split('_').pop(0),
19+
lambda b: b['storageType']['keyName'].split('_').pop(0)
20+
if 'storageType' in b and 'keyName' in b['storageType']
21+
and isinstance(b['storageType']['keyName'], str)
22+
else '-',
2023
mask="storageType.keyName"),
2124
column_helper.Column('capacity_gb', ('capacityGb',), mask="capacityGb"),
2225
column_helper.Column('bytes_used', ('bytesUsed',), mask="bytesUsed"),
2326
column_helper.Column('ip_addr', ('serviceResourceBackendIpAddress',),
2427
mask="serviceResourceBackendIpAddress"),
28+
column_helper.Column('lunId', ('lunId',), mask="lunId"),
29+
column_helper.Column('active_transactions', ('activeTransactionCount',),
30+
mask="activeTransactionCount"),
2531
]
2632

2733
DEFAULT_COLUMNS = [
@@ -31,7 +37,9 @@
3137
'storage_type',
3238
'capacity_gb',
3339
'bytes_used',
34-
'ip_addr'
40+
'ip_addr',
41+
'lunId',
42+
'active_transactions'
3543
]
3644

3745

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)