1#!/usr/bin/env python
2
3r"""
4Provide useful ipmi functions.
5"""
6
7import gen_misc as gm
8import gen_robot_keyword as grk
9import gen_robot_utils as gru
10import tempfile
11gru.my_import_resource("ipmi_client.robot")
12
13
14def get_sol_info():
15
16    r"""
17    Get all SOL info and return it as a dictionary.
18
19    Example use:
20
21    Robot code:
22    ${sol_info}=  get_sol_info
23    Rpvars  sol_info
24
25    Output:
26    sol_info:
27      sol_info[Info]:                                SOL parameter 'Payload Channel (7)' not supported - defaulting to 0x0e
28      sol_info[Character Send Threshold]:            1
29      sol_info[Force Authentication]:                true
30      sol_info[Privilege Level]:                     USER
31      sol_info[Set in progress]:                     set-complete
32      sol_info[Retry Interval (ms)]:                 100
33      sol_info[Non-Volatile Bit Rate (kbps)]:        IPMI-Over-Serial-Setting
34      sol_info[Character Accumulate Level (ms)]:     100
35      sol_info[Enabled]:                             true
36      sol_info[Volatile Bit Rate (kbps)]:            IPMI-Over-Serial-Setting
37      sol_info[Payload Channel]:                     14 (0x0e)
38      sol_info[Payload Port]:                        623
39      sol_info[Force Encryption]:                    true
40      sol_info[Retry Count]:                         7
41    """
42
43    status, ret_values = grk.run_key_u("Run IPMI Standard Command  sol info")
44
45    # Create temp file path.
46    temp = tempfile.NamedTemporaryFile()
47    temp_file_path = temp.name
48
49    # Write sol info to temp file path.
50    text_file = open(temp_file_path, "w")
51    text_file.write(ret_values)
52    text_file.close()
53
54    # Use my_parm_file to interpret data.
55    sol_info = gm.my_parm_file(temp_file_path)
56
57    return sol_info
58
59
60def set_sol_setting(setting_name, setting_value):
61
62    r"""
63    Set SOL setting with given value.
64
65    # Description of argument(s):
66    # setting_name    SOL setting which needs to be set (e.g. "retry-count").
67    # setting_value   Value which needs to be set (e.g. "7").
68    """
69
70    status, ret_values = grk.run_key_u("Run IPMI Standard Command  sol set " +
71                                       setting_name + " " + setting_value)
72
73    return status
74
75
76