George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | VPD functions. |
| 5 | """ |
| 6 | |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 7 | import json |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 8 | |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 9 | import bmc_ssh_utils as bsu |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | import func_args as fa |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 11 | |
| 12 | |
Sridevi Ramesh | 21e7894 | 2025-01-26 03:06:18 -0600 | [diff] [blame] | 13 | class VpdtoolException(Exception): |
| 14 | r""" |
| 15 | Base class for vpdtool related exceptions. |
| 16 | """ |
| 17 | |
| 18 | def __init__(self, message): |
| 19 | self.message = message |
| 20 | super().__init__(self.message) |
| 21 | |
| 22 | |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 23 | def vpdtool(option_string, **bsu_options): |
| 24 | r""" |
| 25 | Run vpdtool on the BMC with the caller's option string and return the result. |
| 26 | |
| 27 | Example: |
| 28 | |
| 29 | ${vpd_results}= vpd-tool -i |
| 30 | Rprint Vars vpd_results |
| 31 | |
| 32 | vpd_results: |
| 33 | [/system/chassis/motherboard]: |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 34 | [PN]: PN12345 |
| 35 | [SN]: YL2E2D010000 |
| 36 | [LocationCode]: U78DA.ND1. -P0 |
| 37 | [CC]: 2E2D |
| 38 | [DR]: SYSTEM BACKPLANE |
| 39 | [FN]: F191014 |
| 40 | [type]: xyz.openbmc_project.Inventory.Item.Board.Motherboard |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 41 | [/system/chassis/motherboard/ebmc_card_bmc]: |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 42 | [PN]: PN12345 |
| 43 | [SN]: YL6B58010000 |
| 44 | [LocationCode]: U78DA.ND1. -P0-C5 |
| 45 | [CC]: 6B58 |
| 46 | [DR]: EBMC |
| 47 | [FN]: F191014 |
| 48 | [type]: xyz.openbmc_project.Inventory.Item.Bmc |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 49 | |
| 50 | Description of argument(s): |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 51 | option_string A string of options which are to be processed by |
| 52 | the vpd-tool command. |
| 53 | bsu_options Options to be passed directly to bmc_execute_command. |
| 54 | See its prolog for details. |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 55 | """ |
| 56 | |
| 57 | bsu_options = fa.args_to_objects(bsu_options) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 58 | out_buf, stderr, rc = bsu.bmc_execute_command( |
| 59 | "vpd-tool " + option_string, **bsu_options |
| 60 | ) |
Rahul Maheshwari | 0ef1e15 | 2020-11-02 23:10:55 -0600 | [diff] [blame] | 61 | |
Rahul Maheshwari | 7e9191b | 2020-12-08 23:55:04 -0600 | [diff] [blame] | 62 | # Only return output if its not a VPD write command. |
Sridevi Ramesh | 21e7894 | 2025-01-26 03:06:18 -0600 | [diff] [blame] | 63 | try: |
| 64 | if "-w" not in option_string: |
| 65 | out_buf = json.loads(out_buf) |
| 66 | if "-r" in option_string: |
| 67 | return out_buf |
| 68 | else: |
| 69 | return out_buf[0] |
| 70 | except Exception as exception: |
| 71 | raise VpdtoolException( |
| 72 | "Failed to get VPD data from BMC : " + str(exception) |
| 73 | ) from exception |