blob: c6a7d57c73e16b158e5aeba545275c7caeb24d61 [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
George Keishingae7c8202017-02-09 10:33:45 -06002r"""
3Generate an inventory variable file containing a list of properties
4fields from the YAML phosphor-dbus-interfaces repository.
5"""
George Keishinge635ddc2022-12-08 07:38:02 -06006import json
Patrick Williams20f38712022-12-08 06:18:26 -06007import os
8import sys
9
10import yaml
George Keishinge635ddc2022-12-08 07:38:02 -060011
George Keishingae7c8202017-02-09 10:33:45 -060012lib_path = sys.path[0] + "/../lib"
13sys.path.insert(0, lib_path)
Patrick Williams20f38712022-12-08 06:18:26 -060014from gen_print import * # NOQA
George Keishingae7c8202017-02-09 10:33:45 -060015
16# This list will be longer when more development codes are available.
Patrick Williams20f38712022-12-08 06:18:26 -060017inventory_items = ["fru", "core", "fan", "fan_wc", "gpu"]
George Keishingae7c8202017-02-09 10:33:45 -060018print_var(inventory_items)
Patrick Williams20f38712022-12-08 06:18:26 -060019fru_inventory_file_path = "inventory.py"
George Keishingae7c8202017-02-09 10:33:45 -060020print_var(fru_inventory_file_path)
21
George Keishing1eab8832020-07-09 06:30:57 -050022# Properties inventory list
23yaml_inventory_list = []
George Keishingae7c8202017-02-09 10:33:45 -060024
25# Clone the phosphor-dbus-interfaces repository
Patrick Williams20f38712022-12-08 06:18:26 -060026cmd_buf = "git clone https://github.com/openbmc/phosphor-dbus-interfaces"
George Keishingae7c8202017-02-09 10:33:45 -060027os.system(cmd_buf)
28
Patrick Williams20f38712022-12-08 06:18:26 -060029repo_subdir_path = "/phosphor-dbus-interfaces/xyz/openbmc_project/"
George Keishingae7c8202017-02-09 10:33:45 -060030base_dir_path = os.getcwd() + repo_subdir_path
31
George Keishing9ef1fd42017-03-10 14:52:38 -060032# yaml file paths for FRU
Patrick Williams20f38712022-12-08 06:18:26 -060033yaml_fru_list = [
34 "Inventory/Item.interface.yaml",
35 "Inventory/Decorator/Asset.interface.yaml",
36 "Inventory/Decorator/Revision.interface.yaml",
37 "Inventory/Decorator/Replaceable.interface.yaml",
38 "Inventory/Decorator/Cacheable.interface.yaml",
39 "State/Decorator/OperationalStatus.interface.yaml",
40]
George Keishingae7c8202017-02-09 10:33:45 -060041
Sweta Potthuri1da4c242018-01-09 04:42:51 -060042# yaml file paths for CORE.
Patrick Williams20f38712022-12-08 06:18:26 -060043yaml_core_list = [
44 "Inventory/Item.interface.yaml",
45 "State/Decorator/OperationalStatus.interface.yaml",
46]
George Keishingdc68eff2017-06-12 22:43:18 -050047
48# yaml file paths for fan.
Patrick Williams20f38712022-12-08 06:18:26 -060049yaml_fan_list = [
50 "Inventory/Item.interface.yaml",
51 "Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml",
52 "State/Decorator/OperationalStatus.interface.yaml",
53]
Steven Sombar5c006d32018-10-08 09:35:38 -050054
55# yaml file paths for fan_wc (fans in water-cooled system).
Patrick Williams20f38712022-12-08 06:18:26 -060056yaml_fan_wc_list = [
57 "Inventory/Item.interface.yaml",
58 "Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml",
59]
Steven Sombar5c006d32018-10-08 09:35:38 -050060
George Keishing19305202017-11-17 12:07:28 -060061# yaml file paths for GPU.
Patrick Williams20f38712022-12-08 06:18:26 -060062yaml_gpu_list = [
63 "Inventory/Item.interface.yaml",
64 "Inventory/Decorator/Replaceable.interface.yaml",
65 "State/Decorator/OperationalStatus.interface.yaml",
66]
Steven Sombar5c006d32018-10-08 09:35:38 -050067
George Keishing1eab8832020-07-09 06:30:57 -050068# Append to inventory list
69yaml_inventory_list.append(yaml_fru_list)
70yaml_inventory_list.append(yaml_core_list)
71yaml_inventory_list.append(yaml_fan_list)
72yaml_inventory_list.append(yaml_fan_wc_list)
73yaml_inventory_list.append(yaml_gpu_list)
George Keishingae7c8202017-02-09 10:33:45 -060074
George Keishing1eab8832020-07-09 06:30:57 -050075print_var(yaml_inventory_list)
George Keishing9ef1fd42017-03-10 14:52:38 -060076
George Keishingae7c8202017-02-09 10:33:45 -060077# Populate Inventory data
78inventory_dict = {}
79
George Keishing1eab8832020-07-09 06:30:57 -050080for inv_index in range(len(yaml_inventory_list)):
81 print_var(inv_index)
82 inventory_dict[str(inventory_items[inv_index])] = []
83 for rel_yaml_file_path in yaml_inventory_list[inv_index]:
George Keishing9ef1fd42017-03-10 14:52:38 -060084 yaml_file_path = base_dir_path + rel_yaml_file_path
George Keishingae7c8202017-02-09 10:33:45 -060085
86 # Get the yaml dictionary data
George Keishing9ef1fd42017-03-10 14:52:38 -060087 print_timen("Loading " + yaml_file_path)
88 f = open(yaml_file_path)
Yunyun Linf87cc0a2022-06-08 16:57:04 -070089 yaml_data = yaml.safe_load(f)
George Keishingae7c8202017-02-09 10:33:45 -060090 f.close()
Patrick Williams20f38712022-12-08 06:18:26 -060091 for item in range(0, len(yaml_data["properties"])):
92 tmp_data = yaml_data["properties"][item]["name"]
George Keishing1eab8832020-07-09 06:30:57 -050093 inventory_dict[str(inventory_items[inv_index])].append(tmp_data)
George Keishingae7c8202017-02-09 10:33:45 -060094
95# Pretty print json formatter
Patrick Williams20f38712022-12-08 06:18:26 -060096data = json.dumps(
97 inventory_dict,
98 indent=4,
99 sort_keys=True,
100 default=str,
101 separators=(",", ":"),
102)
George Keishingae7c8202017-02-09 10:33:45 -0600103
104# Check if there is mismatch in data vs expect list
105if len(inventory_dict) != len(inventory_items):
George Keishing178d9bf2020-07-09 08:29:29 -0500106 print_error("The generated list doesn't match Inventory List.\n")
Patrick Williamsa57fef42022-12-03 07:00:14 -0600107 print(data)
George Keishingae7c8202017-02-09 10:33:45 -0600108 print_var(inventory_items)
109 sys.exit()
110
111# Write dictionary data to inventory file
Patrick Williamsa57fef42022-12-03 07:00:14 -0600112print("\nGenerated Inventory item json format\n")
113print(data)
Patrick Williams20f38712022-12-08 06:18:26 -0600114out = open(fru_inventory_file_path, "w")
115out.write("inventory_dict = ")
George Keishingae7c8202017-02-09 10:33:45 -0600116out.write(data)
117
118out.close()
Patrick Williamsa57fef42022-12-03 07:00:14 -0600119print("\nGenerated Inventory File: %s " % fru_inventory_file_path)