blob: d23e3450c8c24aecb2ceef2f1c82357c7faee176 [file] [log] [blame]
Norman James42c1be82015-10-22 14:34:26 -05001#!/usr/bin/python -u
Norman James19e45912015-10-04 20:19:41 -05002
3import os
4import sys
5import gobject
6import dbus
7import dbus.service
8import dbus.mainloop.glib
9import cPickle
10import json
11
12if (len(sys.argv) < 2):
13 print "Usage: inventory_items.py [system name]"
14 exit(1)
15System = __import__(sys.argv[1])
16import Openbmc
17
18
19INTF_NAME = 'org.openbmc.InventoryItem'
20DBUS_NAME = 'org.openbmc.managers.Inventory'
Norman Jamesa3e47c42015-10-18 14:43:10 -050021ENUM_INTF = 'org.openbmc.Object.Enumerate'
Norman James19e45912015-10-04 20:19:41 -050022
23FRUS = System.FRU_INSTANCES
Norman James19e45912015-10-04 20:19:41 -050024
25class Inventory(dbus.service.Object):
26 def __init__(self,bus,name):
27 dbus.service.Object.__init__(self,bus,name)
28 self.objects = [ ]
29
30 def addItem(self,item):
31 self.objects.append(item)
32
Norman Jamesa3e47c42015-10-18 14:43:10 -050033 @dbus.service.method(ENUM_INTF,
Norman James19e45912015-10-04 20:19:41 -050034 in_signature='', out_signature='a{sa{sv}}')
Norman Jamesa3e47c42015-10-18 14:43:10 -050035 def enumerate(self):
Norman James19e45912015-10-04 20:19:41 -050036 tmp_obj = {}
37 for item in self.objects:
Norman Jamesa3e47c42015-10-18 14:43:10 -050038 tmp_obj[str(item.name)]=item.GetAll(INTF_NAME)
Norman James19e45912015-10-04 20:19:41 -050039 return tmp_obj
40
41
42
Norman Jamesa3e47c42015-10-18 14:43:10 -050043class InventoryItem(Openbmc.DbusProperties):
Norman Jamesb714eb22015-10-26 17:12:57 -050044 def __init__(self,bus,name,is_fru,fru_type):
Norman Jamesa3e47c42015-10-18 14:43:10 -050045 Openbmc.DbusProperties.__init__(self)
Norman James19e45912015-10-04 20:19:41 -050046 dbus.service.Object.__init__(self,bus,name)
Norman Jamesb714eb22015-10-26 17:12:57 -050047
Norman Jamesa3e47c42015-10-18 14:43:10 -050048 self.name = name
Norman Jamesb714eb22015-10-26 17:12:57 -050049 ## this will load properties from cache
50 self.Register('org.openbmc.InventoryItem')
51
52 data = {'is_fru': is_fru, 'fru_type': fru_type, 'present': 'Inactive', 'fault': 'None'}
53 self.SetMultiple(INTF_NAME,data)
Norman Jamesa3e47c42015-10-18 14:43:10 -050054
Norman Jamesb714eb22015-10-26 17:12:57 -050055
56 @dbus.service.signal('org.openbmc.PersistantInterface',
57 signature='s')
58 def Register(self,interface):
59 pass
Norman Jamesa3e47c42015-10-18 14:43:10 -050060
61 @dbus.service.method(INTF_NAME,
Norman James19e45912015-10-04 20:19:41 -050062 in_signature='a{sv}', out_signature='')
63 def update(self,data):
Norman Jamesb714eb22015-10-26 17:12:57 -050064 self.SetMultiple(INTF_NAME,data)
Norman James19e45912015-10-04 20:19:41 -050065
Norman Jamesa3e47c42015-10-18 14:43:10 -050066 @dbus.service.method(INTF_NAME,
Norman James96da5c22015-10-15 10:17:06 -050067 in_signature='s', out_signature='')
68 def setPresent(self,present):
Norman Jamesb714eb22015-10-26 17:12:57 -050069 self.Set(INTF_NAME,'present',present)
Norman James96da5c22015-10-15 10:17:06 -050070
Norman Jamesa3e47c42015-10-18 14:43:10 -050071 @dbus.service.method(INTF_NAME,
Norman James96da5c22015-10-15 10:17:06 -050072 in_signature='s', out_signature='')
73 def setFault(self,fault):
Norman Jamesb714eb22015-10-26 17:12:57 -050074 self.Set(INTF_NAME,'fault',fault)
Norman James19e45912015-10-04 20:19:41 -050075
76
77if __name__ == '__main__':
78 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050079 bus = Openbmc.getDBus()
Norman James19e45912015-10-04 20:19:41 -050080 name = dbus.service.BusName(DBUS_NAME,bus)
81 mainloop = gobject.MainLoop()
Norman Jamesa3e47c42015-10-18 14:43:10 -050082 obj_parent = Inventory(bus, '/org/openbmc/inventory')
Norman James19e45912015-10-04 20:19:41 -050083
84 for f in FRUS.keys():
85 obj_path=f.replace("<inventory_root>",System.INVENTORY_ROOT)
Norman Jamesb714eb22015-10-26 17:12:57 -050086 obj = InventoryItem(bus,obj_path,FRUS[f]['is_fru'],FRUS[f]['fru_type'])
Norman James19e45912015-10-04 20:19:41 -050087 obj_parent.addItem(obj)
88
89 print "Running Inventory Manager"
90 mainloop.run()
91