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