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 | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 18 | 'PCIE_CARD' : 8, |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 19 | } |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 20 | FRU_STATES = { |
| 21 | 'NORMAL' : 0, |
| 22 | 'RECOVERABLE_ERROR' : 1, |
| 23 | 'FATAL_ERROR' : 2, |
| 24 | 'NOT_PRESENT' : 3, |
| 25 | } |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 26 | |
Norman James | 32e74e2 | 2015-09-15 21:28:06 -0500 | [diff] [blame] | 27 | |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 28 | ENUMS = { |
| 29 | 'org.openbmc.SensorIntegerThreshold.state' : |
| 30 | ['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'], |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | DBUS_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 | |
| 43 | BASE_TO_DBUS_TYPES = { |
| 44 | 'int' : 'dbus.Int32', |
| 45 | 'float' : 'dbus.Double', |
| 46 | 'str' : 'dbus.String', |
| 47 | 'long' : 'dbus.Int64', |
| 48 | 'bool' : 'dbus.Boolean' |
Norman James | ce46e3e | 2015-08-30 22:25:55 -0500 | [diff] [blame] | 49 | } |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 50 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 51 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 52 | def 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 James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 57 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 58 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 59 | def get_objs(bus,bus_name,path,objects): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 60 | tmp_path = path |
| 61 | if (path == ""): |
| 62 | tmp_path="/" |
| 63 | obj = bus.get_object(bus_name,tmp_path) |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 64 | introspect_iface = dbus.Interface(obj,"org.freedesktop.DBus.Introspectable") |
| 65 | tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect())) |
| 66 | root = tree.getroot() |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 67 | parent = True |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 68 | for node in root.iter('node'): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 69 | for intf in node.iter('interface'): |
| 70 | intf_name = intf.attrib['name'] |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 71 | 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 James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 80 | |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 81 | if (node.attrib.has_key('name') == True): |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 82 | node_name = node.attrib['name'] |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 83 | 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 James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 90 | |
| 91 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 92 | class DbusProperty: |
| 93 | def __init__(self,name,value): |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 94 | self.name = str(name) |
| 95 | self.dbusType = str(type(value)).split("'")[1] |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 96 | self.variant_level = 2 |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 97 | self.value = None |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 98 | 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 James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 107 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 108 | def setValue(self,value): |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 109 | try: |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 110 | self.value = eval(DBUS_TO_BASE_TYPES[self.dbusType]+"(value)") |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 111 | except: |
| 112 | raise Exception("Unknown dbus type: "+self.dbusType) |
| 113 | |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 114 | def setVariant(self,variant_level): |
| 115 | self.variant_level = variant_level |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 116 | |
| 117 | def getName(self): |
| 118 | return self.name |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 119 | |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 120 | def getValue(self): |
Norman James | 5d78b4d | 2015-09-05 13:34:34 -0500 | [diff] [blame] | 121 | e = self.dbusType+"(self.value, variant_level="+str(self.variant_level)+")" |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 122 | return eval(e) |
| 123 | |
Norman James | 362a80f | 2015-09-14 14:04:39 -0500 | [diff] [blame] | 124 | def getBaseValue(self): |
| 125 | return self.value |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 126 | |
| 127 | def __str__(self): |
| 128 | return self.dbusType+":"+str(self.value) |