blob: 754d255597b96147eab6e0084a1396b32d2276c4 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Rahul Maheshwarief003062020-03-23 07:17:16 -05002
3r"""
4VPD functions.
5"""
6
George Keishing6087e462022-09-19 08:01:44 -05007import json
Patrick Williams20f38712022-12-08 06:18:26 -06008
George Keishinge635ddc2022-12-08 07:38:02 -06009import bmc_ssh_utils as bsu
Patrick Williams20f38712022-12-08 06:18:26 -060010import func_args as fa
Rahul Maheshwarief003062020-03-23 07:17:16 -050011
12
13def 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 Keishing6087e462022-09-19 08:01:44 -050024 [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 Maheshwarief003062020-03-23 07:17:16 -050031 [/system/chassis/motherboard/ebmc_card_bmc]:
George Keishing6087e462022-09-19 08:01:44 -050032 [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 Maheshwarief003062020-03-23 07:17:16 -050039
40 Description of argument(s):
George Keishing6087e462022-09-19 08:01:44 -050041 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 Maheshwarief003062020-03-23 07:17:16 -050045 """
46
47 bsu_options = fa.args_to_objects(bsu_options)
Patrick Williams20f38712022-12-08 06:18:26 -060048 out_buf, stderr, rc = bsu.bmc_execute_command(
49 "vpd-tool " + option_string, **bsu_options
50 )
Rahul Maheshwari0ef1e152020-11-02 23:10:55 -060051
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060052 # Only return output if its not a VPD write command.
Patrick Williams20f38712022-12-08 06:18:26 -060053 if "-w" not in option_string:
Rahul Maheshwari0ef1e152020-11-02 23:10:55 -060054 out_buf = json.loads(out_buf)
Patrick Williams20f38712022-12-08 06:18:26 -060055 if "-r" in option_string:
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060056 return out_buf
57 else:
58 return out_buf[0]