From a06e3cc850ae7165dbe767e03bbe22c114e685b8 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Wed, 9 May 2018 10:56:49 -0400 Subject: [PATCH] OpenBMC rinv more specific REST calls --- .../agent/hwctl/executor/openbmc_flash.py | 2 +- .../agent/hwctl/executor/openbmc_inventory.py | 2 +- .../lib/python/agent/hwctl/openbmc_client.py | 30 ++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py index bdb8c96cc..43be329ea 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_flash.py @@ -528,7 +528,7 @@ class OpenBMCFlashTask(ParallelNodesCommand): try: obmc.login() # Before uploading file, check CPU DD version - inventory_info_dict = obmc.get_inventory_info() + inventory_info_dict = obmc.get_inventory_info('cpu') cpu_info = inventory_info_dict["CPU"] for info in cpu_info: if info.startswith("CPU0 Version : 20"): diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py index a59bd14a6..aa863951b 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/executor/openbmc_inventory.py @@ -83,7 +83,7 @@ class OpenBMCInventoryTask(ParallelNodesCommand): inventory_info = [] try: obmc.login() - inventory_info_dict = obmc.get_inventory_info() + inventory_info_dict = obmc.get_inventory_info(inventory_type) if inventory_type == 'all' or not inventory_type: keys = inventory_info_dict.keys() diff --git a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py index 0401928b3..f4f559186 100644 --- a/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py +++ b/xCAT-openbmc-py/lib/python/agent/hwctl/openbmc_client.py @@ -49,7 +49,13 @@ DUMP_URLS = { GARD_CLEAR_URL = "/org/open_power/control/gard/action/Reset" -INVENTORY_URL = "/inventory/enumerate" +INVENTORY_URLS = { + "all" : "/inventory/enumerate", + "model" : "/inventory/system", + "serial" : "/inventory/system", + "cpu" : "/inventory/system/chassis/motherboard/enumerate", + "dimm" : "/inventory/system/chassis/motherboard/enumerate", +} LEDS_URL = "/led/physical/enumerate" @@ -546,11 +552,19 @@ class OpenBMCRest(object): error = 'Received wrong format response: %s' % sensor_data raise SelfServerException(error) - def get_inventory_info(self): + def get_inventory_info(self, inventory_type): - inventory_data = self.request('GET', INVENTORY_URL, cmd='get_inventory_info') + inventory_data = self.request('GET', INVENTORY_URLS[inventory_type], cmd='get_inventory_info') try: - inverntory_dict = {} + inventory_dict = {} + if inventory_type == 'model' or inventory_type == 'serial': + # The format of returned data for model and serial a different from other inventory types + inventory_dict['SYSTEM'] = [] + for key, value in inventory_data.items(): + inventory_dict['SYSTEM'].append('%s %s : %s' % ("SYSTEM", key, value)) + + return inventory_dict + for key, value in inventory_data.items(): if 'Present' not in value: logger.debug('Not "Present" for %s' % key) @@ -572,13 +586,13 @@ class OpenBMCRest(object): else: source = key_id - if key_type not in inverntory_dict: - inverntory_dict[key_type] = [] + if key_type not in inventory_dict: + inventory_dict[key_type] = [] for (sub_key, v) in value.items(): - inverntory_dict[key_type].append('%s %s : %s' % (source.upper(), sub_key, v)) + inventory_dict[key_type].append('%s %s : %s' % (source.upper(), sub_key, v)) - return inverntory_dict + return inventory_dict except KeyError: error = 'Received wrong format response: %s' % inventory_data raise SelfServerException(error)