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: |
| 23 | [request_message]: 08 01 80 00 04 |
| 24 | [success_in_creating_the_socket]: RC = 3 |
| 25 | [success_in_connecting_to_socket]: RC = 0 |
| 26 | [success_in_sending_message_type_as_pldm_to_mctp]:RC = 0 |
| 27 | [write_to_socket_successful]: RC = 5 |
| 28 | [total_length]: 14 |
| 29 | [loopback_response_message]: 08 01 80 00 04 |
| 30 | [on_first_recv(),response_==_request]: RC = 0 |
| 31 | [shutdown_socket_successful]: RC = 0 |
| 32 | [response_message]: 08 01 00 00 04 00 0d 00 00 00 00 00 00 00 |
| 33 | [supported_types]: |
| 34 | [raw]: |
| 35 | [0]: 0 |
| 36 | [1]: 2 |
| 37 | [2]: 3 |
| 38 | [text]: |
| 39 | [0]: base |
| 40 | [1]: platform |
| 41 | [2]: bios |
| 42 | |
| 43 | Description of argument(s): |
| 44 | option_string A string of options which are to be processed by the pldmtool command. |
| 45 | parse_results Parse the pldmtool results and return a dictionary rather than the raw |
| 46 | pldmtool output. |
| 47 | bsu_options Options to be passed directly to bmc_execute_command. See its prolog for |
| 48 | details. |
| 49 | """ |
| 50 | |
| 51 | # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}). |
| 52 | bsu_options = fa.args_to_objects(bsu_options) |
| 53 | |
| 54 | stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options) |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 55 | if parse_results: |
| 56 | # Remove linefeeds following colons. |
| 57 | stdout = re.sub(":\n", ":", stdout) |
| 58 | # Remove first line (e.g. "Encode request successfully"). |
| 59 | stdout = re.sub("^.*\\n", "", stdout) |
| 60 | result = vf.key_value_outbuf_to_dict(stdout) |
| 61 | if 'supported_types' in result: |
| 62 | # 'supported types' begins like this: |
| 63 | # 0(base) 2(platform) 3(bios) |
| 64 | # Parsing it to look like it does in the example above. |
| 65 | supported_types = {'raw': [], 'text': []} |
| 66 | for entry in result['supported_types'].split(" "): |
| 67 | record = entry.split("(") |
| 68 | supported_types['raw'].append(record[0]) |
| 69 | supported_types['text'].append(record[1].rstrip(")")) |
| 70 | result['supported_types'] = supported_types |
Sridevi Ramesh | 1495bc4 | 2020-02-04 03:13:33 -0600 | [diff] [blame^] | 71 | |
| 72 | if 'date_&_time' in result: |
| 73 | return result['yyyy-mm-dd_hh'].split(' - ')[1] |
| 74 | |
Rahul Maheshwari | 4d48857 | 2019-12-10 23:53:05 -0600 | [diff] [blame] | 75 | return result |
| 76 | |
| 77 | return stdout |