1e7e9171eSGeorge Keishing#!/usr/bin/env python3 2ae7c820fSGeorge Keishingr""" 3ae7c820fSGeorge KeishingGenerate an inventory variable file containing a list of properties 4ae7c820fSGeorge Keishingfields from the YAML phosphor-dbus-interfaces repository. 5ae7c820fSGeorge Keishing""" 6e635ddc0SGeorge Keishingimport sys 7e635ddc0SGeorge Keishingimport os 8e635ddc0SGeorge Keishingimport yaml 9e635ddc0SGeorge Keishingimport json 10e635ddc0SGeorge Keishing 11ae7c820fSGeorge Keishinglib_path = sys.path[0] + "/../lib" 12ae7c820fSGeorge Keishingsys.path.insert(0, lib_path) 13*09679890SGeorge Keishingfrom gen_print import * # NOQA 14ae7c820fSGeorge Keishing 15ae7c820fSGeorge Keishing# This list will be longer when more development codes are available. 16e635ddc0SGeorge Keishinginventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu'] 17ae7c820fSGeorge Keishingprint_var(inventory_items) 18e635ddc0SGeorge Keishingfru_inventory_file_path = 'inventory.py' 19ae7c820fSGeorge Keishingprint_var(fru_inventory_file_path) 20ae7c820fSGeorge Keishing 211eab8838SGeorge Keishing# Properties inventory list 221eab8838SGeorge Keishingyaml_inventory_list = [] 23ae7c820fSGeorge Keishing 24ae7c820fSGeorge Keishing# Clone the phosphor-dbus-interfaces repository 25e635ddc0SGeorge Keishingcmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces' 26ae7c820fSGeorge Keishingos.system(cmd_buf) 27ae7c820fSGeorge Keishing 28e635ddc0SGeorge Keishingrepo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/' 29ae7c820fSGeorge Keishingbase_dir_path = os.getcwd() + repo_subdir_path 30ae7c820fSGeorge Keishing 319ef1fd47SGeorge Keishing# yaml file paths for FRU 32e635ddc0SGeorge Keishingyaml_fru_list = ['Inventory/Item.interface.yaml', 33e635ddc0SGeorge Keishing 'Inventory/Decorator/Asset.interface.yaml', 34e635ddc0SGeorge Keishing 'Inventory/Decorator/Revision.interface.yaml', 35e635ddc0SGeorge Keishing 'Inventory/Decorator/Replaceable.interface.yaml', 36e635ddc0SGeorge Keishing 'Inventory/Decorator/Cacheable.interface.yaml', 37e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 38ae7c820fSGeorge Keishing 391da4c24dSSweta Potthuri# yaml file paths for CORE. 40e635ddc0SGeorge Keishingyaml_core_list = ['Inventory/Item.interface.yaml', 41e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 42dc68eff6SGeorge Keishing 43dc68eff6SGeorge Keishing# yaml file paths for fan. 44e635ddc0SGeorge Keishingyaml_fan_list = ['Inventory/Item.interface.yaml', 45e635ddc0SGeorge Keishing 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', 46e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 475c006d39SSteven Sombar 485c006d39SSteven Sombar# yaml file paths for fan_wc (fans in water-cooled system). 49e635ddc0SGeorge Keishingyaml_fan_wc_list = ['Inventory/Item.interface.yaml', 50e635ddc0SGeorge Keishing 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', ] 515c006d39SSteven Sombar 5219305205SGeorge Keishing# yaml file paths for GPU. 53e635ddc0SGeorge Keishingyaml_gpu_list = ['Inventory/Item.interface.yaml', 54e635ddc0SGeorge Keishing 'Inventory/Decorator/Replaceable.interface.yaml', 55e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 565c006d39SSteven Sombar 571eab8838SGeorge Keishing# Append to inventory list 581eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fru_list) 591eab8838SGeorge Keishingyaml_inventory_list.append(yaml_core_list) 601eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fan_list) 611eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fan_wc_list) 621eab8838SGeorge Keishingyaml_inventory_list.append(yaml_gpu_list) 63ae7c820fSGeorge Keishing 641eab8838SGeorge Keishingprint_var(yaml_inventory_list) 659ef1fd47SGeorge Keishing 66ae7c820fSGeorge Keishing# Populate Inventory data 67ae7c820fSGeorge Keishinginventory_dict = {} 68ae7c820fSGeorge Keishing 691eab8838SGeorge Keishingfor inv_index in range(len(yaml_inventory_list)): 701eab8838SGeorge Keishing print_var(inv_index) 711eab8838SGeorge Keishing inventory_dict[str(inventory_items[inv_index])] = [] 721eab8838SGeorge Keishing for rel_yaml_file_path in yaml_inventory_list[inv_index]: 739ef1fd47SGeorge Keishing yaml_file_path = base_dir_path + rel_yaml_file_path 74ae7c820fSGeorge Keishing 75ae7c820fSGeorge Keishing # Get the yaml dictionary data 769ef1fd47SGeorge Keishing print_timen("Loading " + yaml_file_path) 779ef1fd47SGeorge Keishing f = open(yaml_file_path) 78f87cc0afSYunyun Lin yaml_data = yaml.safe_load(f) 79ae7c820fSGeorge Keishing f.close() 80e635ddc0SGeorge Keishing for item in range(0, len(yaml_data['properties'])): 81e635ddc0SGeorge Keishing tmp_data = yaml_data['properties'][item]['name'] 821eab8838SGeorge Keishing inventory_dict[str(inventory_items[inv_index])].append(tmp_data) 83ae7c820fSGeorge Keishing 84ae7c820fSGeorge Keishing# Pretty print json formatter 85e635ddc0SGeorge Keishingdata = json.dumps(inventory_dict, 869ef1fd47SGeorge Keishing indent=4, 879ef1fd47SGeorge Keishing sort_keys=True, 889ef1fd47SGeorge Keishing default=str, 89e635ddc0SGeorge Keishing separators=(',', ':')) 90ae7c820fSGeorge Keishing 91ae7c820fSGeorge Keishing# Check if there is mismatch in data vs expect list 92ae7c820fSGeorge Keishingif len(inventory_dict) != len(inventory_items): 93178d9bf2SGeorge Keishing print_error("The generated list doesn't match Inventory List.\n") 9432c4c9e4SGeorge Keishing print(data) 95ae7c820fSGeorge Keishing print_var(inventory_items) 96ae7c820fSGeorge Keishing sys.exit() 97ae7c820fSGeorge Keishing 98ae7c820fSGeorge Keishing# Write dictionary data to inventory file 9932c4c9e4SGeorge Keishingprint("\nGenerated Inventory item json format\n") 10032c4c9e4SGeorge Keishingprint(data) 101e635ddc0SGeorge Keishingout = open(fru_inventory_file_path, 'w') 102e635ddc0SGeorge Keishingout.write('inventory_dict = ') 103ae7c820fSGeorge Keishingout.write(data) 104ae7c820fSGeorge Keishing 105ae7c820fSGeorge Keishingout.close() 10632c4c9e4SGeorge Keishingprint("\nGenerated Inventory File: %s " % fru_inventory_file_path) 107