Skip to content

Commit 231a53b

Browse files
Merge pull request #840 from causton81/feature/STORAUTO-62
STORAUTO-62 support for setting LUN ID on block volumes
2 parents 42a275e + 74c49ea commit 231a53b

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

SoftLayer/CLI/block/lun.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Set the LUN ID on an iSCSI volume."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
9+
10+
@click.command()
11+
@click.argument('volume-id')
12+
@click.argument('lun-id')
13+
@environment.pass_env
14+
def cli(env, volume_id, lun_id):
15+
"""Set the LUN ID on an existing block storage volume.
16+
17+
The LUN ID only takes effect during the Host Authorization process. It is
18+
recommended (but not necessary) to de-authorize all hosts before using this
19+
method. See `block access-revoke`.
20+
21+
VOLUME_ID - the volume ID on which to set the LUN ID.
22+
23+
LUN_ID - recommended range is an integer between 0 and 255. Advanced users
24+
can use an integer between 0 and 4095.
25+
"""
26+
27+
block_storage_manager = SoftLayer.BlockStorageManager(env.client)
28+
29+
res = block_storage_manager.create_or_update_lun_id(volume_id, lun_id)
30+
31+
if 'value' in res and lun_id == res['value']:
32+
click.echo(
33+
'Block volume with id %s is reporting LUN ID %s' % (res['volumeId'], res['value']))
34+
else:
35+
click.echo(
36+
'Failed to confirm the new LUN ID on volume %s' % (volume_id))

SoftLayer/CLI/routes.py

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
('block:volume-duplicate', 'SoftLayer.CLI.block.duplicate:cli'),
8181
('block:volume-list', 'SoftLayer.CLI.block.list:cli'),
8282
('block:volume-order', 'SoftLayer.CLI.block.order:cli'),
83+
('block:volume-set-lun-id', 'SoftLayer.CLI.block.lun:cli'),
8384

8485
('file', 'SoftLayer.CLI.file'),
8586
('file:access-authorize', 'SoftLayer.CLI.file.access.authorize:cli'),

SoftLayer/managers/block.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def failback_from_replicant(self, volume_id, replicant_id):
547547
"""Failback from a volume replicant.
548548
549549
:param integer volume_id: The id of the volume
550-
:param integer: ID of replicant to failback from
550+
:param integer replicant_id: ID of replicant to failback from
551551
:return: Returns whether failback was successful or not
552552
"""
553553

@@ -563,3 +563,13 @@ def set_credential_password(self, access_id, password):
563563

564564
return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword',
565565
password, id=access_id)
566+
567+
def create_or_update_lun_id(self, volume_id, lun_id):
568+
"""Set the LUN ID on a volume.
569+
570+
:param integer volume_id: The id of the volume
571+
:param integer lun_id: LUN ID to set on the volume
572+
:return: a SoftLayer_Network_Storage_Property object
573+
"""
574+
return self.client.call('Network_Storage', 'createOrUpdateLunId',
575+
lun_id, id=volume_id)

tests/CLI/modules/block_tests.py

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
:license: MIT, see LICENSE for more details.
66
"""
7+
from SoftLayer import exceptions
78
from SoftLayer import testing
89

910
import json
@@ -28,6 +29,32 @@ def test_volume_cancel(self):
2829
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
2930
args=(False, True, None))
3031

32+
def test_volume_set_lun_id_in_range(self):
33+
lun_mock = self.set_mock('SoftLayer_Network_Storage', 'createOrUpdateLunId')
34+
lun_mock.return_value = dict(volumeId=1234, value='42')
35+
result = self.run_command('block volume-set-lun-id 1234 42'.split())
36+
self.assert_no_fail(result)
37+
self.assertEqual('Block volume with id 1234 is reporting LUN ID 42\n',
38+
result.output)
39+
40+
def test_volume_set_lun_id_in_range_missing_value(self):
41+
lun_mock = self.set_mock('SoftLayer_Network_Storage', 'createOrUpdateLunId')
42+
lun_mock.return_value = dict(volumeId=1234)
43+
result = self.run_command('block volume-set-lun-id 1234 42'.split())
44+
self.assert_no_fail(result)
45+
self.assertEqual('Failed to confirm the new LUN ID on volume 1234\n',
46+
result.output)
47+
48+
def test_volume_set_lun_id_not_in_range(self):
49+
value = '-1'
50+
lun_mock = self.set_mock('SoftLayer_Network_Storage', 'createOrUpdateLunId')
51+
lun_mock.side_effect = exceptions.SoftLayerAPIError(
52+
'SoftLayer_Exception_Network_Storage_Iscsi_InvalidLunId',
53+
'The LUN ID specified is out of the valid range: %s [min: 0 max: 4095]' % (value))
54+
result = self.run_command('block volume-set-lun-id 1234 42'.split())
55+
self.assertIsNotNone(result.exception)
56+
self.assertIn('The LUN ID specified is out of the valid range', result.exception.faultString)
57+
3158
def test_volume_detail(self):
3259
result = self.run_command(['block', 'volume-detail', '1234'])
3360

0 commit comments

Comments
 (0)