Skip to content

Commit fa68061

Browse files
Merge pull request #841 from allmightyspiff/issues826
Issues826 - added ability to change block storage passwords
2 parents 16e1086 + d8f0b82 commit fa68061

File tree

9 files changed

+62
-81
lines changed

9 files changed

+62
-81
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Modifies a password for a volume's access"""
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('access_id')
11+
@click.option('--password', '-p', multiple=False,
12+
help='Password you want to set, this command will fail if the password is not strong')
13+
@environment.pass_env
14+
def cli(env, access_id, password):
15+
"""Changes a password for a volume's access.
16+
17+
access id is the allowed_host_id from slcli block access-list
18+
"""
19+
20+
block_manager = SoftLayer.BlockStorageManager(env.client)
21+
22+
result = block_manager.set_credential_password(access_id=access_id, password=password)
23+
24+
if result:
25+
click.echo('Password updated for %s' % access_id)
26+
else:
27+
click.echo('FAILED updating password for %s' % access_id)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
('block:access-authorize', 'SoftLayer.CLI.block.access.authorize:cli'),
6161
('block:access-list', 'SoftLayer.CLI.block.access.list:cli'),
6262
('block:access-revoke', 'SoftLayer.CLI.block.access.revoke:cli'),
63+
('block:access-password', 'SoftLayer.CLI.block.access.password:cli'),
6364
('block:replica-failback', 'SoftLayer.CLI.block.replication.failback:cli'),
6465
('block:replica-failover', 'SoftLayer.CLI.block.replication.failover:cli'),
6566
('block:replica-order', 'SoftLayer.CLI.block.replication.order:cli'),

SoftLayer/CLI/storage_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ def _format_name(obj):
7575
allowedHardware.allowedHost.credential.password
7676
allowedSubnets.allowedHost.credential.password
7777
allowedIpAddresses.allowedHost.credential.password
78+
"""),
79+
column_helper.Column(
80+
'allowed_host_id',
81+
('allowedHost', 'id',),
82+
"""
83+
allowedVirtualGuests.allowedHost.id
84+
allowedHardware.allowedHost.id
85+
allowedSubnets.allowedHost.id
86+
allowedIpAddresses.allowedHost.id
7887
"""),
7988
]
8089

@@ -87,4 +96,5 @@ def _format_name(obj):
8796
'host_iqn',
8897
'username',
8998
'password',
99+
'allowed_host_id',
90100
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
setCredentialPassword = True

SoftLayer/managers/block.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,13 @@ def failback_from_replicant(self, volume_id, replicant_id):
553553

554554
return self.client.call('Network_Storage', 'failbackFromReplicant',
555555
replicant_id, id=volume_id)
556+
557+
def set_credential_password(self, access_id, password):
558+
"""Sets the password for an access host
559+
560+
:param integer access_id: id of the access host
561+
:param string password: password to set
562+
"""
563+
564+
return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword',
565+
password, id=access_id)

tests/CLI/modules/block_tests.py

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,7 @@ def test_access_list(self):
1616
result = self.run_command(['block', 'access-list', '1234'])
1717

1818
self.assert_no_fail(result)
19-
self.assertEqual([
20-
{
21-
'username': 'joe',
22-
'name': 'test-server.example.com',
23-
'type': 'VIRTUAL',
24-
'host_iqn': 'test-server',
25-
'password': '12345',
26-
'private_ip_address': '10.0.0.1',
27-
'id': 1234,
28-
},
29-
{
30-
'username': 'joe',
31-
'name': 'test-server.example.com',
32-
'type': 'HARDWARE',
33-
'host_iqn': 'test-server',
34-
'password': '12345',
35-
'private_ip_address': '10.0.0.2',
36-
'id': 1234,
37-
},
38-
{
39-
'username': 'joe',
40-
'name': '10.0.0.1/24 (backend subnet)',
41-
'type': 'SUBNET',
42-
'host_iqn': 'test-server',
43-
'password': '12345',
44-
'private_ip_address': None,
45-
'id': 1234,
46-
},
47-
{
48-
'username': 'joe',
49-
'name': '10.0.0.1 (backend ip)',
50-
'type': 'IP',
51-
'host_iqn': 'test-server',
52-
'password': '12345',
53-
'private_ip_address': None,
54-
'id': 1234,
55-
}],
56-
json.loads(result.output),)
19+
self.assert_called_with('SoftLayer_Network_Storage', 'getObject')
5720

5821
def test_volume_cancel(self):
5922
result = self.run_command([
@@ -511,3 +474,7 @@ def test_duplicate_order(self, order_mock):
511474
self.assertEqual(result.output,
512475
'Order #24601 placed successfully!\n'
513476
' > Storage as a Service\n')
477+
478+
def test_set_password(self):
479+
result = self.run_command(['block', 'access-password', '1234', '--password=AAAAA'])
480+
self.assert_no_fail(result)

tests/CLI/modules/file_tests.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,7 @@ class FileTests(testing.TestCase):
1414

1515
def test_access_list(self):
1616
result = self.run_command(['file', 'access-list', '1234'])
17-
1817
self.assert_no_fail(result)
19-
self.assertEqual([
20-
{
21-
'username': 'joe',
22-
'name': 'test-server.example.com',
23-
'type': 'VIRTUAL',
24-
'host_iqn': 'test-server',
25-
'password': '12345',
26-
'private_ip_address': '10.0.0.1',
27-
'id': 1234,
28-
},
29-
{
30-
'username': 'joe',
31-
'name': 'test-server.example.com',
32-
'type': 'HARDWARE',
33-
'host_iqn': 'test-server',
34-
'password': '12345',
35-
'private_ip_address': '10.0.0.2',
36-
'id': 1234,
37-
},
38-
{
39-
'username': 'joe',
40-
'name': '10.0.0.1/24 (backend subnet)',
41-
'type': 'SUBNET',
42-
'host_iqn': 'test-server',
43-
'password': '12345',
44-
'private_ip_address': None,
45-
'id': 1234,
46-
},
47-
{
48-
'username': 'joe',
49-
'name': '10.0.0.1 (backend ip)',
50-
'type': 'IP',
51-
'host_iqn': 'test-server',
52-
'password': '12345',
53-
'private_ip_address': None,
54-
'id': 1234,
55-
}],
56-
json.loads(result.output),)
5718

5819
def test_authorize_host_to_volume(self):
5920
result = self.run_command(['file', 'access-authorize', '12345678',

tests/managers/block_tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,3 +1175,10 @@ def test_order_block_duplicate_endurance(self):
11751175
'osFormatType': {'keyName': 'LINUX'},
11761176
'duplicateOriginSnapshotId': 470
11771177
},))
1178+
1179+
def test_setCredentialPassword(self):
1180+
mock = self.set_mock('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')
1181+
mock.return_value = True
1182+
result = self.block.set_credential_password(access_id=102, password='AAAaaa')
1183+
self.assertEqual(True, result)
1184+
self.assert_called_with('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')

tests/managers/file_tests.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ def test_deauthorize_host_to_volume(self):
5858
identifier=50)
5959

6060
def test_get_file_volume_access_list(self):
61-
result = self.file.get_file_volume_access_list(100)
62-
63-
self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result)
64-
61+
self.file.get_file_volume_access_list(100)
6562
self.assert_called_with(
6663
'SoftLayer_Network_Storage',
6764
'getObject',

0 commit comments

Comments
 (0)