blob: bb3a8797de8157fd6db747db2d3fbec57e23f816 [file] [log] [blame]
Norman Jamesce46e3e2015-08-30 22:25:55 -05001import dbus
Norman James9e6acf92015-09-08 07:00:04 -05002import xml.etree.ElementTree as ET
Norman Jamesce46e3e2015-08-30 22:25:55 -05003
4BUS_PREFIX = 'org.openbmc'
Norman James362a80f2015-09-14 14:04:39 -05005OBJ_PREFIX = "/org/openbmc"
Norman Jamesce46e3e2015-08-30 22:25:55 -05006GPIO_DEV = '/sys/class/gpio'
7
8
9FRU_TYPES = {
Norman James88872672015-09-21 16:51:35 -050010 'SYSTEM' : 0,
Norman James90baede2015-09-02 20:32:49 -050011 'CPU' : 1,
12 'DIMM' : 2,
Norman James88872672015-09-21 16:51:35 -050013 'MAIN_PLANAR' : 3,
Norman James90baede2015-09-02 20:32:49 -050014 'RISER_CARD' : 4,
Norman James88872672015-09-21 16:51:35 -050015 'FAN' : 5,
16 'BMC' : 6,
17 'CORE' : 7,
Norman James19e45912015-10-04 20:19:41 -050018 'PCIE_CARD' : 8,
Norman Jamesce46e3e2015-08-30 22:25:55 -050019}
Norman James362a80f2015-09-14 14:04:39 -050020FRU_STATES = {
21 'NORMAL' : 0,
22 'RECOVERABLE_ERROR' : 1,
23 'FATAL_ERROR' : 2,
24 'NOT_PRESENT' : 3,
25}
Norman James32e74e22015-09-15 21:28:06 -050026
Norman James32e74e22015-09-15 21:28:06 -050027
Norman Jamesce46e3e2015-08-30 22:25:55 -050028ENUMS = {
29 'org.openbmc.SensorIntegerThreshold.state' :
30 ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'],
Norman James362a80f2015-09-14 14:04:39 -050031}
32
33DBUS_TO_BASE_TYPES = {
34 'dbus.Byte' : 'int',
35 'dbus.Double' : 'float',
36 'dbus.Int32' : 'int',
37 'dbus.UInt32' : 'long',
38 'dbus.String' : 'str',
39 'dbus.UInt64' : 'long',
40 'dbus.Boolean' : 'bool',
41}
42
43BASE_TO_DBUS_TYPES = {
44 'int' : 'dbus.Int32',
45 'float' : 'dbus.Double',
46 'str' : 'dbus.String',
47 'long' : 'dbus.Int64',
48 'bool' : 'dbus.Boolean'
Norman Jamesce46e3e2015-08-30 22:25:55 -050049}
Norman James90baede2015-09-02 20:32:49 -050050
Norman James5d78b4d2015-09-05 13:34:34 -050051
Norman James362a80f2015-09-14 14:04:39 -050052def getManagerInterface(bus,manager):
53 bus_name = "org.openbmc.managers."+manager
54 obj_name = "/org/openbmc/managers/"+manager
55 obj = bus.get_object(bus_name,obj_name)
56 return dbus.Interface(obj,bus_name)
Norman James5d78b4d2015-09-05 13:34:34 -050057
Norman James5d78b4d2015-09-05 13:34:34 -050058
Norman James362a80f2015-09-14 14:04:39 -050059def get_objs(bus,bus_name,path,objects):
Norman James19e45912015-10-04 20:19:41 -050060 tmp_path = path
61 if (path == ""):
62 tmp_path="/"
63 obj = bus.get_object(bus_name,tmp_path)
Norman James9e6acf92015-09-08 07:00:04 -050064 introspect_iface = dbus.Interface(obj,"org.freedesktop.DBus.Introspectable")
65 tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect()))
66 root = tree.getroot()
Norman James19e45912015-10-04 20:19:41 -050067 parent = True
Norman James362a80f2015-09-14 14:04:39 -050068 for node in root.iter('node'):
Norman James19e45912015-10-04 20:19:41 -050069 for intf in node.iter('interface'):
70 intf_name = intf.attrib['name']
Norman James19e45912015-10-04 20:19:41 -050071 parts=path.split('/')
72 instance = parts[len(parts)-1]
73 if (objects.has_key(instance) == False):
74 objects[instance] = {}
75 objects[instance]['PATH'] = path
76 objects[instance]['INIT'] = []
77 for method in intf.iter('method'):
78 if (method.attrib['name'] == "init"):
79 objects[instance]['INIT'].append(intf_name)
Norman James362a80f2015-09-14 14:04:39 -050080
Norman James19e45912015-10-04 20:19:41 -050081 if (node.attrib.has_key('name') == True):
Norman James362a80f2015-09-14 14:04:39 -050082 node_name = node.attrib['name']
Norman James19e45912015-10-04 20:19:41 -050083 if (parent == False):
84 get_objs(bus,bus_name,path+"/"+node_name,objects)
85 else:
86 if (node_name != "" and node_name != path):
87 get_objs(bus,bus_name,node_name,objects)
88
89 parent = False
Norman James362a80f2015-09-14 14:04:39 -050090
91
Norman James90baede2015-09-02 20:32:49 -050092class DbusProperty:
93 def __init__(self,name,value):
Norman James90baede2015-09-02 20:32:49 -050094 self.name = str(name)
95 self.dbusType = str(type(value)).split("'")[1]
Norman James362a80f2015-09-14 14:04:39 -050096 self.variant_level = 2
Norman James90baede2015-09-02 20:32:49 -050097 self.value = None
Norman James362a80f2015-09-14 14:04:39 -050098 if (BASE_TO_DBUS_TYPES.has_key(self.dbusType) == False):
99 self.variant_level = value.variant_level
100 try:
101 self.value = eval(DBUS_TO_BASE_TYPES[self.dbusType]+"(value)")
102 except:
103 raise Exception("Unknown dbus type: "+self.dbusType)
104 else:
105 self.dbusType = BASE_TO_DBUS_TYPES[self.dbusType]
106 self.value = value
Norman James90baede2015-09-02 20:32:49 -0500107
Norman James5d78b4d2015-09-05 13:34:34 -0500108 def setValue(self,value):
Norman James90baede2015-09-02 20:32:49 -0500109 try:
Norman James362a80f2015-09-14 14:04:39 -0500110 self.value = eval(DBUS_TO_BASE_TYPES[self.dbusType]+"(value)")
Norman James90baede2015-09-02 20:32:49 -0500111 except:
112 raise Exception("Unknown dbus type: "+self.dbusType)
113
Norman James5d78b4d2015-09-05 13:34:34 -0500114 def setVariant(self,variant_level):
115 self.variant_level = variant_level
Norman James90baede2015-09-02 20:32:49 -0500116
117 def getName(self):
118 return self.name
Norman James5d78b4d2015-09-05 13:34:34 -0500119
Norman James90baede2015-09-02 20:32:49 -0500120 def getValue(self):
Norman James5d78b4d2015-09-05 13:34:34 -0500121 e = self.dbusType+"(self.value, variant_level="+str(self.variant_level)+")"
Norman James90baede2015-09-02 20:32:49 -0500122 return eval(e)
123
Norman James362a80f2015-09-14 14:04:39 -0500124 def getBaseValue(self):
125 return self.value
Norman James90baede2015-09-02 20:32:49 -0500126
127 def __str__(self):
128 return self.dbusType+":"+str(self.value)