1#!/usr/bin/env python3 -u
2import imp as imp
3import string as string
4
5from robot.libraries.BuiltIn import BuiltIn
6
7
8def get_sensor(module_name, value):
9    m = imp.load_source("module.name", module_name)
10
11    for i in m.ID_LOOKUP["SENSOR"]:
12        if m.ID_LOOKUP["SENSOR"][i] == value:
13            return i
14
15    return 0xFF
16
17
18def get_inventory_sensor(module_name, value):
19    m = imp.load_source("module.name", module_name)
20
21    value = string.replace(value, m.INVENTORY_ROOT, "<inventory_root>")
22
23    for i in m.ID_LOOKUP["SENSOR"]:
24        if m.ID_LOOKUP["SENSOR"][i] == value:
25            return i
26
27    return 0xFF
28
29
30def get_inventory_list(module_name):
31    inventory_list = []
32    m = imp.load_source("module.name", module_name)
33
34    for i in m.ID_LOOKUP["FRU"]:
35        s = m.ID_LOOKUP["FRU"][i]
36        s = s.replace("<inventory_root>", m.INVENTORY_ROOT)
37        inventory_list.append(s)
38
39    return inventory_list
40
41
42def get_inventory_fru_type_list(module_name, fru_type):
43    inventory_list = []
44    m = imp.load_source("module.name", module_name)
45
46    for i in m.FRU_INSTANCES.keys():
47        if m.FRU_INSTANCES[i]["fru_type"] == fru_type:
48            s = i.replace("<inventory_root>", m.INVENTORY_ROOT)
49            inventory_list.append(s)
50
51    return inventory_list
52
53
54def call_keyword(keyword):
55    return BuiltIn().run_keyword(keyword)
56
57
58def get_FRU_component_name_list(module_name):
59    name_list = []
60    m = imp.load_source("module.name", module_name)
61
62    for name in m.FRU_COMPONENT_NAME:
63        name_list.append(name)
64        print(name)
65
66    return name_list
67
68
69def get_ipmi_rest_fru_field_map(module_name):
70    m = imp.load_source("module.name", module_name)
71
72    ipmi_rest_fru_field_map = dict.copy(m.ipmi_rest_fru_field_map)
73
74    return ipmi_rest_fru_field_map
75