Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 1 | import dbus |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 2 | import xml.etree.ElementTree as ET |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 3 | |
| 4 | BUS_PREFIX = 'org.openbmc' |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 5 | OBJ_PREFIX = "/org/openbmc" |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 6 | GPIO_DEV = '/sys/class/gpio' |
| 7 | |
| 8 | |
| 9 | FRU_TYPES = { |
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 10 | 'SYSTEM' : 0, |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 11 | 'CPU' : 1, |
| 12 | 'DIMM' : 2, |
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 13 | 'MAIN_PLANAR' : 3, |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 14 | 'RISER_CARD' : 4, |
Norman James | 8887267 | 2015-09-21 16:51:35 -0500 | [diff] [blame] | 15 | 'FAN' : 5, |
| 16 | 'BMC' : 6, |
| 17 | 'CORE' : 7, |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 18 | } |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 19 | FRU_STATES = { |
| 20 | 'NORMAL' : 0, |
| 21 | 'RECOVERABLE_ERROR' : 1, |
| 22 | 'FATAL_ERROR' : 2, |
| 23 | 'NOT_PRESENT' : 3, |
| 24 | } |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 25 | |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 26 | |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 27 | ENUMS = { |
| 28 | 'org.openbmc.SensorIntegerThreshold.state' : |
| 29 | ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'], |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | DBUS_TO_BASE_TYPES = { |
| 33 | 'dbus.Byte' : 'int', |
| 34 | 'dbus.Double' : 'float', |
| 35 | 'dbus.Int32' : 'int', |
| 36 | 'dbus.UInt32' : 'long', |
| 37 | 'dbus.String' : 'str', |
| 38 | 'dbus.UInt64' : 'long', |
| 39 | 'dbus.Boolean' : 'bool', |
| 40 | } |
| 41 | |
| 42 | BASE_TO_DBUS_TYPES = { |
| 43 | 'int' : 'dbus.Int32', |
| 44 | 'float' : 'dbus.Double', |
| 45 | 'str' : 'dbus.String', |
| 46 | 'long' : 'dbus.Int64', |
| 47 | 'bool' : 'dbus.Boolean' |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 48 | } |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 49 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 50 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 51 | def getManagerInterface(bus,manager): |
| 52 | bus_name = "org.openbmc.managers."+manager |
| 53 | obj_name = "/org/openbmc/managers/"+manager |
| 54 | obj = bus.get_object(bus_name,obj_name) |
| 55 | return dbus.Interface(obj,bus_name) |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 56 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 57 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 58 | def get_objs(bus,bus_name,path,objects): |
| 59 | obj = bus.get_object(bus_name,path) |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 60 | introspect_iface = dbus.Interface(obj,"org.freedesktop.DBus.Introspectable") |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 61 | #print introspect_iface.Introspect() |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 62 | tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect())) |
| 63 | root = tree.getroot() |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 64 | for node in root.iter('node'): |
| 65 | if (node.attrib.has_key('name') == False): |
| 66 | for intf in node.iter('interface'): |
| 67 | intf_name = intf.attrib['name'] |
| 68 | if (intf_name.find(BUS_PREFIX)==0): |
| 69 | parts=path.split('/') |
| 70 | instance = parts[len(parts)-1] |
| 71 | if (objects.has_key(instance) == False): |
| 72 | objects[instance] = {} |
| 73 | objects[instance]['PATH'] = path |
| 74 | objects[instance]['INIT'] = [] |
| 75 | for method in intf.iter('method'): |
| 76 | if (method.attrib['name'] == "init"): |
| 77 | objects[instance]['INIT'].append(intf_name) |
| 78 | |
| 79 | else: |
| 80 | node_name = node.attrib['name'] |
| 81 | if (node_name != path): |
| 82 | get_objs(bus,bus_name,path+"/"+node.attrib['name'],objects) |
| 83 | |
| 84 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 85 | class DbusProperty: |
| 86 | def __init__(self,name,value): |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 87 | self.name = str(name) |
| 88 | self.dbusType = str(type(value)).split("'")[1] |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 89 | self.variant_level = 2 |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 90 | self.value = None |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 91 | if (BASE_TO_DBUS_TYPES.has_key(self.dbusType) == False): |
| 92 | self.variant_level = value.variant_level |
| 93 | try: |
| 94 | self.value = eval(DBUS_TO_BASE_TYPES[self.dbusType]+"(value)") |
| 95 | except: |
| 96 | raise Exception("Unknown dbus type: "+self.dbusType) |
| 97 | else: |
| 98 | self.dbusType = BASE_TO_DBUS_TYPES[self.dbusType] |
| 99 | self.value = value |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 100 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 101 | def setValue(self,value): |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 102 | try: |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 103 | self.value = eval(DBUS_TO_BASE_TYPES[self.dbusType]+"(value)") |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 104 | except: |
| 105 | raise Exception("Unknown dbus type: "+self.dbusType) |
| 106 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 107 | def setVariant(self,variant_level): |
| 108 | self.variant_level = variant_level |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 109 | |
| 110 | def getName(self): |
| 111 | return self.name |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 112 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 113 | def getValue(self): |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 114 | e = self.dbusType+"(self.value, variant_level="+str(self.variant_level)+")" |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 115 | return eval(e) |
| 116 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 117 | def getBaseValue(self): |
| 118 | return self.value |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 119 | |
| 120 | def __str__(self): |
| 121 | return self.dbusType+":"+str(self.value) |