Skip to content

Commit ad13107

Browse files
author
Fernando Ojeda
committed
Add to block and file storage volume lis order.
1 parent 8a873b0 commit ad13107

File tree

8 files changed

+139
-4
lines changed

8 files changed

+139
-4
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', 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,11 +69,12 @@
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,
77+
order=order,
7678
storage_type=storage_type,
7779
mask=columns.mask())
7880

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', 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,11 +67,12 @@
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, order, storage_type):
7071
"""List file storage."""
7172
file_manager = SoftLayer.FileStorageManager(env.client)
7273
file_volumes = file_manager.list_file_volumes(datacenter=datacenter,
7374
username=username,
75+
order=order,
7476
storage_type=storage_type,
7577
mask=columns.mask())
7678

SoftLayer/managers/block.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def list_block_volume_limit(self):
2525
"""
2626
return self.get_volume_count_limits()
2727

28-
def list_block_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs):
28+
def list_block_volumes(self, datacenter=None, username=None, order=None, storage_type=None, **kwargs):
2929
"""Returns a list of block volumes.
3030
31+
:param order: Volume order id.
3132
:param datacenter: Datacenter short name (e.g.: dal09)
3233
:param username: Name of volume.
3334
:param storage_type: Type of volume: Endurance or Performance
@@ -67,6 +68,10 @@ def list_block_volumes(self, datacenter=None, username=None, storage_type=None,
6768
_filter['iscsiNetworkStorage']['username'] = \
6869
(utils.query_filter(username))
6970

71+
if order:
72+
_filter['iscsiNetworkStorage']['billingItem']['orderItem'][
73+
'order']['id'] = (utils.query_filter(order))
74+
7075
kwargs['filter'] = _filter.to_dict()
7176
return self.client.call('Account', 'getIscsiNetworkStorage', **kwargs)
7277

SoftLayer/managers/file.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ def list_file_volume_limit(self):
2222
"""
2323
return self.get_volume_count_limits()
2424

25-
def list_file_volumes(self, datacenter=None, username=None, storage_type=None, **kwargs):
25+
def list_file_volumes(self, datacenter=None, username=None, order=None, storage_type=None, **kwargs):
2626
"""Returns a list of file volumes.
2727
28+
:param order: Volume order id.
2829
:param datacenter: Datacenter short name (e.g.: dal09)
2930
:param username: Name of volume.
3031
:param storage_type: Type of volume: Endurance or Performance
@@ -64,6 +65,10 @@ def list_file_volumes(self, datacenter=None, username=None, storage_type=None, *
6465
_filter['nasNetworkStorage']['username'] = \
6566
(utils.query_filter(username))
6667

68+
if order:
69+
_filter['nasNetworkStorage']['billingItem']['orderItem'][
70+
'order']['id'] = (utils.query_filter(order))
71+
6772
kwargs['filter'] = _filter.to_dict()
6873
return self.client.call('Account', 'getNasNetworkStorage', **kwargs)
6974

tests/CLI/modules/block_tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,27 @@ def test_volume_list(self):
141141
}],
142142
json.loads(result.output))
143143

144+
def test_volume_list_order(self):
145+
result = self.run_command(['block', 'volume-list', '--order=1234567'])
146+
147+
self.assert_no_fail(result)
148+
self.assertEqual([
149+
{
150+
'bytes_used': None,
151+
'capacity_gb': 20,
152+
'datacenter': 'dal05',
153+
'id': 100,
154+
'iops': None,
155+
'ip_addr': '10.1.2.3',
156+
'lunId': None,
157+
'notes': "{'status': 'availabl",
158+
'rep_partner_count': None,
159+
'storage_type': 'ENDURANCE',
160+
'username': 'username',
161+
'active_transactions': None
162+
}],
163+
json.loads(result.output))
164+
144165
@mock.patch('SoftLayer.BlockStorageManager.list_block_volumes')
145166
def test_volume_count(self, list_mock):
146167
list_mock.return_value = [

tests/CLI/modules/file_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ def test_volume_list(self):
5555
}],
5656
json.loads(result.output))
5757

