Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion SoftLayer/CLI/block/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
@click.command()
@click.option('--username', '-u', help='Volume username')
@click.option('--datacenter', '-d', help='Datacenter shortname')
@click.option('--order', '-o', type=int, help='Filter by ID of the order that purchased the block storage')
@click.option('--storage-type',
help='Type of storage volume',
type=click.Choice(['performance', 'endurance']))
Expand All @@ -68,12 +69,13 @@
', '.join(column.name for column in COLUMNS)),
default=','.join(DEFAULT_COLUMNS))
@environment.pass_env
def cli(env, sortby, columns, datacenter, username, storage_type):
def cli(env, sortby, columns, datacenter, username, storage_type, order):
"""List block storage."""
block_manager = SoftLayer.BlockStorageManager(env.client)
block_volumes = block_manager.list_block_volumes(datacenter=datacenter,
username=username,
storage_type=storage_type,
order=order,
mask=columns.mask())

table = formatting.Table(columns.columns)
Expand Down
4 changes: 3 additions & 1 deletion SoftLayer/CLI/block/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions


CONTEXT_SETTINGS = {'token_normalize_func': lambda x: x.upper()}


Expand Down Expand Up @@ -128,5 +127,8 @@ def cli(env, storage_type, size, iops, tier, os_type,
order['placedOrder']['id']))
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
click.echo(
'\nYou may run "slcli block volume-list --order {0}" to find this block volume after it '
'is ready.'.format(order['placedOrder']['id']))
else:
click.echo("Order could not be placed! Please verify your options and try again.")
4 changes: 3 additions & 1 deletion SoftLayer/CLI/file/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
@click.command()
@click.option('--username', '-u', help='Volume username')
@click.option('--datacenter', '-d', help='Datacenter shortname')
@click.option('--order', '-o', type=int, help='Filter by ID of the order that purchased the block storage')
@click.option('--storage-type',
help='Type of storage volume',
type=click.Choice(['performance', 'endurance']))
Expand All @@ -66,12 +67,13 @@
', '.join(column.name for column in COLUMNS)),
default=','.join(DEFAULT_COLUMNS))
@environment.pass_env
def cli(env, sortby, columns, datacenter, username, storage_type):
def cli(env, sortby, columns, datacenter, username, storage_type, order):
"""List file storage."""
file_manager = SoftLayer.FileStorageManager(env.client)
file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
username=username,
storage_type=storage_type,
order=order,
mask=columns.mask())

table = formatting.Table(columns.columns)
Expand Down
3 changes: 3 additions & 0 deletions SoftLayer/CLI/file/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,8 @@ def cli(env, storage_type, size, iops, tier,
order['placedOrder']['id']))
for item in order['placedOrder']['items']:
click.echo(" > %s" % item['description'])
click.echo(
'\nYou may run "slcli file volume-list --order {0}" to find this file volume after it '
'is ready.'.format(order['placedOrder']['id']))
else:
click.echo("Order could not be placed! Please verify your options and try again.")
7 changes: 6 additions & 1 deletion SoftLayer/managers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def list_block_volume_limit(self):
"""
return self.get_volume_count_limits()

def list_block_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs):
def list_block_volumes(self, datacenter=None, username=None, storage_type=None, order=None, **kwargs):
"""Returns a list of block volumes.

:param datacenter: Datacenter short name (e.g.: dal09)
:param username: Name of volume.
:param storage_type: Type of volume: Endurance or Performance
:param order: Volume order id.
:param kwargs:
:return: Returns a list of block volumes.
"""
Expand Down Expand Up @@ -67,6 +68,10 @@ def list_block_volumes(self, datacenter=None, username=None, storage_type=None,
_filter['iscsiNetworkStorage']['username'] = \
(utils.query_filter(username))

if order:
_filter['iscsiNetworkStorage']['billingItem']['orderItem'][
'order']['id'] = (utils.query_filter(order))

kwargs['filter'] = _filter.to_dict()
return self.client.call('Account', 'getIscsiNetworkStorage', **kwargs)

Expand Down
7 changes: 6 additions & 1 deletion SoftLayer/managers/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ def list_file_volume_limit(self):
"""
return self.get_volume_count_limits()

def list_file_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs):
def list_file_volumes(self, datacenter=None, username=None, storage_type=None, order=None, **kwargs):
"""Returns a list of file volumes.

:param datacenter: Datacenter short name (e.g.: dal09)
:param username: Name of volume.
:param storage_type: Type of volume: Endurance or Performance
:param order: Volume order id.
:param kwargs:
:return: Returns a list of file volumes.
"""
Expand Down Expand Up @@ -64,6 +65,10 @@ def list_file_volumes(self, datacenter=None, username=None, storage_type=None, *
_filter['nasNetworkStorage']['username'] = \
(utils.query_filter(username))

if order:
_filter['nasNetworkStorage']['billingItem']['orderItem'][
'order']['id'] = (utils.query_filter(order))

kwargs['filter'] = _filter.to_dict()
return self.client.call('Account', 'getNasNetworkStorage', **kwargs)

Expand Down
19 changes: 16 additions & 3 deletions tests/CLI/modules/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ def test_volume_list(self):
}],
json.loads(result.output))

def test_volume_list_order(self):
result = self.run_command(['block', 'volume-list', '--order=1234567'])

self.assert_no_fail(result)
json_result = json.loads(result.output)
self.assertEqual(json_result[0]['id'], 100)

@mock.patch('SoftLayer.BlockStorageManager.list_block_volumes')
def test_volume_count(self, list_mock):
list_mock.return_value = [
Expand Down Expand Up @@ -199,7 +206,9 @@ def test_volume_order_performance(self, order_mock):
'Order #478 placed successfully!\n'
' > Performance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli block volume-list --order 478" to find this block volume '
'after it is ready.\n')

