Norman James | 42c1be8 | 2015-10-22 14:34:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/python -u |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import gobject |
| 6 | import dbus |
| 7 | import dbus.service |
| 8 | import dbus.mainloop.glib |
| 9 | import cPickle |
| 10 | import json |
| 11 | |
| 12 | if (len(sys.argv) < 2): |
| 13 | print "Usage: inventory_items.py [system name]" |
| 14 | exit(1) |
| 15 | System = __import__(sys.argv[1]) |
| 16 | import Openbmc |
| 17 | |
| 18 | |
| 19 | INTF_NAME = 'org.openbmc.InventoryItem' |
| 20 | DBUS_NAME = 'org.openbmc.managers.Inventory' |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 21 | ENUM_INTF = 'org.openbmc.Object.Enumerate' |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 22 | |
| 23 | FRUS = System.FRU_INSTANCES |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 24 | |
| 25 | class 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 James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 33 | @dbus.service.method(ENUM_INTF, |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 34 | in_signature='', out_signature='a{sa{sv}}') |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 35 | def enumerate(self): |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 36 | tmp_obj = {} |
| 37 | for item in self.objects: |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 38 | tmp_obj[str(item.name)]=item.GetAll(INTF_NAME) |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 39 | return tmp_obj |
| 40 | |
| 41 | |
| 42 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 43 | class InventoryItem(Openbmc.DbusProperties): |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 44 | def __init__(self,bus,name,is_fru,fru_type): |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 45 | Openbmc.DbusProperties.__init__(self) |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 46 | dbus.service.Object.__init__(self,bus,name) |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 47 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 48 | self.name = name |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 49 | ## 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 James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 54 | |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 55 | |
| 56 | @dbus.service.signal('org.openbmc.PersistantInterface', |
| 57 | signature='s') |
| 58 | def Register(self,interface): |
| 59 | pass |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 60 | |
| 61 | @dbus.service.method(INTF_NAME, |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 62 | in_signature='a{sv}', out_signature='') |
| 63 | def update(self,data): |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 64 | self.SetMultiple(INTF_NAME,data) |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 65 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 66 | @dbus.service.method(INTF_NAME, |
Norman James | 96da5c2 | 2015-10-15 10:17:06 -0500 | [diff] [blame] | 67 | in_signature='s', out_signature='') |
| 68 | def setPresent(self,present): |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 69 | self.Set(INTF_NAME,'present',present) |
Norman James | 96da5c2 | 2015-10-15 10:17:06 -0500 | [diff] [blame] | 70 | |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 71 | @dbus.service.method(INTF_NAME, |
Norman James | 96da5c2 | 2015-10-15 10:17:06 -0500 | [diff] [blame] | 72 | in_signature='s', out_signature='') |
| 73 | def setFault(self,fault): |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 74 | self.Set(INTF_NAME,'fault',fault) |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 75 | |
| 76 | |
| 77 | if __name__ == '__main__': |
| 78 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Norman James | 5e792e3 | 2015-10-07 17:36:17 -0500 | [diff] [blame] | 79 | bus = Openbmc.getDBus() |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 80 | name = dbus.service.BusName(DBUS_NAME,bus) |
| 81 | mainloop = gobject.MainLoop() |
Norman James | a3e47c4 | 2015-10-18 14:43:10 -0500 | [diff] [blame] | 82 | obj_parent = Inventory(bus, '/org/openbmc/inventory') |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 83 | |
| 84 | for f in FRUS.keys(): |
| 85 | obj_path=f.replace("<inventory_root>",System.INVENTORY_ROOT) |
Norman James | b714eb2 | 2015-10-26 17:12:57 -0500 | [diff] [blame] | 86 | obj = InventoryItem(bus,obj_path,FRUS[f]['is_fru'],FRUS[f]['fru_type']) |
Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 87 | obj_parent.addItem(obj) |
| 88 | |
| 89 | print "Running Inventory Manager" |
| 90 | mainloop.run() |
| 91 | |