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""" 647375aa7SSridevi Ramesh 75731818dSPatrick Williamsfrom gen_print import * 8ae7c820fSGeorge Keishing 9*e635ddc0SGeorge Keishingimport sys 10*e635ddc0SGeorge Keishingimport os 11*e635ddc0SGeorge Keishingimport yaml 12*e635ddc0SGeorge Keishingimport json 13*e635ddc0SGeorge Keishing 14ae7c820fSGeorge Keishinglib_path = sys.path[0] + "/../lib" 15ae7c820fSGeorge Keishingsys.path.insert(0, lib_path) 16ae7c820fSGeorge Keishing 17ae7c820fSGeorge Keishing# This list will be longer when more development codes are available. 18*e635ddc0SGeorge Keishinginventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu'] 19ae7c820fSGeorge Keishingprint_var(inventory_items) 20*e635ddc0SGeorge Keishingfru_inventory_file_path = 'inventory.py' 21ae7c820fSGeorge Keishingprint_var(fru_inventory_file_path) 22ae7c820fSGeorge Keishing 231eab8838SGeorge Keishing# Properties inventory list 241eab8838SGeorge Keishingyaml_inventory_list = [] 25ae7c820fSGeorge Keishing 26ae7c820fSGeorge Keishing# Clone the phosphor-dbus-interfaces repository 27*e635ddc0SGeorge Keishingcmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces' 28ae7c820fSGeorge Keishingos.system(cmd_buf) 29ae7c820fSGeorge Keishing 30*e635ddc0SGeorge Keishingrepo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/' 31ae7c820fSGeorge Keishingbase_dir_path = os.getcwd() + repo_subdir_path 32ae7c820fSGeorge Keishing 339ef1fd47SGeorge Keishing# yaml file paths for FRU 34*e635ddc0SGeorge Keishingyaml_fru_list = ['Inventory/Item.interface.yaml', 35*e635ddc0SGeorge Keishing 'Inventory/Decorator/Asset.interface.yaml', 36*e635ddc0SGeorge Keishing 'Inventory/Decorator/Revision.interface.yaml', 37*e635ddc0SGeorge Keishing 'Inventory/Decorator/Replaceable.interface.yaml', 38*e635ddc0SGeorge Keishing 'Inventory/Decorator/Cacheable.interface.yaml', 39*e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 40ae7c820fSGeorge Keishing 411da4c24dSSweta Potthuri# yaml file paths for CORE. 42*e635ddc0SGeorge Keishingyaml_core_list = ['Inventory/Item.interface.yaml', 43*e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 44dc68eff6SGeorge Keishing 45dc68eff6SGeorge Keishing# yaml file paths for fan. 46*e635ddc0SGeorge Keishingyaml_fan_list = ['Inventory/Item.interface.yaml', 47*e635ddc0SGeorge Keishing 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', 48*e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 495c006d39SSteven Sombar 505c006d39SSteven Sombar# yaml file paths for fan_wc (fans in water-cooled system). 51*e635ddc0SGeorge Keishingyaml_fan_wc_list = ['Inventory/Item.interface.yaml', 52*e635ddc0SGeorge Keishing 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', ] 535c006d39SSteven Sombar 5419305205SGeorge Keishing# yaml file paths for GPU. 55*e635ddc0SGeorge Keishingyaml_gpu_list = ['Inventory/Item.interface.yaml', 56*e635ddc0SGeorge Keishing 'Inventory/Decorator/Replaceable.interface.yaml', 57*e635ddc0SGeorge Keishing 'State/Decorator/OperationalStatus.interface.yaml', ] 585c006d39SSteven Sombar 591eab8838SGeorge Keishing# Append to inventory list 601eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fru_list) 611eab8838SGeorge Keishingyaml_inventory_list.append(yaml_core_list) 621eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fan_list) 631eab8838SGeorge Keishingyaml_inventory_list.append(yaml_fan_wc_list) 641eab8838SGeorge Keishingyaml_inventory_list.append(yaml_gpu_list) 65ae7c820fSGeorge Keishing 661eab8838SGeorge Keishingprint_var(yaml_inventory_list) 679ef1fd47SGeorge Keishing 68ae7c820fSGeorge Keishing# Populate Inventory data 69ae7c820fSGeorge Keishinginventory_dict = {} 70ae7c820fSGeorge Keishing 711eab8838SGeorge Keishingfor inv_index in range(len(yaml_inventory_list)): 721eab8838SGeorge Keishing print_var(inv_index) 731eab8838SGeorge Keishing inventory_dict[str(inventory_items[inv_index])] = [] 741eab8838SGeorge Keishing for rel_yaml_file_path in yaml_inventory_list[inv_index]: 759ef1fd47SGeorge Keishing yaml_file_path = base_dir_path + rel_yaml_file_path 76ae7c820fSGeorge Keishing 77ae7c820fSGeorge Keishing # Get the yaml dictionary data 789ef1fd47SGeorge Keishing print_timen("Loading " + yaml_file_path) 799ef1fd47SGeorge Keishing f = open(yaml_file_path) 80f87cc0afSYunyun Lin yaml_data = yaml.safe_load(f) 81ae7c820fSGeorge Keishing f.close() 82*e635ddc0SGeorge Keishing for item in range(0, len(yaml_data['properties'])): 83*e635ddc0SGeorge Keishing tmp_data = yaml_data['properties'][item]['name'] 841eab8838SGeorge Keishing inventory_dict[str(inventory_items[inv_index])].append(tmp_data) 85ae7c820fSGeorge Keishing 86ae7c820fSGeorge Keishing# Pretty print json formatter 87*e635ddc0SGeorge Keishingdata = json.dumps(inventory_dict, 889ef1fd47SGeorge Keishing indent=4, 899ef1fd47SGeorge Keishing sort_keys=True, 909ef1fd47SGeorge Keishing default=str, 91*e635ddc0SGeorge Keishing separators=(',', ':')) 92ae7c820fSGeorge Keishing 93ae7c820fSGeorge Keishing# Check if there is mismatch in data vs expect list 94ae7c820fSGeorge Keishingif len(inventory_dict) != len(inventory_items): 95178d9bf2SGeorge Keishing print_error("The generated list doesn't match Inventory List.\n") 9632c4c9e4SGeorge Keishing print(data) 97ae7c820fSGeorge Keishing print_var(inventory_items) 98ae7c820fSGeorge Keishing sys.exit() 99ae7c820fSGeorge Keishing 100ae7c820fSGeorge Keishing# Write dictionary data to inventory file 10132c4c9e4SGeorge Keishingprint("\nGenerated Inventory item json format\n") 10232c4c9e4SGeorge Keishingprint(data) 103*e635ddc0SGeorge Keishingout = open(fru_inventory_file_path, 'w') 104*e635ddc0SGeorge Keishingout.write('inventory_dict = ') 105ae7c820fSGeorge Keishingout.write(data) 106ae7c820fSGeorge Keishing 107ae7c820fSGeorge Keishingout.close() 10832c4c9e4SGeorge Keishingprint("\nGenerated Inventory File: %s " % fru_inventory_file_path) 109