Browse Source

Add ability to retrieve system properties

Change-Id: I7ae6efb913895c86aab838481b6025c8a17a42ee
changes/88/589088/4
digambar 3 years ago
parent
commit
0960fba23a
4 changed files with 58 additions and 1 deletions
  1. +9
    -0
      dracclient/client.py
  2. +32
    -0
      dracclient/resources/inventory.py
  3. +14
    -0
      dracclient/tests/test_inventory.py
  4. +3
    -1
      dracclient/tests/wsman_mocks/system_view-enum-ok.xml

+ 9
- 0
dracclient/client.py View File

@ -716,6 +716,15 @@ class DRACClient(object):
return self._inventory_mgmt.list_nics()
def get_system(self):
"""Return a Systen object.
:returns: a System object
:raises: WSManRequestFailure on request failures
:raises: WSManInvalidResponse when receiving invalid response
"""
return self._inventory_mgmt.get_system()
def is_idrac_ready(self):
"""Indicates if the iDRAC is ready to accept commands


+ 32
- 0
dracclient/resources/inventory.py View File

@ -57,6 +57,10 @@ NIC = collections.namedtuple(
'NIC',
['id', 'mac', 'model', 'speed_mbps', 'duplex', 'media_type'])
System = collections.namedtuple(
'System',
['id', 'lcc_version', 'model', 'service_tag'])
class InventoryManagement(object):
@ -170,3 +174,31 @@ class InventoryManagement(object):
def _get_nic_attr(self, drac_nic, attr_name):
return utils.get_wsman_resource_attr(drac_nic, uris.DCIM_NICView,
attr_name)
def get_system(self):
"""Returns a System object
:returns: a System object
:raises: WSManRequestFailure on request failures
:raises: WSManInvalidRespons when receiving invalid response
"""
doc = self.client.enumerate(uris.DCIM_SystemView)
drac_system = utils.find_xml(doc,
'DCIM_SystemView',
uris.DCIM_SystemView,
find_all=False)
return self._parse_drac_system(drac_system)
def _parse_drac_system(self, drac_system):
return System(
id=self._get_system_attr(drac_system, 'InstanceID'),
service_tag=self._get_system_attr(drac_system, 'ServiceTag'),
model=self._get_system_attr(drac_system, 'Model'),
lcc_version=self._get_system_attr(drac_system,
'LifecycleControllerVersion'))
def _get_system_attr(self, drac_system, attr_name):
return utils.get_wsman_resource_attr(drac_system,
uris.DCIM_SystemView,
attr_name)

+ 14
- 0
dracclient/tests/test_inventory.py View File

@ -129,3 +129,17 @@ class ClientInventoryManagementTestCase(base.BaseTest):
self.assertEqual(
expected_nics,
self.drac_client.list_nics())
def test_get_system(self, mock_requests, mock_wait_until_idrac_is_ready):
expected_system = inventory.System(
id='System.Embedded.1',
service_tag='A1B2C3D',
model='PowerEdge R630',
lcc_version='2.1.0')
mock_requests.post(
'https://1.2.3.4:443/wsman',
text=test_utils.LifecycleControllerEnumerations[
uris.DCIM_SystemView]['ok'])
self.assertEqual(
expected_system,
self.drac_client.get_system())

+ 3
- 1
dracclient/tests/wsman_mocks/system_view-enum-ok.xml View File

@ -15,9 +15,11 @@
<n1:DCIM_SystemView>
<n1:InstanceID>System.Embedded.1</n1:InstanceID>
<n1:LifecycleControllerVersion>2.1.0</n1:LifecycleControllerVersion>
<n1:Model>PowerEdge R630</n1:Model>
<n1:ServiceTag>A1B2C3D</n1:ServiceTag>
</n1:DCIM_SystemView>
</wsman:Items>
<wsman:EndOfSequence/>
</wsen:EnumerateResponse>
</s:Body>
</s:Envelope>
</s:Envelope>

Loading…
Cancel
Save