def get_dump_dict(quiet=None): r""" Get dump information and return as an ordered dictionary where the keys are the dump IDs and the values are the full path names of the dumps. Example robot program call: ${dump_dict}= Get Dump Dict Rpvars 1 dump_dict Example output: dump_dict: [1]: /var/lib/phosphor-debug-collector/dumps/1/obmcdump_1_1508255216.tar.xz [2]: /var/lib/phosphor-debug-collector/dumps/2/obmcdump_2_1508255245.tar.xz [3]: /var/lib/phosphor-debug-collector/dumps/3/obmcdump_3_1508255267.tar.xz [4]: /var/lib/phosphor-debug-collector/dumps/4/obmcdump_4_1508255283.tar.xz Description of argument(s): quiet If quiet is set to 1, this function will NOT write status messages to stdout. """ quiet = int(gp.get_var_value(quiet, 1)) cmd_buf = "dump_dir_path=" + var.DUMP_DIR_PATH + " ; " \ + "for dump_id in $(ls ${dump_dir_path} | sort -n) ; " \ + "do echo -n $dump_id: ; ls ${dump_dir_path}${dump_id}/* ; done" output, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet) return vf.key_value_outbuf_to_dict(output)
def get_os_release_info(): r""" Get release info from the OS and return as a dictionary. Example: ${release_info}= Get OS Release Info Rprint Vars release_info Output: release_info: [name]: Red Hat Enterprise Linux Server [version]: 7.6 (Maipo) [id]: rhel [id_like]: fedora [variant]: Server [variant_id]: server [version_id]: 7.6 [pretty_name]: Red Hat Enterprise Linux Server 7.6 (Maipo) [ansi_color]: 0;31 [cpe_name]: cpe:/o:redhat:enterprise_linux:7.6:GA:server [home_url]: https://www.redhat.com/ [bug_report_url]: https://bugzilla.redhat.com/ [redhat_bugzilla_product]: Red Hat Enterprise Linux 7 [redhat_bugzilla_product_version]: 7.6 [redhat_support_product]: Red Hat Enterprise Linux [redhat_support_product_version]: 7.6 """ out_buf, stderr, rc = bsu.os_execute_command('cat /etc/os-release') return vf.key_value_outbuf_to_dict(out_buf, delim="=", strip='"')
def get_health_check(verify=False): r""" Get the health_check information and return as a dictionary. Example robot code: ${health_check}= Get Health Check Rprint Vars health_check fmt=1 Example result: health_check: [hardware_status]: OK [performance]: OK Description of argument(s): verify If set, verify that all all expected field_names are generated by the health_check command. """ rc, output = openbmctool_execute_command("health_check", print_output=False, ignore_err=False) health_check = vf.key_value_outbuf_to_dict(output, delim=":") if int(verify): err_msg = gv.valid_dict(health_check, health_check_fields()) if err_msg != "": BuiltIn().fail(gp.sprint_error(err_msg)) return health_check
def get_dump_dict(quiet=None): r""" Get dump information and return as an ordered dictionary where the keys are the dump IDs and the values are the full path names of the dumps. Example robot program call: ${dump_dict}= Get Dump Dict Rprint Vars dump_dict Example output: dump_dict: [1]: /var/lib/phosphor-debug-collector/dumps/1/obmcdump_1_1508255216.tar.xz [2]: /var/lib/phosphor-debug-collector/dumps/2/obmcdump_2_1508255245.tar.xz [3]: /var/lib/phosphor-debug-collector/dumps/3/obmcdump_3_1508255267.tar.xz [4]: /var/lib/phosphor-debug-collector/dumps/4/obmcdump_4_1508255283.tar.xz Description of argument(s): quiet If quiet is set to 1, this function will NOT write status messages to stdout. """ quiet = int(gp.get_var_value(quiet, 1)) cmd_buf = "dump_dir_path=" + var.DUMP_DIR_PATH + " ; " \ + "for dump_id in $(ls ${dump_dir_path} | sort -n) ; do " \ + "file_path=$(ls ${dump_dir_path}${dump_id}/* 2>/dev/null)" \ + " || continue ; echo ${dump_id}:${file_path} ; done" output, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet) return vf.key_value_outbuf_to_dict(output)
def get_mc_info(): r""" Get IPMI mc info data and return it as a dictionary. The data is obtained by issuing the IPMI "mc info" command. An example is shown below: Device ID : 0 Device Revision : 0 Firmware Revision : 2.01 IPMI Version : 2.0 Manufacturer ID : 42817 Manufacturer Name : Unknown (0xA741) Product ID : 16975 (0x424f) Product Name : Unknown (0x424F) Device Available : yes Provides Device SDRs : yes Additional Device Support : Sensor Device SEL Device FRU Inventory Device Chassis Device Aux Firmware Rev Info : 0x00 0x00 0x00 0x00 For the data shown above, the following dictionary will be returned. mc_info: [device_id]: 0 [device_revision]: 0 [firmware_revision]: 2.01 [ipmi_version]: 2.0 [manufacturer_id]: 42817 [manufacturer_name]: Unknown (0xA741) [product_id]: 16975 (0x424f) [product_name]: Unknown (0x424F) [device_available]: yes [provides_device_sdrs]: yes [additional_device_support]: [additional_device_support][0]: Sensor Device [additional_device_support][1]: SEL Device [additional_device_support][2]: FRU Inventory Device [additional_device_support][3]: Chassis Device [aux_firmware_rev_info]: [aux_firmware_rev_info][0]: 0x00 [aux_firmware_rev_info][1]: 0x00 [aux_firmware_rev_info][2]: 0x00 [aux_firmware_rev_info][3]: 0x00 """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command mc info") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def get_fru_info(): r""" Get fru info and return it as a list of dictionaries. The data is obtained by issuing the IPMI "fru print -N 50" command. An example is shown below: FRU Device Description : Builtin FRU Device (ID 0) Device not present (Unspecified error) FRU Device Description : cpu0 (ID 1) Board Mfg Date : Sun Dec 31 18:00:00 1995 Board Mfg : <Manufacturer Name> Board Product : PROCESSOR MODULE Board Serial : YA1934315964 Board Part Number : 02CY209 FRU Device Description : cpu1 (ID 2) Board Mfg Date : Sun Dec 31 18:00:00 1995 Board Mfg : <Manufacturer Name> Board Product : PROCESSOR MODULE Board Serial : YA1934315965 Board Part Number : 02CY209 For the data shown above, the following list of dictionaries will be returned. fru_obj: fru_obj[0]: [fru_device_description]: Builtin FRU Device (ID 0) [state]: Device not present (Unspecified error) fru_obj[1]: [fru_device_description]: cpu0 (ID 1) [board_mfg_date]: Sun Dec 31 18:00:00 1995 [board_mfg]: <Manufacturer Name> [board_product]: PROCESSOR MODULE [board_serial]: YA1934315964 [board_part_number]: 02CY209 fru_obj[2]: [fru_device_description]: cpu1 (ID 2) [board_mfg_date]: Sun Dec 31 18:00:00 1995 [board_mfg]: <Manufacturer Name> [board_product]: PROCESSOR MODULE [board_serial]: YA1934315965 [board_part_number]: 02CY209 """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command fru print -N 50") # Manipulate the "Device not present" line to create a "state" key. ret_values = re.sub("Device not present", "state : Device not present", ret_values) return [ vf.key_value_outbuf_to_dict(x) for x in re.split("\n\n", ret_values) ]
def get_chassis_status(): r""" Get IPMI chassis status data and return it as a dictionary. The data is obtained by issuing the IPMI "chassis status" command. An example is shown below: System Power : off Power Overload : false Power Interlock : inactive Main Power Fault : false Power Control Fault : false Power Restore Policy : previous Last Power Event : Chassis Intrusion : inactive Front-Panel Lockout : inactive Drive Fault : false Cooling/Fan Fault : false Sleep Button Disable : not allowed Diag Button Disable : not allowed Reset Button Disable : not allowed Power Button Disable : allowed Sleep Button Disabled : false Diag Button Disabled : false Reset Button Disabled : false Power Button Disabled : false For the data shown above, the following dictionary will be returned. chassis_status: [system_power]: off [power_overload]: false [power_interlock]: inactive [main_power_fault]: false [power_control_fault]: false [power_restore_policy]: previous [last_power_event]: [chassis_intrusion]: inactive [front-panel_lockout]: inactive [drive_fault]: false [cooling/fan_fault]: false [sleep_button_disable]: not allowed [diag_button_disable]: not allowed [reset_button_disable]: not allowed [power_button_disable]: allowed [sleep_button_disabled]: false [diag_button_disabled]: false [reset_button_disabled]: false [power_button_disabled]: false """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command chassis status") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def get_os_release_info(): r""" Get os-release info and return it as a dictionary. An example of the contents of /etc/os-release: NAME="Red Hat Enterprise Linux Server" VERSION="7.5 (Maipo)" ID="rhel" ID_LIKE="fedora" VARIANT="Server" VARIANT_ID="server" VERSION_ID="7.5" PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 Beta (Maipo)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:beta:server" HOME_URL="https://www.redhat.com/" BUG_REPORT_URL="https://bugzilla.redhat.com/" REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7" REDHAT_BUGZILLA_PRODUCT_VERSION=7.5 REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux" REDHAT_SUPPORT_PRODUCT_VERSION="7.5 Beta" For the data shown above, this function will return the following dictionary: result: [name]: Red Hat Enterprise Linux Server [version]: 7.5 (Maipo) [id]: rhel [id_like]: fedora [variant]: Server [variant_id]: server [version_id]: 7.5 [pretty_name]: Red Hat Enterprise Linux Server 7.5 Beta (Maipo) [ansi_color]: 0;31 [cpe_name]: cpe:/o:redhat:enterprise_linux:7.5:beta:server [home_url]: https://www.redhat.com/ [bug_report_url]: https://bugzilla.redhat.com/ [redhat_bugzilla_product]: Red Hat Enterprise Linux 7 [redhat_bugzilla_product_version]: 7.5 [redhat_support_product]: Red Hat Enterprise Linux [redhat_support_product_version]: 7.5 Beta """ stdout, stderr, rc =\ bmc_ssh_utils.os_execute_command("cat /etc/os-release") return var_funcs.key_value_outbuf_to_dict(stdout, delim="=", strip='"')
def get_user_info(userid, channel_number=1): r""" Get user info using channel command and return it as a dictionary. Description of argument(s): userid The userid (e.g. "1", "2", etc.). channel_number The user's channel number (e.g. "1"). Note: If userid is blank, this function will return a list of dictionaries. Each list entry represents one userid record. The data is obtained by issuing the IPMI "channel getaccess" command. An example is shown below for user id 1 and channel number 1. Maximum User IDs : 15 Enabled User IDs : 1 User ID : 1 User Name : root Fixed Name : No Access Available : callback Link Authentication : enabled IPMI Messaging : enabled Privilege Level : ADMINISTRATOR Enable Status : enabled For the data shown above, the following dictionary will be returned. user_info: [maximum_userids]: 15 [enabled_userids: 1 [userid] 1 [user_name] root [fixed_name] No [access_available] callback [link_authentication] enabled [ipmi_messaging] enabled [privilege_level] ADMINISTRATOR [enable_status] enabled """ status, ret_values = grk.run_key_u( "Run IPMI Standard Command channel getaccess " + str(channel_number) + " " + str(userid)) if userid == "": return vf.key_value_outbuf_to_dicts(ret_values, process_indent=1) else: return vf.key_value_outbuf_to_dict(ret_values, process_indent=1)
def get_bmc_date_time(): r""" Get date/time info from BMC and return as a dictionary. Example of dictionary data returned by this keyword. time_dict: [local_time]: Fri 2017-11-03 152756 UTC [local_time_seconds]: 1509740876 [universal_time]: Fri 2017-11-03 152756 UTC [universal_time_seconds]: 1509740876 [rtc_time]: Fri 2016-05-20 163403 [rtc_time_seconds]: 1463780043 [time_zone]: n/a (UTC, +0000) [network_time_on]: yes [ntp_synchronized]: no [rtc_in_local_tz]: no """ out_buf, stderr, rc = bsu.bmc_execute_command('timedatectl') # Example of output returned by call to timedatectl: # Local time: Fri 2017-11-03 15:27:56 UTC # Universal time: Fri 2017-11-03 15:27:56 UTC # RTC time: Fri 2016-05-20 16:34:03 # Time zone: n/a (UTC, +0000) # Network time on: yes # NTP synchronized: no # RTC in local TZ: no # Convert the out_buf to a dictionary. initial_time_dict = vf.key_value_outbuf_to_dict(out_buf) # For each "_time" entry in the dictionary, we will create a corresponding # "_time_seconds" entry. We create a new dictionary so that the entries # are kept in a nice order for printing. try: result_time_dict = collections.OrderedDict() except AttributeError: result_time_dict = DotDict() for key, value in initial_time_dict.items(): result_time_dict[key] = value if not key.endswith("_time"): continue result_time_dict[key + '_seconds'] = \ int(DateTime.convert_date(value, result_format='epoch')) return result_time_dict
def get_bmc_date_time(): r""" Get date/time info from BMC and return as a dictionary. Example of dictionary data returned by this keyword. time_dict: [local_time]: Fri 2017-11-03 152756 UTC [local_time_seconds]: 1509740876 [universal_time]: Fri 2017-11-03 152756 UTC [universal_time_seconds]: 1509740876 [rtc_time]: Fri 2016-05-20 163403 [rtc_time_seconds]: 1463780043 [time_zone]: n/a (UTC, +0000) [network_time_on]: yes [ntp_synchronized]: no [rtc_in_local_tz]: no """ out_buf, stderr, rc = bsu.bmc_execute_command('timedatectl') # Example of output returned by call to timedatectl: # Local time: Fri 2017-11-03 15:27:56 UTC # Universal time: Fri 2017-11-03 15:27:56 UTC # RTC time: Fri 2016-05-20 16:34:03 # Time zone: n/a (UTC, +0000) # Network time on: yes # NTP synchronized: no # RTC in local TZ: no # Convert the out_buf to a dictionary. initial_time_dict = vf.key_value_outbuf_to_dict(out_buf) # For each "_time" entry in the dictionary, we will create a corresponding # "_time_seconds" entry. We create a new dictionary so that the entries # are kept in a nice order for printing. try: result_time_dict = collections.OrderedDict() except AttributeError: result_time_dict = DotDict() for key, value in initial_time_dict.items(): result_time_dict[key] = value if not key.endswith("_time"): continue result_time_dict[key + '_seconds'] = \ int(DateTime.convert_date(value, result_format='epoch')) return result_time_dict
def get_secure_boot_info(self, quiet=None): r""" Get secure-boot information and return it as a tuple consisting of num_procs, secure_boot, jumper. num_procs is the number of processors containing the information. secure_boot will be set to True if each and every register value in question has its secureboot bit set (Bit 4). jumper will be set to True if each and every register value in question has its jumper bit set (Bit 5). Description of argument(s): quiet See shell_cmd for details. """ cmd_buf = "pdbg -d p9w -a getcfam 0x2801" out_buf, stderr, rc = bsu.bmc_execute_command(cmd_buf, quiet=quiet) # Convert result to a dictionary with one key for each processor: # result: # [p0:0x2801]: 0x80c00002 # [p1:0x2801]: 0x90c00002 result = vf.key_value_outbuf_to_dict(out_buf, delim="=") num_procs = len(result) # Initialize values to True. secure_boot = True jumper = True for key, value in result.items(): # Convert hex string to int. reg_value = int(value, 16) if not reg_value & secure_boot_mask(): secure_boot = False if not reg_value & jumper_mask(): jumper = False return num_procs, secure_boot, jumper
def get_sdr_info(): r""" Get IPMI sdr info data and return it as a dictionary. The data is obtained by issuing the IPMI "sdr info" command. An example is shown below: SDR Version : 0x51 Record Count : 216 Free Space : unspecified Most recent Addition : Most recent Erase : SDR overflow : no SDR Repository Update Support : unspecified Delete SDR supported : no Partial Add SDR supported : no Reserve SDR repository supported : no SDR Repository Alloc info supported : no For the data shown above, the following dictionary will be returned. mc_info: [sdr_version]: 0x51 [record_Count]: 216 [free_space]: unspecified [most_recent_addition]: [most_recent_erase]: [sdr_overflow]: no [sdr_repository_update_support]: unspecified [delete_sdr_supported]: no [partial_add_sdr_supported]: no [reserve_sdr_repository_supported]: no [sdr_repository_alloc_info_supported]: no """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command sdr info") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def get_health_check(verify=False): r""" Get the health_check information and return as a dictionary. Example robot code: ${health_check}= Get Health Check Rpvars 1 health_check Example result: health_check: [hardware_status]: OK [performance]: OK Description of argument(s): verify If set, verify that all all expected field_names are generated by the health_check command. """ rc, output = openbmctool_execute_command("health_check", print_output=False, ignore_err=False) health_check = vf.key_value_outbuf_to_dict(output, delim=":") if int(verify): # Create a list of files by stripping the dir names from the elements # of collect_service_data_file_paths. fields_obtained = health_check.keys() fields_expected = health_check_fields() fields_missing = list(set(fields_expected) - set(fields_obtained)) if len(fields_missing) > 0: err_msg = "The following fields are missing from the output of" err_msg += " health_check:\n" err_msg += gp.sprint_var(fields_missing) err_msg += gp.sprint_var(health_check) BuiltIn().fail(gp.sprint_error(err_msg)) return health_check
def get_ipmi_power_reading(strip_watts=1): r""" Get IPMI power reading data and return it as a dictionary. The data is obtained by issuing the IPMI "power reading" command. An example is shown below: Instantaneous power reading: 234 Watts Minimum during sampling period: 234 Watts Maximum during sampling period: 234 Watts Average power reading over sample period: 234 Watts IPMI timestamp: Thu Jan 1 00:00:00 1970 Sampling period: 00000000 Seconds. Power reading state is: deactivated For the data shown above, the following dictionary will be returned. result: [instantaneous_power_reading]: 238 Watts [minimum_during_sampling_period]: 238 Watts [maximum_during_sampling_period]: 238 Watts [average_power_reading_over_sample_period]: 238 Watts [ipmi_timestamp]: Thu Jan 1 00:00:00 1970 [sampling_period]: 00000000 Seconds. [power_reading_state_is]: deactivated Description of argument(s): strip_watts Strip all dictionary values of the trailing " Watts" substring. """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command dcmi power reading") result = vf.key_value_outbuf_to_dict(ret_values) if strip_watts: result.update((k, re.sub(' Watts$', '', v)) for k, v in result.items()) return result
def get_bmc_release_info(): r""" Get release info from the BMC and return as a dictionary. Example: ${release_info}= Get BMC Release Info Rprint Vars release_info Output: release_info: [id]: openbmc-phosphor [name]: Phosphor OpenBMC (Phosphor OpenBMC Project Reference... [version]: 2.8.0-dev [version_id]: 2.8.0-dev-1083-g8954c3505 [pretty_name]: Phosphor OpenBMC (Phosphor OpenBMC Project Reference... [build_id]: 2.8.0-dev [openbmc_target_machine]: witherspoon """ out_buf, stderr, rc = bsu.bmc_execute_command('cat /etc/os-release') return vf.key_value_outbuf_to_dict(out_buf, delim="=", strip='"')
def get_channel_auth_capabilities(channel_number=1): r""" Get the channel authentication capabilities and return as a dictionary. Example: channel_auth_cap: [channel_number]: 2 [ipmi_v1.5__auth_types]: [kg_status]: default (all zeroes) [per_message_authentication]: enabled [user_level_authentication]: enabled [non-null_user_names_exist]: yes [null_user_names_exist]: no [anonymous_login_enabled]: no [channel_supports_ipmi_v1.5]: no [channel_supports_ipmi_v2.0]: yes """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command channel authcap " + str(channel_number) + " 4") result = vf.key_value_outbuf_to_dict(ret_values, process_indent=1) return result
def pldmtool(option_string, parse_results=1, **bsu_options): r""" Run pldmtool on the BMC with the caller's option string and return the result. Example: ${pldm_results}= Pldmtool base GetPLDMTypes Rprint Vars pldm_results pldm_results: [request_message]: 08 01 80 00 04 [success_in_creating_the_socket]: RC = 3 [success_in_connecting_to_socket]: RC = 0 [success_in_sending_message_type_as_pldm_to_mctp]:RC = 0 [write_to_socket_successful]: RC = 5 [total_length]: 14 [loopback_response_message]: 08 01 80 00 04 [on_first_recv(),response_==_request]: RC = 0 [shutdown_socket_successful]: RC = 0 [response_message]: 08 01 00 00 04 00 0d 00 00 00 00 00 00 00 [supported_types]: [raw]: [0]: 0 [1]: 2 [2]: 3 [text]: [0]: base [1]: platform [2]: bios Description of argument(s): option_string A string of options which are to be processed by the pldmtool command. parse_results Parse the pldmtool results and return a dictionary rather than the raw pldmtool output. bsu_options Options to be passed directly to bmc_execute_command. See its prolog for details. """ # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}). bsu_options = fa.args_to_objects(bsu_options) stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options) if parse_results: # Remove linefeeds following colons. stdout = re.sub(":\n", ":", stdout) # Remove first line (e.g. "Encode request successfully"). stdout = re.sub("^.*\\n", "", stdout) result = vf.key_value_outbuf_to_dict(stdout) if 'supported_types' in result: # 'supported types' begins like this: # 0(base) 2(platform) 3(bios) # Parsing it to look like it does in the example above. supported_types = {'raw': [], 'text': []} for entry in result['supported_types'].split(" "): record = entry.split("(") supported_types['raw'].append(record[0]) supported_types['text'].append(record[1].rstrip(")")) result['supported_types'] = supported_types if 'date_&_time' in result: return result['yyyy-mm-dd_hh'].split(' - ')[1] return result return stdout
def get_hard_disk_info(device="/dev/sdb"): r""" Get firmware information for the given device on the OS and return it as a dictionary. Description of argument(s): device The device to be passed to the hdparm and lsblk commands (e.g. "/dev/sdb"). Example result: sda_info: [model_number]: MTFDDAK1T9TCB 00LY461 00LY570IBM [serial_number]: 179C413F [firmware_revision]: MJ06 [transport]: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0 [used]: unknown (minor revision code 0x006d) [supported]: enhanced erase [likely_used]: 10 [lba_user_addressable_sectors]: 268435455 [lba48_user_addressable_sectors]: 3750748848 [logical_sector_size]: 512 bytes [physical_sector_size]: 4096 bytes [logical_sector-0_offset]: 0 bytes [device_size_with_m_=_1024*1024]: 1831420 MBytes [device_size_with_m_=_1000*1000]: 1920383 MBytes (1920 GB) [form_factor]: 2.5 inch [nominal_media_rotation_rate]: Solid State Device [queue_depth]: 32 [standby_timer_values]: spec'd by Standard, with device specific minimum [r/w_multiple_sector_transfer]: Max = 16 Current = 16 [advanced_power_management_level]: 254 [dma]: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 [cycle_time]: no flow control=120ns IORDY flow control=120ns [pio]: pio0 pio1 pio2 pio3 pio4 [security]: [not_expired]: security count [logical_unit_wwn_device_identifier]: 500a0751179c413f [naa]: 5 [ieee_oui]: 00a075 [unique_id]: 1179c413f [checksum]: correct [name]: sda1 [maj:min]: 8:1 [rm]: 1 [size]: 4M [ro]: 0 [type]: part [mountpoint]: """ cmd_buf = "hdparm -I " + device + " | egrep \":.+\" | sed -re" +\ " \"s/[ \t]+/ /g\"" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) firmware_dict = vf.key_value_outbuf_to_dict(stdout) cmd_buf = "lsblk -P " + device + " | sed -re 's/\" /\"\\n/g'" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) firmware_dict.update(vf.key_value_outbuf_to_dict(stdout, delim='=', strip=" \"")) return firmware_dict
def get_os_ethtool(interface_name): r""" Get OS 'ethtool' output for the given interface_name and return it as a dictionary. Settings for enP52p1s0f0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: Unknown! Duplex: Unknown! (255) Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: Unknown Supports Wake-on: g Wake-on: g Current message level: 0x000000ff (255) drv probe link timer ifdown ifup rx_err tx_err Link detected: no Given that data, this function will return the following dictionary. ethtool_dict: [supported_ports]: [ TP ] [supported_link_modes]: [supported_link_modes][0]: 10baseT/Half 10baseT/Full [supported_link_modes][1]: 100baseT/Half 100baseT/Full [supported_link_modes][2]: 1000baseT/Half 1000baseT/Full [supported_pause_frame_use]: No [supports_auto-negotiation]: Yes [supported_fec_modes]: Not reported [advertised_link_modes]: [advertised_link_modes][0]: 10baseT/Half 10baseT/Full [advertised_link_modes][1]: 100baseT/Half 100baseT/Full [advertised_link_modes][2]: 1000baseT/Half 1000baseT/Full [advertised_pause_frame_use]: Symmetric [advertised_auto-negotiation]: Yes [advertised_fec_modes]: Not reported [speed]: Unknown! [duplex]: Unknown! (255) [port]: Twisted Pair [phyad]: 1 [transceiver]: internal [auto-negotiation]: on [mdi-x]: Unknown [supports_wake-on]: g [wake-on]: g [current_message_level]: 0x000000ff (255) [drv_probe_link_timer_ifdown_ifup_rx_err_tx_err]:<blank> [link_detected]: no """ # Using sed and tail to massage the data a bit before running # key_value_outbuf_to_dict. cmd_buf = "ethtool " + interface_name +\ " | sed -re 's/(.* link modes:)(.*)/\\1\\n\\2/g' | tail -n +2" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) result = vf.key_value_outbuf_to_dict(stdout, process_indent=1, strip=" \t") return result
def get_os_ethtool(interface_name): r""" Get OS 'ethtool' output for the given interface_name and return it as a dictionary. Settings for enP52p1s0f0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: Unknown! Duplex: Unknown! (255) Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: Unknown Supports Wake-on: g Wake-on: g Current message level: 0x000000ff (255) drv probe link timer ifdown ifup rx_err tx_err Link detected: no Given that data, this function will return the following dictionary. ethtool_dict: [supported_ports]: [ TP ] [supported_link_modes]: [supported_link_modes][0]: 10baseT/Half 10baseT/Full [supported_link_modes][1]: 100baseT/Half 100baseT/Full [supported_link_modes][2]: 1000baseT/Half 1000baseT/Full [supported_pause_frame_use]: No [supports_auto-negotiation]: Yes [supported_fec_modes]: Not reported [advertised_link_modes]: [advertised_link_modes][0]: 10baseT/Half 10baseT/Full [advertised_link_modes][1]: 100baseT/Half 100baseT/Full [advertised_link_modes][2]: 1000baseT/Half 1000baseT/Full [advertised_pause_frame_use]: Symmetric [advertised_auto-negotiation]: Yes [advertised_fec_modes]: Not reported [speed]: Unknown! [duplex]: Unknown! (255) [port]: Twisted Pair [phyad]: 1 [transceiver]: internal [auto-negotiation]: on [mdi-x]: Unknown [supports_wake-on]: g [wake-on]: g [current_message_level]: 0x000000ff (255) [drv_probe_link_timer_ifdown_ifup_rx_err_tx_err]:<blank> [link_detected]: no """ # Using sed and tail to massage the data a bit before running # key_value_outbuf_to_dict. cmd_buf = "ethtool " + interface_name +\ " | sed -re 's/(.* link modes:)(.*)/\\1\\n\\2/g' | tail -n +2" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) result = vf.key_value_outbuf_to_dict(stdout, process_indent=1, strip=" \t") return result
def get_lan_print_dict(ipmi_cmd_type='external'): r""" Get IPMI 'lan print' output and return it as a dictionary. Here is an example of the IPMI lan print output: Set in Progress : Set Complete Auth Type Support : MD5 Auth Type Enable : Callback : MD5 : User : MD5 : Operator : MD5 : Admin : MD5 : OEM : MD5 IP Address Source : Static Address IP Address : x.x.x.x Subnet Mask : x.x.x.x MAC Address : xx:xx:xx:xx:xx:xx Default Gateway IP : x.x.x.x 802.1q VLAN ID : Disabled Cipher Suite Priv Max : Not Available Bad Password Threshold : Not Available Given that data, this function will return the following dictionary. lan_print_dict: [Set in Progress]: Set Complete [Auth Type Support]: MD5 [Auth Type Enable]: [Callback]: MD5 [User]: MD5 [Operator]: MD5 [Admin]: MD5 [OEM]: MD5 [IP Address Source]: Static Address [IP Address]: x.x.x.x [Subnet Mask]: x.x.x.x [MAC Address]: xx:xx:xx:xx:xx:xx [Default Gateway IP]: x.x.x.x [802.1q VLAN ID]: Disabled [Cipher Suite Priv Max]: Not Available [Bad Password Threshold]: Not Available Description of argument(s): ipmi_cmd_type The type of ipmi command to use (e.g. 'inband', 'external'). """ # Notice in the example of data above that 'Auth Type Enable' needs some # special processing. We essentially want to isolate its data and remove # the 'Auth Type Enable' string so that key_value_outbuf_to_dict can # process it as a sub-dictionary. cmd_buf = "lan print | grep -E '^(Auth Type Enable)" +\ "?[ ]+: ' | sed -re 's/^(Auth Type Enable)?[ ]+: //g'" stdout1, stderr, rc = execute_ipmi_cmd(cmd_buf, ipmi_cmd_type, print_output=0) # Now get the remainder of the data and exclude the lines with no field # names (i.e. the 'Auth Type Enable' sub-fields). cmd_buf = "lan print | grep -E -v '^[ ]+: '" stdout2, stderr, rc = execute_ipmi_cmd(cmd_buf, ipmi_cmd_type, print_output=0) # Make auth_type_enable_dict sub-dictionary... auth_type_enable_dict = vf.key_value_outbuf_to_dict(stdout1, to_lower=0, underscores=0) # Create the lan_print_dict... lan_print_dict = vf.key_value_outbuf_to_dict(stdout2, to_lower=0, underscores=0) # Re-assign 'Auth Type Enable' to contain the auth_type_enable_dict. lan_print_dict['Auth Type Enable'] = auth_type_enable_dict return lan_print_dict
def pldmtool(option_string, parse_results=1, **bsu_options): r""" Run pldmtool on the BMC with the caller's option string and return the result. Example: ${pldm_results}= Pldmtool base GetPLDMTypes Rprint Vars pldm_results pldm_results: [supported_types]: [raw]: [0]: 0 [1]: 2 [2]: 3 [text]: [0]: base [1]: platform [2]: bios Description of argument(s): option_string A string of options which are to be processed by the pldmtool command. parse_results Parse the pldmtool results and return a dictionary rather than the raw pldmtool output. bsu_options Options to be passed directly to bmc_execute_command. See its prolog for details. """ # This allows callers to specify arguments in python style (e.g. print_out=1 vs. print_out=${1}). bsu_options = fa.args_to_objects(bsu_options) stdout, stderr, rc = bsu.bmc_execute_command('pldmtool ' + option_string, **bsu_options) if parse_results: result = vf.key_value_outbuf_to_dict(stdout) if 'supported_types' in result: # 'supported types' begins like this: # 0(base) 2(platform) 3(bios) # Parsing it to look like it does in the example above. supported_types = {'raw': [], 'text': []} for entry in result['supported_types'].split(" "): record = entry.split("(") supported_types['raw'].append(record[0]) supported_types['text'].append(record[1].rstrip(")")) result['supported_types'] = supported_types elif 'supported_commands' in result: commands = result['supported_commands'].split(":")[0].split(" ") return commands elif 'yyyy-mm-dd_hh' in result: # Date & Time : # YYYY-MM-DD HH:MM:SS - 2020-02-24 06:44:16 return result['yyyy-mm-dd_hh'].split(' - ')[1] # Simplfying dict output for GetPDR with type PDREntityAssociation. # Example : # pldmtool platform GetPDR -d 10 # Entity Association # nextRecordHandle: 0 # responseCount: 56 # recordHandle: 10 # PDRHeaderVersion: 1 # PDRType: 15 # recordChangeNumber: 0 # dataLength: 46 # containerID: 1 # associationType: Physical # containerEntityType: System Board # containerEntityInstanceNumber: 1 # containerEntityContainerID: 0 # containedEntityCount: 6 # containedEntityType[1]: Chassis front panel board (control panel) # containedEntityInstanceNumber[1]: 1 # containedEntityContainerID[1]: 1 # containedEntityType[2]: Chassis front panel board (control panel) # containedEntityInstanceNumber[2]: 2 # containedEntityContainerID[2]: 1 elif 'containerentitycontainerid' in result: dict_data1, dict_data2 = vf.split_dict_on_key( 'containerentitycontainerid', result) return dict_data1 elif 'entitytype' in result: # Example : # entityType: 24576(OEM) # Note: OEM type number is dynamic if 'OEM' in result['entitytype']: result['entitytype'] = 'OEM' # Collect bios strings from bios string table in to list. # Example output for pldmtool GetBIOSTable --type stringTable # PLDM StringTable: # BIOSStringHandle : BIOSString # 0 : Allowed # 1 : Disabled # 2 : Enabled elif 'pldm_stringtable' in result: result.pop('pldm_stringtable') result.pop('biosstringhandle') bios_string_list = [] for data in result: bios_string_list.append(result[data]) # Example for bios_string_list: # bios_string_list = ['Allowed', 'Disabled', 'Enabled'] return bios_string_list # Check if parameter pldm_attributetable/pldm_attributevaluetable present for # pldmtool GetBIOSTable --type AttributeTable/AttributeValueTable. # Note: Output for AttributeTable/AttributeValueTable is huge and verification of # table content is not available. elif 'pldm_attributetable' in result: result['pldm_attributetable'] = True return result elif 'pldm_attributevaluetable' in result: result['pldm_attributevaluetable'] = True return result return result return stdout
def get_hard_disk_info(device="/dev/sdb"): r""" Get firmware information for the given device on the OS and return it as a dictionary. Description of argument(s): device The device to be passed to the hdparm and lsblk commands (e.g. "/dev/sdb"). Example result: sda_info: [model_number]: MTFDDAK1T9TCB 00LY461 00LY570XXX [serial_number]: 179C413F [firmware_revision]: MJ06 [transport]: Serial, ATA8-AST, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0 [used]: unknown (minor revision code 0x006d) [supported]: enhanced erase [likely_used]: 10 [lba_user_addressable_sectors]: 268435455 [lba48_user_addressable_sectors]: 3750748848 [logical_sector_size]: 512 bytes [physical_sector_size]: 4096 bytes [logical_sector-0_offset]: 0 bytes [device_size_with_m_=_1024*1024]: 1831420 MBytes [device_size_with_m_=_1000*1000]: 1920383 MBytes (1920 GB) [form_factor]: 2.5 inch [nominal_media_rotation_rate]: Solid State Device [queue_depth]: 32 [standby_timer_values]: spec'd by Standard, with device specific minimum [r/w_multiple_sector_transfer]: Max = 16 Current = 16 [advanced_power_management_level]: 254 [dma]: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6 [cycle_time]: no flow control=120ns IORDY flow control=120ns [pio]: pio0 pio1 pio2 pio3 pio4 [security]: [not_expired]: security count [logical_unit_wwn_device_identifier]: 500a0751179c413f [naa]: 5 [ieee_oui]: 00a075 [unique_id]: 1179c413f [checksum]: correct [name]: sda1 [maj:min]: 8:1 [rm]: 1 [size]: 4M [ro]: 0 [type]: part [mountpoint]: """ cmd_buf = "hdparm -I " + device + " | egrep \":.+\" | sed -re" +\ " \"s/[ \t]+/ /g\"" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) firmware_dict = vf.key_value_outbuf_to_dict(stdout) cmd_buf = "lsblk -P " + device + " | sed -re 's/\" /\"\\n/g'" stdout, stderr, rc = bsu.os_execute_command(cmd_buf) firmware_dict.update( vf.key_value_outbuf_to_dict(stdout, delim='=', strip=" \"")) return firmware_dict