blob: 03581bbe5324a4a5acee71fb8312bec52ef82ebe [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
Rahul Maheshwarief003062020-03-23 07:17:16 -05008import func_args as fa
9import bmc_ssh_utils as bsu
Rahul Maheshwarief003062020-03-23 07:17:16 -050010
11
12def 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]:
George Keishing6087e462022-09-19 08:01:44 -050023 [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
Rahul Maheshwarief003062020-03-23 07:17:16 -050030 [/system/chassis/motherboard/ebmc_card_bmc]:
George Keishing6087e462022-09-19 08:01:44 -050031 [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
Rahul Maheshwarief003062020-03-23 07:17:16 -050038
39 Description of argument(s):
George Keishing6087e462022-09-19 08:01:44 -050040 option_string A string of options which are to be processed by
41 the vpd-tool command.
42 bsu_options Options to be passed directly to bmc_execute_command.
43 See its prolog for details.
Rahul Maheshwarief003062020-03-23 07:17:16 -050044 """
45
46 bsu_options = fa.args_to_objects(bsu_options)
47 out_buf, stderr, rc = bsu.bmc_execute_command('vpd-tool ' + option_string, **bsu_options)
Rahul Maheshwari0ef1e152020-11-02 23:10:55 -060048
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060049 # Only return output if its not a VPD write command.
50 if '-w' not in option_string:
Rahul Maheshwari0ef1e152020-11-02 23:10:55 -060051 out_buf = json.loads(out_buf)
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060052 if '-r' in option_string:
53 return out_buf
54 else:
55 return out_buf[0]