1#!/usr/bin/env python
2
3r"""
4PEL functions.
5"""
6
7import func_args as fa
8import bmc_ssh_utils as bsu
9import json
10
11
12def peltool(option_string, parse_json=True, **bsu_options):
13    r"""
14    Run peltool on the BMC with the caller's option string and return the result.
15
16    Example:
17
18    ${pel_results}=  Peltool  -l
19    Rprint Vars  pel_results
20
21    pel_results:
22      [0x50000031]:
23        [CompID]:                       0x1000
24        [PLID]:                         0x50000031
25        [Subsystem]:                    BMC Firmware
26        [Message]:                      An application had an internal failure
27        [SRC]:                          BD8D1002
28        [Commit Time]:                  02/25/2020  04:51:31
29        [Sev]:                          Unrecoverable Error
30        [CreatorID]:                    BMC
31
32    Description of argument(s):
33    option_string                   A string of options which are to be processed by the peltool command.
34    parse_json                      Indicates that the raw JSON data should parsed into a list of
35                                    dictionaries.
36    bsu_options                     Options to be passed directly to bmc_execute_command. See its prolog for
37                                    details.
38    """
39
40    bsu_options = fa.args_to_objects(bsu_options)
41    out_buf, stderr, rc = bsu.bmc_execute_command('peltool ' + option_string, **bsu_options)
42    if parse_json:
43        try:
44            return json.loads(out_buf)
45        except json.JSONDecodeError:
46            return {}
47    return out_buf
48