1#!/usr/bin/env python 2 3r""" 4Provide useful ipmi functions. 5""" 6 7import gen_print as gp 8import gen_misc as gm 9import gen_robot_keyword as grk 10import gen_robot_utils as gru 11import bmc_ssh_utils as bsu 12import var_funcs as vf 13import tempfile 14gru.my_import_resource("ipmi_client.robot") 15from robot.libraries.BuiltIn import BuiltIn 16 17 18def get_sol_info(): 19 20 r""" 21 Get all SOL info and return it as a dictionary. 22 23 Example use: 24 25 Robot code: 26 ${sol_info}= get_sol_info 27 Rpvars sol_info 28 29 Output: 30 sol_info: 31 sol_info[Info]: SOL parameter 'Payload Channel (7)' not supported - defaulting to 0x0e 32 sol_info[Character Send Threshold]: 1 33 sol_info[Force Authentication]: true 34 sol_info[Privilege Level]: USER 35 sol_info[Set in progress]: set-complete 36 sol_info[Retry Interval (ms)]: 100 37 sol_info[Non-Volatile Bit Rate (kbps)]: IPMI-Over-Serial-Setting 38 sol_info[Character Accumulate Level (ms)]: 100 39 sol_info[Enabled]: true 40 sol_info[Volatile Bit Rate (kbps)]: IPMI-Over-Serial-Setting 41 sol_info[Payload Channel]: 14 (0x0e) 42 sol_info[Payload Port]: 623 43 sol_info[Force Encryption]: true 44 sol_info[Retry Count]: 7 45 """ 46 47 status, ret_values = grk.run_key_u("Run IPMI Standard Command sol info") 48 49 # Create temp file path. 50 temp = tempfile.NamedTemporaryFile() 51 temp_file_path = temp.name 52 53 # Write sol info to temp file path. 54 text_file = open(temp_file_path, "w") 55 text_file.write(ret_values) 56 text_file.close() 57 58 # Use my_parm_file to interpret data. 59 sol_info = gm.my_parm_file(temp_file_path) 60 61 return sol_info 62 63 64def set_sol_setting(setting_name, setting_value): 65 66 r""" 67 Set SOL setting with given value. 68 69 # Description of argument(s): 70 # setting_name SOL setting which needs to be set (e.g. "retry-count"). 71 # setting_value Value which needs to be set (e.g. "7"). 72 """ 73 74 status, ret_values = grk.run_key_u("Run IPMI Standard Command sol set " + 75 setting_name + " " + setting_value) 76 77 return status 78 79 80def get_lan_print_dict(): 81 82 r""" 83 Get IPMI 'lan print' output and return it as a dictionary. 84 85 Here is an example of the IPMI lan print output: 86 87 Set in Progress : Set Complete 88 Auth Type Support : MD5 89 Auth Type Enable : Callback : MD5 90 : User : MD5 91 : Operator : MD5 92 : Admin : MD5 93 : OEM : MD5 94 IP Address Source : Static Address 95 IP Address : x.x.x.x 96 Subnet Mask : x.x.x.x 97 MAC Address : xx:xx:xx:xx:xx:xx 98 Default Gateway IP : x.x.x.x 99 802.1q VLAN ID : Disabled 100 Cipher Suite Priv Max : Not Available 101 Bad Password Threshold : Not Available 102 103 Given that data, this function will return the following dictionary. 104 105 lan_print_dict: 106 [Set in Progress]: Set Complete 107 [Auth Type Support]: MD5 108 [Auth Type Enable]: 109 [Callback]: MD5 110 [User]: MD5 111 [Operator]: MD5 112 [Admin]: MD5 113 [OEM]: MD5 114 [IP Address Source]: Static Address 115 [IP Address]: x.x.x.x 116 [Subnet Mask]: x.x.x.x 117 [MAC Address]: xx:xx:xx:xx:xx:xx 118 [Default Gateway IP]: x.x.x.x 119 [802.1q VLAN ID]: Disabled 120 [Cipher Suite Priv Max]: Not Available 121 [Bad Password Threshold]: Not Available 122 123 """ 124 125 IPMI_INBAND_CMD = BuiltIn().get_variable_value("${IPMI_INBAND_CMD}") 126 127 # Notice in the example of data above that 'Auth Type Enable' needs some 128 # special processing. We essentially want to isolate its data and remove 129 # the 'Auth Type Enable' string so that key_value_outbuf_to_dict can 130 # process it as a sub-dictionary. 131 cmd_buf = IPMI_INBAND_CMD + " lan print | grep -E '^(Auth Type Enable)" +\ 132 "?[ ]+: ' | sed -re 's/^(Auth Type Enable)?[ ]+: //g'" 133 stdout1, stderr, rc = bsu.os_execute_command(cmd_buf) 134 135 # Now get the remainder of the data and exclude the lines with no field 136 # names (i.e. the 'Auth Type Enable' sub-fields). 137 cmd_buf = IPMI_INBAND_CMD + " lan print | grep -E -v '^[ ]+: '" 138 stdout2, stderr, rc = bsu.os_execute_command(cmd_buf) 139 140 # Make auth_type_enable_dict sub-dictionary... 141 auth_type_enable_dict = vf.key_value_outbuf_to_dict(stdout1, to_lower=0, 142 underscores=0) 143 144 # Create the lan_print_dict... 145 lan_print_dict = vf.key_value_outbuf_to_dict(stdout2, to_lower=0, 146 underscores=0) 147 # Re-assign 'Auth Type Enable' to contain the auth_type_enable_dict. 148 lan_print_dict['Auth Type Enable'] = auth_type_enable_dict 149 150 return lan_print_dict 151 152 153def get_ipmi_power_reading(): 154 155 r""" 156 Get IPMI power reading data and return it as a dictionary. 157 158 The data is obtained by issuing the IPMI "power reading" command. An 159 example is shown below: 160 161 Instantaneous power reading: 234 Watts 162 Minimum during sampling period: 234 Watts 163 Maximum during sampling period: 234 Watts 164 Average power reading over sample period: 234 Watts 165 IPMI timestamp: Thu Jan 1 00:00:00 1970 166 Sampling period: 00000000 Seconds. 167 Power reading state is: deactivated 168 169 For the data shown above, the following dictionary will be returned. 170 171 result: 172 [instantaneous_power_reading]: 238 Watts 173 [minimum_during_sampling_period]: 238 Watts 174 [maximum_during_sampling_period]: 238 Watts 175 [average_power_reading_over_sample_period]: 238 Watts 176 [ipmi_timestamp]: Thu Jan 1 00:00:00 1970 177 [sampling_period]: 00000000 Seconds. 178 [power_reading_state_is]: deactivated 179 """ 180 181 status, ret_values = \ 182 grk.run_key_u("Run IPMI Standard Command dcmi power reading") 183 result = vf.key_value_outbuf_to_dict(ret_values) 184 185 return result 186 187 188def get_mc_info(): 189 190 r""" 191 Get IPMI mc info data and return it as a dictionary. 192 193 The data is obtained by issuing the IPMI "mc info" command. An 194 example is shown below: 195 196 Device ID : 0 197 Device Revision : 0 198 Firmware Revision : 2.01 199 IPMI Version : 2.0 200 Manufacturer ID : 42817 201 Manufacturer Name : Unknown (0xA741) 202 Product ID : 16975 (0x424f) 203 Product Name : Unknown (0x424F) 204 Device Available : yes 205 Provides Device SDRs : yes 206 Additional Device Support : 207 Sensor Device 208 SEL Device 209 FRU Inventory Device 210 Chassis Device 211 Aux Firmware Rev Info : 212 0x00 213 0x00 214 0x00 215 0x00 216 217 For the data shown above, the following dictionary will be returned. 218 mc_info: 219 [device_id]: 0 220 [device_revision]: 0 221 [firmware_revision]: 2.01 222 [ipmi_version]: 2.0 223 [manufacturer_id]: 42817 224 [manufacturer_name]: Unknown (0xA741) 225 [product_id]: 16975 (0x424f) 226 [product_name]: Unknown (0x424F) 227 [device_available]: yes 228 [provides_device_sdrs]: yes 229 [additional_device_support]: 230 [additional_device_support][0]: Sensor Device 231 [additional_device_support][1]: SEL Device 232 [additional_device_support][2]: FRU Inventory Device 233 [additional_device_support][3]: Chassis Device 234 [aux_firmware_rev_info]: 235 [aux_firmware_rev_info][0]: 0x00 236 [aux_firmware_rev_info][1]: 0x00 237 [aux_firmware_rev_info][2]: 0x00 238 [aux_firmware_rev_info][3]: 0x00 239 """ 240 241 status, ret_values = \ 242 grk.run_key_u("Run IPMI Standard Command mc info") 243 result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) 244 245 return result 246