Skip to content

Commit 9e00da4

Browse files
Merge pull request #1470 from caberos/issue1465
Show component versions on hw detail
2 parents c7d2abc + 00131b2 commit 9e00da4

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

SoftLayer/CLI/hardware/detail.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
from SoftLayer.CLI import helpers
1010
from SoftLayer import utils
1111

12+
# pylint: disable=R0915
13+
1214

1315
@click.command()
1416
@click.argument('identifier')
1517
@click.option('--passwords', is_flag=True, help='Show passwords (check over your shoulder!)')
1618
@click.option('--price', is_flag=True, help='Show associated prices')
19+
@click.option('--components', is_flag=True, default=False, help='Show associated hardware components')
1720
@environment.pass_env
18-
def cli(env, identifier, passwords, price):
21+
def cli(env, identifier, passwords, price, components):
1922
"""Get details for a hardware device."""
2023

2124
hardware = SoftLayer.HardwareManager(env.client)
@@ -66,7 +69,7 @@ def cli(env, identifier, passwords, price):
6669
utils.clean_time(utils.lookup(result, 'lastTransaction', 'modifyDate')))
6770

6871
table.add_row(['last_transaction', last_transaction])
69-
table.add_row(['billing', 'Hourly' if result['hourlyBillingFlag'] else'Monthly'])
72+
table.add_row(['billing', 'Hourly' if result['hourlyBillingFlag'] else 'Monthly'])
7073

7174
vlan_table = formatting.Table(['type', 'number', 'id'])
7275
for vlan in result['networkVlans']:
@@ -107,6 +110,24 @@ def cli(env, identifier, passwords, price):
107110
pass_table.add_row([item['username'], item['password']])
108111
table.add_row(['remote users', pass_table])
109112

113+
if components:
114+
components = hardware.get_components(identifier)
115+
components_table = formatting.Table(['name', 'Firmware version', 'Firmware build date', 'Type'])
116+
components_table.align['date'] = 'l'
117+
component_ids = []
118+
for hw_component in components:
119+
if hw_component['id'] not in component_ids:
120+
firmware = hw_component['hardwareComponentModel']['firmwares'][0]
121+
components_table.add_row([utils.lookup(hw_component, 'hardwareComponentModel', 'longDescription'),
122+
utils.lookup(firmware, 'version'),
123+
utils.clean_time(utils.lookup(firmware, 'createDate')),
124+
utils.lookup(hw_component, 'hardwareComponentModel',
125+
'hardwareGenericComponentModel', 'hardwareComponentType',
126+
'keyName')])
127+
component_ids.append(hw_component['id'])
128+
129+
table.add_row(['components', components_table])
130+
110131
table.add_row(['tags', formatting.tags(result['tagReferences'])])
111132

112133
env.fout(table)

SoftLayer/fixtures/SoftLayer_Hardware_Server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,21 @@
377377
}
378378
}
379379
]
380+
381+
getComponents = [{
382+
"hardwareComponentModelId": 147,
383+
"hardwareId": 1234,
384+
"id": 369,
385+
"modifyDate": "2017-11-10T16:59:38-06:00",
386+
"serviceProviderId": 1,
387+
"hardwareComponentModel": {
388+
"name": "IMM2 - Onboard",
389+
"firmwares": [
390+
{
391+
"createDate": "2020-09-24T13:46:29-06:00",
392+
"version": "5.60"
393+
},
394+
{
395+
"createDate": "2019-10-14T16:51:12-06:00",
396+
"version": "5.10"
397+
}]}}]

SoftLayer/managers/hardware.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,41 @@ def _get_disk_price_detail(self, disk_data, upgrade_prices, disk_channel, disk_t
10301030

10311031
return disk_price
10321032

1033+
def get_components(self, hardware_id, mask=None, filter_component=None):
1034+
"""Get details about a hardware components.
1035+
1036+
:param int hardware_id: the instance ID
1037+
:returns: A dictionary containing a large amount of information about
1038+
the specified components.
1039+
"""
1040+
if not mask:
1041+
mask = 'id,hardwareComponentModel[longDescription,' \
1042+
'hardwareGenericComponentModel[description,hardwareComponentType[keyName]],' \
1043+
'firmwares[createDate,version]]'
1044+
1045+
if not filter_component:
1046+
filter_component = {"components": {
1047+
"hardwareComponentModel": {
1048+
"firmwares": {
1049+
"createDate": {
1050+
"operation": "orderBy",
1051+
"options": [
1052+
{
1053+
"name": "sort",
1054+
"value": [
1055+
"DESC"
1056+
]
1057+
},
1058+
{
1059+
"name": "sortOrder",
1060+
"value": [
1061+
1
1062+
]}]}
1063+
}}}}
1064+
1065+
return self.client.call('Hardware_Server', 'getComponents',
1066+
mask=mask, filter=filter_component, id=hardware_id)
1067+
10331068

10341069
def _get_bandwidth_key(items, hourly=True, no_public=False, location=None):
10351070
"""Picks a valid Bandwidth Item, returns the KeyName"""

tests/CLI/modules/server_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,3 +985,7 @@ def test_upgrade(self, confirm_mock):
985985
'--drive-controller=RAID', '--network=10000 Redundant'])
986986

987987
self.assert_no_fail(result)
988+
989+
def test_components(self):
990+
result = self.run_command(['hardware', 'detail', '100', '--components'])
991+
self.assert_no_fail(result)

tests/managers/hardware_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,26 @@ def test_upgrade_full(self):
928928
self.assertIn({'id': 22482}, order_container['prices'])
929929
self.assertIn({'id': 50357}, order_container['prices'])
930930

931+
def test_get_components(self):
932+
result = self.hardware.get_components(1234)
933+
components = [{'hardwareComponentModelId': 147,
934+
'hardwareId': 1234,
935+
'id': 369,
936+
'modifyDate': '2017-11-10T16:59:38-06:00',
937+
'serviceProviderId': 1,
938+
'hardwareComponentModel':
939+
{'name': 'IMM2 - Onboard',
940+
'firmwares':
941+
[{'createDate': '2020-09-24T13:46:29-06:00',
942+
'version': '5.60'},
943+
{'createDate': '2019-10-14T16:51:12-06:00',
944+
'version': '5.10'}]}}]
945+
self.assert_called_with('SoftLayer_Hardware_Server', 'getComponents')
946+
self.assertEqual(result, components)
947+
self.assertEqual(result[0]['hardwareId'], 1234)
948+
self.assertEqual(result[0]['hardwareComponentModel']['name'], 'IMM2 - Onboard')
949+
self.assertEqual(result[0]['hardwareComponentModel']['firmwares'][0]['version'], '5.60')
950+
931951

932952
class HardwareHelperTests(testing.TestCase):
933953

0 commit comments

Comments
 (0)