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
27 changes: 27 additions & 0 deletions SoftLayer/CLI/block/access/password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Modifies a password for a volume's access"""
# :license: MIT, see LICENSE for more details.

import click
import SoftLayer
from SoftLayer.CLI import environment


@click.command()
@click.argument('access_id')
@click.option('--password', '-p', multiple=False,
help='Password you want to set, this command will fail if the password is not strong')
@environment.pass_env
def cli(env, access_id, password):
"""Changes a password for a volume's access.

access id is the allowed_host_id from slcli block access-list
"""

block_manager = SoftLayer.BlockStorageManager(env.client)

result = block_manager.set_credential_password(access_id=access_id, password=password)

if result:
click.echo('Password updated for %s' % access_id)
else:
click.echo('FAILED updating password for %s' % access_id)
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
('block:access-authorize', 'SoftLayer.CLI.block.access.authorize:cli'),
('block:access-list', 'SoftLayer.CLI.block.access.list:cli'),
('block:access-revoke', 'SoftLayer.CLI.block.access.revoke:cli'),
('block:access-password', 'SoftLayer.CLI.block.access.password:cli'),
('block:replica-failback', 'SoftLayer.CLI.block.replication.failback:cli'),
('block:replica-failover', 'SoftLayer.CLI.block.replication.failover:cli'),
('block:replica-order', 'SoftLayer.CLI.block.replication.order:cli'),
Expand Down
10 changes: 10 additions & 0 deletions SoftLayer/CLI/storage_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def _format_name(obj):
allowedHardware.allowedHost.credential.password
allowedSubnets.allowedHost.credential.password
allowedIpAddresses.allowedHost.credential.password
"""),
column_helper.Column(
'allowed_host_id',
('allowedHost', 'id',),
"""
allowedVirtualGuests.allowedHost.id
allowedHardware.allowedHost.id
allowedSubnets.allowedHost.id
allowedIpAddresses.allowedHost.id
"""),
]

Expand All @@ -87,4 +96,5 @@ def _format_name(obj):
'host_iqn',
'username',
'password',
'allowed_host_id',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setCredentialPassword = True
10 changes: 10 additions & 0 deletions SoftLayer/managers/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,13 @@ def failback_from_replicant(self, volume_id, replicant_id):

return self.client.call('Network_Storage', 'failbackFromReplicant',
replicant_id, id=volume_id)

def set_credential_password(self, access_id, password):
"""Sets the password for an access host

:param integer access_id: id of the access host
:param string password: password to set
"""

return self.client.call('Network_Storage_Allowed_Host', 'setCredentialPassword',
password, id=access_id)
43 changes: 5 additions & 38 deletions tests/CLI/modules/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,7 @@ def test_access_list(self):
result = self.run_command(['block', 'access-list', '1234'])

self.assert_no_fail(result)
self.assertEqual([
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'VIRTUAL',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.1',
'id': 1234,
},
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'HARDWARE',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.2',
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1/24 (backend subnet)',
'type': 'SUBNET',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1 (backend ip)',
'type': 'IP',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
}],
json.loads(result.output),)
self.assert_called_with('SoftLayer_Network_Storage', 'getObject')

def test_volume_cancel(self):
result = self.run_command([
Expand Down Expand Up @@ -511,3 +474,7 @@ def test_duplicate_order(self, order_mock):
self.assertEqual(result.output,
'Order #24601 placed successfully!\n'
' > Storage as a Service\n')

def test_set_password(self):
result = self.run_command(['block', 'access-password', '1234', '--password=AAAAA'])
self.assert_no_fail(result)
39 changes: 0 additions & 39 deletions tests/CLI/modules/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,7 @@ class FileTests(testing.TestCase):

def test_access_list(self):
result = self.run_command(['file', 'access-list', '1234'])

self.assert_no_fail(result)
self.assertEqual([
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'VIRTUAL',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.1',
'id': 1234,
},
{
'username': 'joe',
'name': 'test-server.example.com',
'type': 'HARDWARE',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': '10.0.0.2',
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1/24 (backend subnet)',
'type': 'SUBNET',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
},
{
'username': 'joe',
'name': '10.0.0.1 (backend ip)',
'type': 'IP',
'host_iqn': 'test-server',
'password': '12345',
'private_ip_address': None,
'id': 1234,
}],
json.loads(result.output),)

def test_authorize_host_to_volume(self):
result = self.run_command(['file', 'access-authorize', '12345678',
Expand Down
7 changes: 7 additions & 0 deletions tests/managers/block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,10 @@ def test_order_block_duplicate_endurance(self):
'osFormatType': {'keyName': 'LINUX'},
'duplicateOriginSnapshotId': 470
},))

def test_setCredentialPassword(self):
mock = self.set_mock('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')
mock.return_value = True
result = self.block.set_credential_password(access_id=102, password='AAAaaa')
self.assertEqual(True, result)
self.assert_called_with('SoftLayer_Network_Storage_Allowed_Host', 'setCredentialPassword')
5 changes: 1 addition & 4 deletions tests/managers/file_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def test_deauthorize_host_to_volume(self):
identifier=50)

def test_get_file_volume_access_list(self):
result = self.file.get_file_volume_access_list(100)

self.assertEqual(fixtures.SoftLayer_Network_Storage.getObject, result)

self.file.get_file_volume_access_list(100)
self.assert_called_with(
'SoftLayer_Network_Storage',
'getObject',
Expand Down