blob: ab1aae3316be4bd2713b006e9770ef872001c3dd [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
Norman Jamesab777b12015-10-29 06:19:18 -050011import PropertyCacher
Norman James19e45912015-10-04 20:19:41 -050012
13if (len(sys.argv) < 2):
14 print "Usage: inventory_items.py [system name]"
15 exit(1)
16System = __import__(sys.argv[1])
17import Openbmc
18
19
20INTF_NAME = 'org.openbmc.InventoryItem'
21DBUS_NAME = 'org.openbmc.managers.Inventory'
Norman Jamesa3e47c42015-10-18 14:43:10 -050022ENUM_INTF = 'org.openbmc.Object.Enumerate'
Norman James19e45912015-10-04 20:19:41 -050023
24FRUS = System.FRU_INSTANCES
Norman James19e45912015-10-04 20:19:41 -050025
26class Inventory(dbus.service.Object):
27 def __init__(self,bus,name):
28 dbus.service.Object.__init__(self,bus,name)
29 self.objects = [ ]
30
31 def addItem(self,item):
32 self.objects.append(item)
33
Norman Jamesa3e47c42015-10-18 14:43:10 -050034 @dbus.service.method(ENUM_INTF,
Norman James19e45912015-10-04 20:19:41 -050035 in_signature='', out_signature='a{sa{sv}}')
Norman Jamesa3e47c42015-10-18 14:43:10 -050036 def enumerate(self):
Norman James19e45912015-10-04 20:19:41 -050037 tmp_obj = {}
38 for item in self.objects:
Norman Jamesa3e47c42015-10-18 14:43:10 -050039 tmp_obj[str(item.name)]=item.GetAll(INTF_NAME)
Norman James19e45912015-10-04 20:19:41 -050040 return tmp_obj
41
42
43
Norman Jamesa3e47c42015-10-18 14:43:10 -050044class InventoryItem(Openbmc.DbusProperties):
Norman Jamesb714eb22015-10-26 17:12:57 -050045 def __init__(self,bus,name,is_fru,fru_type):
Norman Jamesa3e47c42015-10-18 14:43:10 -050046 Openbmc.DbusProperties.__init__(self)
Norman James19e45912015-10-04 20:19:41 -050047 dbus.service.Object.__init__(self,bus,name)
Norman Jamesb714eb22015-10-26 17:12:57 -050048
Norman Jamesa3e47c42015-10-18 14:43:10 -050049 self.name = name
Norman Jamesb714eb22015-10-26 17:12:57 -050050
Norman Jamesab777b12015-10-29 06:19:18 -050051 ## this will load properties from cache
52 PropertyCacher.load(name,INTF_NAME,self.properties)
Norman Jamesb714eb22015-10-26 17:12:57 -050053 data = {'is_fru': is_fru, 'fru_type': fru_type, 'present': 'Inactive', 'fault': 'None'}
54 self.SetMultiple(INTF_NAME,data)
Norman Jamesab777b12015-10-29 06:19:18 -050055
Norman Jamesa3e47c42015-10-18 14:43:10 -050056
Norman Jamesab777b12015-10-29 06:19:18 -050057
Norman Jamesa3e47c42015-10-18 14:43:10 -050058
59 @dbus.service.method(INTF_NAME,
Norman James19e45912015-10-04 20:19:41 -050060 in_signature='a{sv}', out_signature='')
61 def update(self,data):
Norman Jamesb714eb22015-10-26 17:12:57 -050062 self.SetMultiple(INTF_NAME,data)
Norman Jamesab777b12015-10-29 06:19:18 -050063 PropertyCacher.save(self.name,INTF_NAME,self.properties)
Norman James19e45912015-10-04 20:19:41 -050064
Norman Jamesa3e47c42015-10-18 14:43:10 -050065 @dbus.service.method(INTF_NAME,
Norman James96da5c22015-10-15 10:17:06 -050066 in_signature='s', out_signature='')
67 def setPresent(self,present):
Norman Jamesb714eb22015-10-26 17:12:57 -050068 self.Set(INTF_NAME,'present',present)
Norman James96da5c22015-10-15 10:17:06 -050069
Norman Jamesa3e47c42015-10-18 14:43:10 -050070 @dbus.service.method(INTF_NAME,
Norman James96da5c22015-10-15 10:17:06 -050071 in_signature='s', out_signature='')
72 def setFault(self,fault):
Norman Jamesb714eb22015-10-26 17:12:57 -050073 self.Set(INTF_NAME,'fault',fault)
Norman James19e45912015-10-04 20:19:41 -050074
75
76if __name__ == '__main__':
77 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Norman James5e792e32015-10-07 17:36:17 -050078 bus = Openbmc.getDBus()
Norman James19e45912015-10-04 20:19:41 -050079 name = dbus.service.BusName(DBUS_NAME,bus)
80 mainloop = gobject.MainLoop()
Norman Jamesa3e47c42015-10-18 14:43:10 -050081 obj_parent = Inventory(bus, '/org/openbmc/inventory')
Norman James19e45912015-10-04 20:19:41 -050082
83 for f in FRUS.keys():
84 obj_path=f.replace("<inventory_root>",System.INVENTORY_ROOT)
Norman Jamesb714eb22015-10-26 17:12:57 -050085 obj = InventoryItem(bus,obj_path,FRUS[f]['is_fru'],FRUS[f]['fru_type'])
Norman James19e45912015-10-04 20:19:41 -050086 obj_parent.addItem(obj)
87
88 print "Running Inventory Manager"
89 mainloop.run()
90