summaryrefslogtreecommitdiffstats
path: root/pyinventorymgr
diff options
context:
space:
mode:
authorMatt Spinler <spinler@us.ibm.com>2016-08-15 13:31:10 -0500
committerPatrick Williams <patrick@stwcx.xyz>2016-09-08 18:04:17 +0000
commit14c8286a7e4e81481e1387238ce1efaf72ea3e14 (patch)
tree92ca19660614c182acb5766ae5cfe656e8a38683 /pyinventorymgr
parente2c68b315fabf270b925c8c85aed5cfa907e77e8 (diff)
downloadtalos-skeleton-14c8286a7e4e81481e1387238ce1efaf72ea3e14.tar.gz
talos-skeleton-14c8286a7e4e81481e1387238ce1efaf72ea3e14.zip
Add ability to load inventory from file instead of hardcoding.
This commit allows inventory_items.py to load the inventory from /usr/share/inventory/inventory.json instead of using the hardcoded array in <System>.py. A future commit will generate inventory.json from the machine readable workbook XML for at least one system. If the code can't load the json file, it will fall back to the hardcoded array, which at this point we know is always present. Even though pyinventorymgr will probably be rewritten in C++ at some point, this series of commits illustrates how the OpenBMC can utilize a data-driven design, and this component was chosen as it takes a minimal amount of changes. Change-Id: Ie749a068d6f47c5671677b21ff3ef5418739f161 Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Diffstat (limited to 'pyinventorymgr')
-rw-r--r--pyinventorymgr/inventory_items.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/pyinventorymgr/inventory_items.py b/pyinventorymgr/inventory_items.py
index d6d3d1d..41e3093 100644
--- a/pyinventorymgr/inventory_items.py
+++ b/pyinventorymgr/inventory_items.py
@@ -84,6 +84,17 @@ if __name__ == '__main__':
bus = get_dbus()
mainloop = gobject.MainLoop()
obj_parent = Inventory(bus, '/org/openbmc/inventory')
+ INVENTORY_FILE = os.path.join(sys.prefix, 'share',
+ 'inventory', 'inventory.json')
+
+ if os.path.exists(INVENTORY_FILE):
+ with open(INVENTORY_FILE, 'r') as f:
+ try:
+ inv = json.load(f)
+ except ValueError:
+ print "Invalid JSON detected in " + INVENTORY_FILE
+ else:
+ FRUS = inv
for f in FRUS.keys():
obj_path = f.replace("<inventory_root>", System.INVENTORY_ROOT)
OpenPOWER on IntegriCloud