def create_ipmi_ext_command_string(command, **options): r""" Create and return an IPMI external command string which is fit to be run from a bash command line. Example: ipmi_ext_cmd = create_ipmi_ext_command_string('power status') Result: ipmitool -I lanplus -C 3 -p 623 -P ******** -H x.x.x.x power status Example: ipmi_ext_cmd = create_ipmi_ext_command_string('power status', C='4') Result: ipmitool -I lanplus -C 4 -p 623 -P ******** -H x.x.x.x power status Description of argument(s): command The ipmitool command (e.g. 'power status'). options Any desired options that are understood by ipmitool (see iptmitool's help text for a complete list). If the caller does NOT provide any of several required options (e.g. "P", i.e. password), this function will include them on the caller's behalf using default values. """ new_options = collections.OrderedDict() for option in ipmi_required_options: # This is to prevent boot table "-N 10" vs user input timeout. if " -N " in command and option == "N": continue if option in options: # If the caller has specified this particular option, use it in # preference to the default value. new_options[option] = options[option] # Delete the value from the caller's options. del options[option] else: # The caller hasn't specified this required option so specify it # for them using the global value. var_name = 'ipmi_' + ipmi_option_name_map[option] value = eval(var_name) new_options[option] = value # Include the remainder of the caller's options in the new options # dictionary. for key, value in options.items(): new_options[key] = value return gc.create_command_string('ipmitool', command, new_options)
def nping(host=openbmc_host, parse_results=1, **options): r""" Run the nping command and return the results either as a string or as a dictionary. Do a 'man nping' for a complete description of the nping utility. Note that any valid nping argument may be specified as a function argument. Example robot code: ${nping_result}= Nping delay=${delay} count=${count} icmp=${None} icmp-type=echo Rprint Vars nping_result Resulting output: nping_result: [max_rtt]: 0.534ms [min_rtt]: 0.441ms [avg_rtt]: 0.487ms [raw_packets_sent]: 4 (112B) [rcvd]: 2 (92B) [lost]: 2 (50.00%) [percent_lost]: 50.0 Description of argument(s): host The host name or IP of the target of the nping command. parse_results 1 or True indicates that this function should parse the nping results and return a dictionary rather than the raw nping output. See the parse_nping_output() function for details on the dictionary structure. options Zero or more options accepted by the nping command. Do a 'man nping' for details. """ command_string = gc.create_command_string('nping', host, options) rc, output = gc.shell_cmd(command_string, print_output=0, ignore_err=0) if parse_results: return parse_nping_output(output) return output
def network(sub_command, **options): r""" Run an openbmctool.py network command and return the results as a dictionary. Note that any valid network argument may be specified as a function argument. Example robot code: ${ip_records}= Network getIP I=eth0 Rprint Vars ip_records Resulting output: ip_records: [/xyz/openbmc_project/network/eth0/ipv4/23d41d48]: [Address]: n.n.n.n [Gateway]: [Origin]: xyz.openbmc_project.Network.IP.AddressOrigin.Static [PrefixLength]: 24 [Type]: xyz.openbmc_project.Network.IP.Protocol.IPv4 [/xyz/openbmc_project/network/eth0/ipv4/24ba5feb]: [Address]: n.n.n.n (etc.) Description of argument(s): sub_command The sub-command accepted by the network command (e.g. "view-config", "getIP", etc.). options Zero or more options accepted by the network command. """ if gm.python_version < gm.ordered_dict_version: new_options = collections.OrderedDict(options) else: new_options = options command_string = gc.create_command_string('network ' + sub_command, new_options) return openbmctool_execute_command_json(command_string, print_output=False, ignore_err=False)