Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | PLDM functions. |
| 5 | """ |
| 6 | |
| 7 | import re |
| 8 | import var_funcs as vf |
| 9 | import func_args as fa |
| 10 | import bmc_ssh_utils as bsu |
| 11 | |
| 12 | |
| 13 | def 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 Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 23 | [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 Ramesh | 0126ea0 | 2020-03-30 07:54:29 -0500 | [diff] [blame] | 45 | |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 46 | if parse_results: |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 47 | 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 Ramesh | 0126ea0 | 2020-03-30 07:54:29 -0500 | [diff] [blame] | 58 | |
| 59 | elif 'yyyy-mm-dd_hh' in result: |
Sridevi Ramesh | fe52e40 | 2020-02-05 00:15:24 -0600 | [diff] [blame] | 60 | # Date & Time : |
| 61 | # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16 |
Sridevi Ramesh | 1495bc4 | 2020-02-04 03:13:33 -0600 | [diff] [blame] | 62 | return result['yyyy-mm-dd_hh'].split(' - ')[1] |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 63 | return result |
| 64 | |
| 65 | return stdout |