From 4007d758b43dbf7c1562200bd69210c9a690e236 Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Thu, 20 Feb 2020 18:02:41 -0400 Subject: [PATCH 1/2] Fix the block and file storage detail. --- SoftLayer/CLI/block/detail.py | 15 ++++++++++- SoftLayer/CLI/file/detail.py | 15 ++++++++++- tests/CLI/modules/block_tests.py | 43 ++++++++++++++++++++++++++++++++ tests/CLI/modules/file_tests.py | 43 ++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/block/detail.py b/SoftLayer/CLI/block/detail.py index 6b1b7288c..73e93298f 100644 --- a/SoftLayer/CLI/block/detail.py +++ b/SoftLayer/CLI/block/detail.py @@ -5,16 +5,29 @@ import SoftLayer from SoftLayer.CLI import environment from SoftLayer.CLI import formatting +from SoftLayer.CLI import helpers from SoftLayer import utils +def get_block_volume_id(volume_id, block_manager): + storage_list = block_manager.list_block_volumes() + for storage in storage_list: + if volume_id == storage['username']: + volume_id = storage['id'] + break + + return volume_id + + @click.command() @click.argument('volume_id') @environment.pass_env def cli(env, volume_id): """Display details for a specified volume.""" block_manager = SoftLayer.BlockStorageManager(env.client) - block_volume = block_manager.get_block_volume_details(volume_id) + volume_id = get_block_volume_id(volume_id, block_manager) + block_volume_id = helpers.resolve_id(block_manager.resolve_ids, volume_id, 'Block Volume') + block_volume = block_manager.get_block_volume_details(block_volume_id) block_volume = utils.NestedDict(block_volume) table = formatting.KeyValueTable(['Name', 'Value']) diff --git a/SoftLayer/CLI/file/detail.py b/SoftLayer/CLI/file/detail.py index 02bb5c17a..25af366f2 100644 --- a/SoftLayer/CLI/file/detail.py +++ b/SoftLayer/CLI/file/detail.py @@ -5,16 +5,29 @@ import SoftLayer from SoftLayer.CLI import environment from SoftLayer.CLI import formatting +from SoftLayer.CLI import helpers from SoftLayer import utils +def get_file_volume_id(volume_id, file_manager): + storage_list = file_manager.list_file_volumes() + for storage in storage_list: + if volume_id == storage['username']: + volume_id = storage['id'] + break + + return volume_id + + @click.command() @click.argument('volume_id') @environment.pass_env def cli(env, volume_id): """Display details for a specified volume.""" file_manager = SoftLayer.FileStorageManager(env.client) - file_volume = file_manager.get_file_volume_details(volume_id) + volume_id = get_file_volume_id(volume_id, file_manager) + file_volume_id = helpers.resolve_id(file_manager.resolve_ids, volume_id, 'File Storage') + file_volume = file_manager.get_file_volume_details(file_volume_id) file_volume = utils.NestedDict(file_volume) table = formatting.KeyValueTable(['Name', 'Value']) diff --git a/tests/CLI/modules/block_tests.py b/tests/CLI/modules/block_tests.py index e59288981..42e574c48 100644 --- a/tests/CLI/modules/block_tests.py +++ b/tests/CLI/modules/block_tests.py @@ -98,6 +98,49 @@ def test_volume_detail(self): ] }, json.loads(result.output)) + def test_volume_detail_name_identifier(self): + result = self.run_command(['block', 'volume-detail', 'username']) + + self.assert_no_fail(result) + isinstance(json.loads(result.output)['IOPs'], float) + self.assertEqual({ + 'Username': 'username', + 'LUN Id': '2', + 'Endurance Tier': 'READHEAVY_TIER', + 'IOPs': 1000, + 'Snapshot Capacity (GB)': '10', + 'Snapshot Used (Bytes)': 1024, + 'Capacity (GB)': '20GB', + 'Target IP': '10.1.2.3', + 'Data Center': 'dal05', + 'Type': 'ENDURANCE', + 'ID': 100, + '# of Active Transactions': '1', + 'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server', + 'Replicant Count': '1', + 'Replication Status': 'Replicant Volume Provisioning ' + 'has completed.', + 'Replicant Volumes': [[ + {'Replicant ID': 'Volume Name', '1784': 'TEST_REP_1'}, + {'Replicant ID': 'Target IP', '1784': '10.3.174.79'}, + {'Replicant ID': 'Data Center', '1784': 'wdc01'}, + {'Replicant ID': 'Schedule', '1784': 'REPLICATION_HOURLY'}, + ], [ + {'Replicant ID': 'Volume Name', '1785': 'TEST_REP_2'}, + {'Replicant ID': 'Target IP', '1785': '10.3.177.84'}, + {'Replicant ID': 'Data Center', '1785': 'dal01'}, + {'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'}, + ]], + 'Original Volume Properties': [ + {'Property': 'Original Volume Size', + 'Value': '20'}, + {'Property': 'Original Volume Name', + 'Value': 'test-original-volume-name'}, + {'Property': 'Original Snapshot Name', + 'Value': 'test-original-snapshot-name'} + ] + }, json.loads(result.output)) + def test_volume_list(self): result = self.run_command(['block', 'volume-list']) diff --git a/tests/CLI/modules/file_tests.py b/tests/CLI/modules/file_tests.py index e1d8628cb..e5e3ca556 100644 --- a/tests/CLI/modules/file_tests.py +++ b/tests/CLI/modules/file_tests.py @@ -163,6 +163,49 @@ def test_volume_detail(self): ] }, json.loads(result.output)) + def test_volume_detail_name_identifier(self): + result = self.run_command(['file', 'volume-detail', 'user']) + + self.assert_no_fail(result) + self.assertEqual({ + 'Username': 'username', + 'Used Space': '0B', + 'Endurance Tier': 'READHEAVY_TIER', + 'IOPs': 1000, + 'Mount Address': '127.0.0.1:/TEST', + 'Snapshot Capacity (GB)': '10', + 'Snapshot Used (Bytes)': 1024, + 'Capacity (GB)': '20GB', + 'Target IP': '10.1.2.3', + 'Data Center': 'dal05', + 'Type': 'ENDURANCE', + 'ID': 100, + '# of Active Transactions': '1', + 'Ongoing Transaction': 'This is a buffer time in which the customer may cancel the server', + 'Replicant Count': '1', + 'Replication Status': 'Replicant Volume Provisioning ' + 'has completed.', + 'Replicant Volumes': [[ + {'Replicant ID': 'Volume Name', '1784': 'TEST_REP_1'}, + {'Replicant ID': 'Target IP', '1784': '10.3.174.79'}, + {'Replicant ID': 'Data Center', '1784': 'wdc01'}, + {'Replicant ID': 'Schedule', '1784': 'REPLICATION_HOURLY'}, + ], [ + {'Replicant ID': 'Volume Name', '1785': 'TEST_REP_2'}, + {'Replicant ID': 'Target IP', '1785': '10.3.177.84'}, + {'Replicant ID': 'Data Center', '1785': 'dal01'}, + {'Replicant ID': 'Schedule', '1785': 'REPLICATION_DAILY'}, + ]], + 'Original Volume Properties': [ + {'Property': 'Original Volume Size', + 'Value': '20'}, + {'Property': 'Original Volume Name', + 'Value': 'test-original-volume-name'}, + {'Property': 'Original Snapshot Name', + 'Value': 'test-original-snapshot-name'} + ] + }, json.loads(result.output)) + def test_volume_order_performance_iops_not_given(self): result = self.run_command(['file', 'volume-order', '--storage-type=performance', '--size=20', From b07e0ecd2ebb109ef3babb3df4b19edfb6706a3c Mon Sep 17 00:00:00 2001 From: Fernando Ojeda Date: Thu, 20 Feb 2020 18:18:33 -0400 Subject: [PATCH 2/2] Add docstring for block and file new method. --- SoftLayer/CLI/block/detail.py | 6 ++++++ SoftLayer/CLI/file/detail.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/SoftLayer/CLI/block/detail.py b/SoftLayer/CLI/block/detail.py index 73e93298f..02ce0c82f 100644 --- a/SoftLayer/CLI/block/detail.py +++ b/SoftLayer/CLI/block/detail.py @@ -10,6 +10,12 @@ def get_block_volume_id(volume_id, block_manager): + """Returns the volume id. + + :param volume_id: ID of volume. + :param block_manager: Block Storage Manager. + :return: Returns the volume id. + """ storage_list = block_manager.list_block_volumes() for storage in storage_list: if volume_id == storage['username']: diff --git a/SoftLayer/CLI/file/detail.py b/SoftLayer/CLI/file/detail.py index 25af366f2..ad0393916 100644 --- a/SoftLayer/CLI/file/detail.py +++ b/SoftLayer/CLI/file/detail.py @@ -10,6 +10,12 @@ def get_file_volume_id(volume_id, file_manager): + """Returns the volume id. + + :param volume_id: ID of volume. + :param block_manager: Block Storage Manager. + :return: Returns the volume id. + """ storage_list = file_manager.list_file_volumes() for storage in storage_list: if volume_id == storage['username']: