blob: ea41125d19576d1ae99630ddd8ecbac09f1b9983 [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
Sridevi Ramesh039bc762020-03-30 09:59:07 -050059 elif 'supported_commands' in result:
60 commands = result['supported_commands'].split(":")[0].split(" ")
61 return commands
62
Sridevi Ramesh0126ea02020-03-30 07:54:29 -050063 elif 'yyyy-mm-dd_hh' in result:
Sridevi Rameshfe52e402020-02-05 00:15:24 -060064 # Date & Time :
65 # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16
Sridevi Ramesh1495bc42020-02-04 03:13:33 -060066 return result['yyyy-mm-dd_hh'].split(' - ')[1]
Sridevi Ramesh538d18d2020-03-30 11:45:42 -050067
68 # Simplfying dict output for GetPDR with type PDREntityAssociation.
69 # Example :
70
71 # pldmtool platform GetPDR -d 10
72 # Entity Association
73 # nextRecordHandle: 0
74 # responseCount: 56
75 # recordHandle: 10
76 # PDRHeaderVersion: 1
77 # PDRType: 15
78 # recordChangeNumber: 0
79 # dataLength: 46
80 # containerID: 1
81 # associationType: Physical
82 # containerEntityType: System Board
83 # containerEntityInstanceNumber: 1
84 # containerEntityContainerID: 0
85 # containedEntityCount: 6
86 # containedEntityType[1]: Chassis front panel board (control panel)
87 # containedEntityInstanceNumber[1]: 1
88 # containedEntityContainerID[1]: 1
89 # containedEntityType[2]: Chassis front panel board (control panel)
90 # containedEntityInstanceNumber[2]: 2
91 # containedEntityContainerID[2]: 1
92 elif 'containerentitycontainerid' in result:
93 dict_data1, dict_data2 = vf.split_dict_on_key('containerentitycontainerid', result)
94 return dict_data1
95
Sridevi Ramesh072d5af2020-06-02 09:20:57 -050096 elif 'entitytype' in result:
97 # Example :
98 # entityType: 24576(OEM)
99 # Note: OEM type number is dynamic
100 if 'OEM' in result['entitytype']:
101 result['entitytype'] = 'OEM'
102
Sridevi Rameshf60581b2020-04-07 05:11:12 -0500103 # Collect bios strings from bios string table in to list.
104 # Example output for pldmtool GetBIOSTable --type stringTable
105 # PLDM StringTable:
106 # BIOSStringHandle : BIOSString
107 # 0 : Allowed
108 # 1 : Disabled
109 # 2 : Enabled
110 elif 'pldm_stringtable' in result:
111 result.pop('pldm_stringtable')
112 result.pop('biosstringhandle')
113 bios_string_list = []
114 for data in result:
115 bios_string_list.append(result[data])
116 # Example for bios_string_list:
117 # bios_string_list = ['Allowed', 'Disabled', 'Enabled']
118 return bios_string_list
119
120 # Check if parameter pldm_attributetable/pldm_attributevaluetable present for
121 # pldmtool GetBIOSTable --type AttributeTable/AttributeValueTable.
George Keishing1faaa462020-04-16 10:27:20 -0500122 # Note: Output for AttributeTable/AttributeValueTable is huge and verification of
Sridevi Rameshf60581b2020-04-07 05:11:12 -0500123 # table content is not available.
124 elif 'pldm_attributetable' in result:
125 result['pldm_attributetable'] = True
126 return result
127 elif 'pldm_attributevaluetable' in result:
128 result['pldm_attributevaluetable'] = True
129 return result
130
Rahul Maheshwari4d488572019-12-10 23:53:05 -0600131 return result
132
133 return stdout