blob: 9163b3ca2cd964f6afeba5dd7ff7af7d91bcf528 [file] [log] [blame]
George Keishingae7c8202017-02-09 10:33:45 -06001#!/usr/bin/env python
2r"""
3Generate an inventory variable file containing a list of properties
4fields from the YAML phosphor-dbus-interfaces repository.
5"""
6import sys
7import os
8import yaml
9import json
10
11lib_path = sys.path[0] + "/../lib"
12sys.path.insert(0, lib_path)
13from gen_print import *
14
15# This list will be longer when more development codes are available.
Steven Sombar5c006d32018-10-08 09:35:38 -050016inventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu']
George Keishingae7c8202017-02-09 10:33:45 -060017print_var(inventory_items)
18fru_inventory_file_path = 'inventory.py'
19print_var(fru_inventory_file_path)
20
21# Properties master list
22yaml_master_list = []
23
24# Clone the phosphor-dbus-interfaces repository
25cmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces'
26os.system(cmd_buf)
27
George Keishing36fedf22017-03-21 06:30:27 -050028repo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/'
George Keishingae7c8202017-02-09 10:33:45 -060029base_dir_path = os.getcwd() + repo_subdir_path
30
George Keishing9ef1fd42017-03-10 14:52:38 -060031# yaml file paths for FRU
Sweta Potthuri1da4c242018-01-09 04:42:51 -060032yaml_fru_list = ['Inventory/Item.interface.yaml',
33 'Inventory/Decorator/Asset.interface.yaml',
34 'Inventory/Decorator/Revision.interface.yaml',
35 'Inventory/Decorator/Replaceable.interface.yaml',
36 'Inventory/Decorator/Cacheable.interface.yaml',
37 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingae7c8202017-02-09 10:33:45 -060038
Sweta Potthuri1da4c242018-01-09 04:42:51 -060039# yaml file paths for CORE.
Sweta Potthuri1da4c242018-01-09 04:42:51 -060040yaml_core_list = ['Inventory/Item.interface.yaml',
41 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingdc68eff2017-06-12 22:43:18 -050042
43# yaml file paths for fan.
Sweta Potthuri1da4c242018-01-09 04:42:51 -060044yaml_fan_list = ['Inventory/Item.interface.yaml',
45 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml',
46 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050047
48# yaml file paths for fan_wc (fans in water-cooled system).
49yaml_fan_wc_list = ['Inventory/Item.interface.yaml',
50 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', ]
51
George Keishing19305202017-11-17 12:07:28 -060052# yaml file paths for GPU.
Sweta Potthuri1da4c242018-01-09 04:42:51 -060053yaml_gpu_list = ['Inventory/Item.interface.yaml',
George Keishing0219da62018-03-26 03:24:40 -050054 'Inventory/Decorator/Replaceable.interface.yaml',
Sweta Potthuri1da4c242018-01-09 04:42:51 -060055 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050056
George Keishingae7c8202017-02-09 10:33:45 -060057# Append to master list
58yaml_master_list.append(yaml_fru_list)
George Keishing36fedf22017-03-21 06:30:27 -050059yaml_master_list.append(yaml_core_list)
George Keishingdc68eff2017-06-12 22:43:18 -050060yaml_master_list.append(yaml_fan_list)
Steven Sombar5c006d32018-10-08 09:35:38 -050061yaml_master_list.append(yaml_fan_wc_list)
George Keishing19305202017-11-17 12:07:28 -060062yaml_master_list.append(yaml_gpu_list)
George Keishingae7c8202017-02-09 10:33:45 -060063
George Keishing9ef1fd42017-03-10 14:52:38 -060064print_var(yaml_master_list)
65
George Keishingae7c8202017-02-09 10:33:45 -060066# Populate Inventory data
67inventory_dict = {}
68
George Keishing9ef1fd42017-03-10 14:52:38 -060069for master_index in range(len(yaml_master_list)):
70 print_var(master_index)
George Keishingae7c8202017-02-09 10:33:45 -060071 inventory_dict[str(inventory_items[master_index])] = []
George Keishing9ef1fd42017-03-10 14:52:38 -060072 for rel_yaml_file_path in yaml_master_list[master_index]:
73 yaml_file_path = base_dir_path + rel_yaml_file_path
George Keishingae7c8202017-02-09 10:33:45 -060074
75 # Get the yaml dictionary data
George Keishing9ef1fd42017-03-10 14:52:38 -060076 print_timen("Loading " + yaml_file_path)
77 f = open(yaml_file_path)
George Keishingae7c8202017-02-09 10:33:45 -060078 yaml_data = yaml.load(f)
79 f.close()
80 for item in range(0, len(yaml_data['properties'])):
81 tmp_data = yaml_data['properties'][item]['name']
82 inventory_dict[str(inventory_items[master_index])].append(tmp_data)
83
84# Pretty print json formatter
George Keishing9ef1fd42017-03-10 14:52:38 -060085data = json.dumps(inventory_dict,
86 indent=4,
87 sort_keys=True,
88 default=str,
89 separators=(',', ':'))
George Keishingae7c8202017-02-09 10:33:45 -060090
91# Check if there is mismatch in data vs expect list
92if len(inventory_dict) != len(inventory_items):
93 print_error("The generated list doesn't match Master Inventory List.\n")
George Keishing32c4c9e2018-08-06 14:00:10 -050094 print (data)
George Keishingae7c8202017-02-09 10:33:45 -060095 print_var(inventory_items)
96 sys.exit()
97
98# Write dictionary data to inventory file
George Keishing32c4c9e2018-08-06 14:00:10 -050099print ("\nGenerated Inventory item json format\n")
100print (data)
George Keishingae7c8202017-02-09 10:33:45 -0600101out = open(fru_inventory_file_path, 'w')
102out.write('inventory_dict = ')
103out.write(data)
104
105out.close()
George Keishing32c4c9e2018-08-06 14:00:10 -0500106print ("\nGenerated Inventory File: %s " % fru_inventory_file_path)