58+
def test_volume_list_order(self):
59+
result = self.run_command(['file', 'volume-list', '--order=1234567'])
60+
61+
self.assert_no_fail(result)
62+
self.assertEqual([
63+
{
64+
'bytes_used': None,
65+
'capacity_gb': 10,
66+
'datacenter': 'Dallas',
67+
'id': 1,
68+
'ip_addr': '127.0.0.1',
69+
'storage_type': 'ENDURANCE',
70+
'username': 'user',
71+
'active_transactions': None,
72+
'mount_addr': '127.0.0.1:/TEST',
73+
'notes': None,
74+
'rep_partner_count': None
75+
}],
76+
json.loads(result.output))
77+
5878
@mock.patch('SoftLayer.FileStorageManager.list_file_volumes')
5979
def test_volume_count(self, list_mock):
6080
list_mock.return_value = [

tests/managers/block_tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,46 @@ def test_list_block_volumes(self):
157157
mask='mask[%s]' % expected_mask
158158
)
159159

160+
def test_list_block_volumes_additional_filter_order(self):
161+
result = self.block.list_block_volumes(order=1234567)
162+
163+
self.assertEqual(SoftLayer_Account.getIscsiNetworkStorage,
164+
result)
165+
166+
expected_filter = {
167+
'iscsiNetworkStorage': {
168+
'storageType': {
169+
'keyName': {'operation': '*= BLOCK_STORAGE'}
170+
},
171+
'serviceResource': {
172+
'type': {
173+
'type': {'operation': '!~ ISCSI'}
174+
}
175+
},
176+
'billingItem': {
177+
'orderItem': {
178+
'order': {
179+
'id': {'operation': 1234567}}}}
180+
}
181+
}
182+
183+
expected_mask = 'id,' \
184+
'username,' \
185+
'lunId,' \
186+
'capacityGb,' \
187+
'bytesUsed,' \
188+
'serviceResource.datacenter[name],' \
189+
'serviceResourceBackendIpAddress,' \
190+
'activeTransactionCount,' \
191+
'replicationPartnerCount'
192+
193+
self.assert_called_with(
194+
'SoftLayer_Account',
195+
'getIscsiNetworkStorage',
196+
filter=expected_filter,
197+
mask='mask[%s]' % expected_mask
198+
)
199+
160200
def test_list_block_volumes_with_additional_filters(self):
161201
result = self.block.list_block_volumes(datacenter="dal09",
162202
storage_type="Endurance",

tests/managers/file_tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,46 @@ def test_list_file_volumes(self):
365365
mask='mask[%s]' % expected_mask
366366
)
367367

368+
def test_list_file_volumes_additional_filter_order(self):
369+
result = self.file.list_file_volumes(order=1234567)
370+
371+
self.assertEqual(SoftLayer_Account.getNasNetworkStorage,
372+
result)
373+
374+
expected_filter = {
375+
'nasNetworkStorage': {
376+
'storageType': {
377+
'keyName': {'operation': '*= FILE_STORAGE'}
378+
},
379+
'serviceResource': {
380+
'type': {
381+
'type': {'operation': '!~ NAS'}
382+
}
383+
},
384+
'billingItem': {
385+
'orderItem': {
386+
'order': {
387+
'id': {'operation': 1234567}}}}
388+
}
389+
}
390+
391+
expected_mask = 'id,'\
392+
'username,'\
393+
'capacityGb,'\
394+
'bytesUsed,'\
395+
'serviceResource.datacenter[name],'\
396+
'serviceResourceBackendIpAddress,'\
397+
'activeTransactionCount,'\
398+
'fileNetworkMountAddress,'\
399+
'replicationPartnerCount'
400+
401+
self.assert_called_with(
402+
'SoftLayer_Account',
403+
'getNasNetworkStorage',
404+
filter=expected_filter,
405+
mask='mask[%s]' % expected_mask
406+
)
407+
368408
def test_list_file_volumes_with_additional_filters(self):
369409
result = self.file.list_file_volumes(datacenter="dal09",
370410
storage_type="Endurance",

0 commit comments

Comments
 (0)