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 | |
| 13 | def vpdtool(option_string, **bsu_options): |
| 14 | r""" |
| 15 | Run vpdtool on the BMC with the caller's option string and return the result. |
| 16 | |
| 17 | Example: |
| 18 | |
| 19 | ${vpd_results}= vpd-tool -i |
| 20 | Rprint Vars vpd_results |
| 21 | |
| 22 | vpd_results: |
| 23 | [/system/chassis/motherboard]: |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 24 | [PN]: PN12345 |
| 25 | [SN]: YL2E2D010000 |
| 26 | [LocationCode]: U78DA.ND1. -P0 |
| 27 | [CC]: 2E2D |
| 28 | [DR]: SYSTEM BACKPLANE |
| 29 | [FN]: F191014 |
| 30 | [type]: xyz.openbmc_project.Inventory.Item.Board.Motherboard |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 31 | [/system/chassis/motherboard/ebmc_card_bmc]: |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 32 | [PN]: PN12345 |
| 33 | [SN]: YL6B58010000 |
| 34 | [LocationCode]: U78DA.ND1. -P0-C5 |
| 35 | [CC]: 6B58 |
| 36 | [DR]: EBMC |
| 37 | [FN]: F191014 |
| 38 | [type]: xyz.openbmc_project.Inventory.Item.Bmc |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 39 | |
| 40 | Description of argument(s): |
George Keishing | 6087e46 | 2022-09-19 08:01:44 -0500 | [diff] [blame] | 41 | option_string A string of options which are to be processed by |
| 42 | the vpd-tool command. |
| 43 | bsu_options Options to be passed directly to bmc_execute_command. |
| 44 | See its prolog for details. |
Rahul Maheshwari | ef00306 | 2020-03-23 07:17:16 -0500 | [diff] [blame] | 45 | """ |
| 46 | |
| 47 | bsu_options = fa.args_to_objects(bsu_options) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 48 | out_buf, stderr, rc = bsu.bmc_execute_command( |
| 49 | "vpd-tool " + option_string, **bsu_options |
| 50 | ) |
Rahul Maheshwari | 0ef1e15 | 2020-11-02 23:10:55 -0600 | [diff] [blame] | 51 | |
Rahul Maheshwari | 7e9191b | 2020-12-08 23:55:04 -0600 | [diff] [blame] | 52 | # Only return output if its not a VPD write command. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 53 | if "-w" not in option_string: |
Rahul Maheshwari | 0ef1e15 | 2020-11-02 23:10:55 -0600 | [diff] [blame] | 54 | out_buf = json.loads(out_buf) |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 55 | if "-r" in option_string: |
Rahul Maheshwari | 7e9191b | 2020-12-08 23:55:04 -0600 | [diff] [blame] | 56 | return out_buf |
| 57 | else: |
| 58 | return out_buf[0] |