1e7e9171eSGeorge Keishing#!/usr/bin/env python3 2ef00306eSRahul Maheshwari 3ef00306eSRahul Maheshwarir""" 4ef00306eSRahul MaheshwariVPD functions. 5ef00306eSRahul Maheshwari""" 6ef00306eSRahul Maheshwari 76087e46eSGeorge Keishingimport json 820f38712SPatrick Williams 9e635ddc0SGeorge Keishingimport bmc_ssh_utils as bsu 1020f38712SPatrick Williamsimport func_args as fa 11ef00306eSRahul Maheshwari 12ef00306eSRahul Maheshwari 13*21e78943SSridevi Rameshclass VpdtoolException(Exception): 14*21e78943SSridevi Ramesh r""" 15*21e78943SSridevi Ramesh Base class for vpdtool related exceptions. 16*21e78943SSridevi Ramesh """ 17*21e78943SSridevi Ramesh 18*21e78943SSridevi Ramesh def __init__(self, message): 19*21e78943SSridevi Ramesh self.message = message 20*21e78943SSridevi Ramesh super().__init__(self.message) 21*21e78943SSridevi Ramesh 22*21e78943SSridevi Ramesh 23ef00306eSRahul Maheshwaridef vpdtool(option_string, **bsu_options): 24ef00306eSRahul Maheshwari r""" 25ef00306eSRahul Maheshwari Run vpdtool on the BMC with the caller's option string and return the result. 26ef00306eSRahul Maheshwari 27ef00306eSRahul Maheshwari Example: 28ef00306eSRahul Maheshwari 29ef00306eSRahul Maheshwari ${vpd_results}= vpd-tool -i 30ef00306eSRahul Maheshwari Rprint Vars vpd_results 31ef00306eSRahul Maheshwari 32ef00306eSRahul Maheshwari vpd_results: 33ef00306eSRahul Maheshwari [/system/chassis/motherboard]: 34ef00306eSRahul Maheshwari [PN]: PN12345 35ef00306eSRahul Maheshwari [SN]: YL2E2D010000 36ef00306eSRahul Maheshwari [LocationCode]: U78DA.ND1. -P0 37ef00306eSRahul Maheshwari [CC]: 2E2D 38ef00306eSRahul Maheshwari [DR]: SYSTEM BACKPLANE 39ef00306eSRahul Maheshwari [FN]: F191014 40ef00306eSRahul Maheshwari [type]: xyz.openbmc_project.Inventory.Item.Board.Motherboard 41ef00306eSRahul Maheshwari [/system/chassis/motherboard/ebmc_card_bmc]: 42ef00306eSRahul Maheshwari [PN]: PN12345 43ef00306eSRahul Maheshwari [SN]: YL6B58010000 44ef00306eSRahul Maheshwari [LocationCode]: U78DA.ND1. -P0-C5 45ef00306eSRahul Maheshwari [CC]: 6B58 46ef00306eSRahul Maheshwari [DR]: EBMC 47ef00306eSRahul Maheshwari [FN]: F191014 48ef00306eSRahul Maheshwari [type]: xyz.openbmc_project.Inventory.Item.Bmc 49ef00306eSRahul Maheshwari 50ef00306eSRahul Maheshwari Description of argument(s): 516087e46eSGeorge Keishing option_string A string of options which are to be processed by 526087e46eSGeorge Keishing the vpd-tool command. 536087e46eSGeorge Keishing bsu_options Options to be passed directly to bmc_execute_command. 546087e46eSGeorge Keishing See its prolog for details. 55ef00306eSRahul Maheshwari """ 56ef00306eSRahul Maheshwari 57ef00306eSRahul Maheshwari bsu_options = fa.args_to_objects(bsu_options) 5820f38712SPatrick Williams out_buf, stderr, rc = bsu.bmc_execute_command( 5920f38712SPatrick Williams "vpd-tool " + option_string, **bsu_options 6020f38712SPatrick Williams ) 610ef1e157SRahul Maheshwari 627e9191beSRahul Maheshwari # Only return output if its not a VPD write command. 63*21e78943SSridevi Ramesh try: 6420f38712SPatrick Williams if "-w" not in option_string: 65ef00306eSRahul Maheshwari out_buf = json.loads(out_buf) 6620f38712SPatrick Williams if "-r" in option_string: 67ef00306eSRahul Maheshwari return out_buf 687e9191beSRahul Maheshwari else: 697e9191beSRahul Maheshwari return out_buf[0] 70*21e78943SSridevi Ramesh except Exception as exception: 71*21e78943SSridevi Ramesh raise VpdtoolException( 72*21e78943SSridevi Ramesh "Failed to get VPD data from BMC : " + str(exception) 73*21e78943SSridevi Ramesh ) from exception 74