blob: 81fbbf072fa7be5286ea212b37e37f233e553973 [file] [log] [blame]
Rahul Maheshwari4d488572019-12-10 23:53:05 -06001#!/usr/bin/env python
2
3r"""
4PLDM functions.
5"""
6
7import re
8import var_funcs as vf
9import func_args as fa
10import bmc_ssh_utils as bsu
11
12
13def pldmtool(option_string, parse_results=1, **bsu_options):
14 r"""
15 Run pldmtool on the BMC with the caller's option string and return the result.
16
17 Example:
18
19 ${pldm_results}= Pldmtool base GetPLDMTypes
20 Rprint Vars pldm_results
21
22 pldm_results:
Rahul Maheshwari4d488572019-12-10 23:53:05 -060023 [supported_types]:
24 [raw]:
25 [0]: 0
26 [1]: 2
27 [2]: 3
28 [text]:
29 [0]: base
30 [1]: platform
31 [2]: bios
32
33 Description of argument(s):
34 option_string A string of options which are to be processed by the pldmtool command.
35 parse_results Parse the pldmtool results and return a dictionary rather than the raw
36 pldmtool output.
37 bsu_options Options to be passed directly to bmc_execute_command. See its prolog for
38 details.
39 """
40
41 # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}).
42 bsu_options = fa.args_to_objects(bsu_options)
43
44 stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options)
Sridevi Ramesh0126ea02020-03-30 07:54:29 -050045
Rahul Maheshwari4d488572019-12-10 23:53:05 -060046 if parse_results:
Rahul Maheshwari4d488572019-12-10 23:53:05 -060047 result = vf.key_value_outbuf_to_dict(stdout)
48 if 'supported_types' in result:
49 # 'supported types' begins like this:
50 # 0(base) 2(platform) 3(bios)
51 # Parsing it to look like it does in the example above.
52 supported_types = {'raw': [], 'text': []}
53 for entry in result['supported_types'].split(" "):
54 record = entry.split("(")
55 supported_types['raw'].append(record[0])
56 supported_types['text'].append(record[1].rstrip(")"))
57 result['supported_types'] = supported_types
Sridevi Ramesh0126ea02020-03-30 07:54:29 -050058
59 elif 'yyyy-mm-dd_hh' in result:
Sridevi Rameshfe52e402020-02-05 00:15:24 -060060 # Date & Time :
61 # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16
Sridevi Ramesh1495bc42020-02-04 03:13:33 -060062 return result['yyyy-mm-dd_hh'].split(' - ')[1]
Rahul Maheshwari4d488572019-12-10 23:53:05 -060063 return result
64
65 return stdout