blob: eb31c71fe5f40824f342daeba4b34295c1af926c [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
7import func_args as fa
8import bmc_ssh_utils as bsu
9import json
10
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]:
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 Maheshwari0ef1e152020-11-02 23:10:55 -060047
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060048 # Only return output if its not a VPD write command.
49 if '-w' not in option_string:
Rahul Maheshwari0ef1e152020-11-02 23:10:55 -060050 out_buf = json.loads(out_buf)
Rahul Maheshwari7e9191b2020-12-08 23:55:04 -060051 if '-r' in option_string:
52 return out_buf
53 else:
54 return out_buf[0]