def test_volume_order_endurance_tier_not_given(self):
result = self.run_command(['block', 'volume-order',
Expand Down Expand Up @@ -232,7 +241,9 @@ def test_volume_order_endurance(self, order_mock):
'Order #478 placed successfully!\n'
' > Endurance Storage\n > Block Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli block volume-list --order 478" to find this block volume '
'after it is ready.\n')

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_order_not_placed(self, order_mock):
Expand Down Expand Up @@ -281,7 +292,9 @@ def test_volume_order_hourly_billing(self, order_mock):
' > Storage as a Service\n'
' > Block Storage\n'
' > 20 GB Storage Space\n'
' > 200 IOPS\n')
' > 200 IOPS\n'
'\nYou may run "slcli block volume-list --order 10983647" to find this block volume '
'after it is ready.\n')

@mock.patch('SoftLayer.BlockStorageManager.order_block_volume')
def test_volume_order_performance_manager_error(self, order_mock):
Expand Down
19 changes: 16 additions & 3 deletions tests/CLI/modules/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def test_volume_list(self):
}],
json.loads(result.output))

def test_volume_list_order(self):
result = self.run_command(['file', 'volume-list', '--order=1234567'])

self.assert_no_fail(result)
json_result = json.loads(result.output)
self.assertEqual(json_result[0]['id'], 1)

@mock.patch('SoftLayer.FileStorageManager.list_file_volumes')
def test_volume_count(self, list_mock):
list_mock.return_value = [
Expand Down Expand Up @@ -223,7 +230,9 @@ def test_volume_order_performance(self, order_mock):
'Order #478 placed successfully!\n'
' > Performance Storage\n > File Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli file volume-list --order 478" to find this file volume after it is '
'ready.\n')

def test_volume_order_endurance_tier_not_given(self):
result = self.run_command(['file', 'volume-order',
Expand Down Expand Up @@ -256,7 +265,9 @@ def test_volume_order_endurance(self, order_mock):
'Order #478 placed successfully!\n'
' > Endurance Storage\n > File Storage\n'
' > 0.25 IOPS per GB\n > 20 GB Storage Space\n'
' > 10 GB Storage Space (Snapshot Space)\n')
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli file volume-list --order 478" to find this file volume after it is '
'ready.\n')

@mock.patch('SoftLayer.FileStorageManager.order_file_volume')
def test_volume_order_order_not_placed(self, order_mock):
Expand Down Expand Up @@ -307,7 +318,9 @@ def test_volume_order_hourly_billing(self, order_mock):
' > File Storage\n'
' > 20 GB Storage Space\n'
' > 0.25 IOPS per GB\n'
' > 10 GB Storage Space (Snapshot Space)\n')
' > 10 GB Storage Space (Snapshot Space)\n'
'\nYou may run "slcli file volume-list --order 479" to find this file volume after it is '
'ready.\n')

@mock.patch('SoftLayer.FileStorageManager.order_file_volume')
def test_volume_order_performance_manager_error(self, order_mock):
Expand Down
40 changes: 40 additions & 0 deletions tests/managers/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,46 @@ def test_list_block_volumes(self):
mask='mask[%s]' % expected_mask
)

def test_list_block_volumes_additional_filter_order(self):
result = self.block.list_block_volumes(order=1234567)

self.assertEqual(SoftLayer_Account.getIscsiNetworkStorage,
result)

expected_filter = {
'iscsiNetworkStorage': {
'storageType': {
'keyName': {'operation': '*= BLOCK_STORAGE'}
},
'serviceResource': {
'type': {
'type': {'operation': '!~ ISCSI'}
}
},
'billingItem': {
'orderItem': {
'order': {
'id': {'operation': 1234567}}}}
}
}

expected_mask = 'id,' \
'username,' \
'lunId,' \
'capacityGb,' \
'bytesUsed,' \
'serviceResource.datacenter[name],' \
'serviceResourceBackendIpAddress,' \
'activeTransactionCount,' \
'replicationPartnerCount'

self.assert_called_with(
'SoftLayer_Account',
'getIscsiNetworkStorage',
filter=expected_filter,
mask='mask[%s]' % expected_mask
)

def test_list_block_volumes_with_additional_filters(self):
result = self.block.list_block_volumes(datacenter="dal09",
storage_type="Endurance",
Expand Down
40 changes: 40 additions & 0 deletions tests/managers/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,46 @@ def test_list_file_volumes(self):
mask='mask[%s]' % expected_mask
)

def test_list_file_volumes_additional_filter_order(self):
result = self.file.list_file_volumes(order=1234567)

self.assertEqual(SoftLayer_Account.getNasNetworkStorage,
result)

expected_filter = {
'nasNetworkStorage': {
'storageType': {
'keyName': {'operation': '*= FILE_STORAGE'}
},
'serviceResource': {
'type': {
'type': {'operation': '!~ NAS'}
}
},
'billingItem': {
'orderItem': {
'order': {
'id': {'operation': 1234567}}}}
}
}

expected_mask = 'id,'\
'username,'\
'capacityGb,'\
'bytesUsed,'\
'serviceResource.datacenter[name],'\
'serviceResourceBackendIpAddress,'\
'activeTransactionCount,'\
'fileNetworkMountAddress,'\
'replicationPartnerCount'

self.assert_called_with(
'SoftLayer_Account',
'getNasNetworkStorage',
filter=expected_filter,
mask='mask[%s]' % expected_mask
)

def test_list_file_volumes_with_additional_filters(self):
result = self.file.list_file_volumes(datacenter="dal09",
storage_type="Endurance",
Expand Down