diff options
author | Dinesh Chinari <chinari@us.ibm.com> | 2017-03-29 23:09:59 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-28 20:15:43 +0000 |
commit | c47c6a6b8f08912b07990511ca362e26cdaebc80 (patch) | |
tree | 6aa93ff9f3178c544e08422bb9f99f9b62b0aeb6 /pyinventorymgr | |
parent | a42400f24f94a69ef9effd3961b277ac52734652 (diff) | |
download | talos-skeleton-c47c6a6b8f08912b07990511ca362e26cdaebc80.tar.gz talos-skeleton-c47c6a6b8f08912b07990511ca362e26cdaebc80.zip |
U-boot script update with new inventory object
Updated new inventory objects in u-boot fw_env scripts.
Change-Id: I9545f29f603e2fc46424d44df45ca82379df5ecb
Signed-off-by: Dinesh Chinari <chinari@us.ibm.com>
Diffstat (limited to 'pyinventorymgr')
-rw-r--r-- | pyinventorymgr/sync_inventory_items.py | 131 |
1 files changed, 72 insertions, 59 deletions
diff --git a/pyinventorymgr/sync_inventory_items.py b/pyinventorymgr/sync_inventory_items.py index d92c3df..5fcca42 100644 --- a/pyinventorymgr/sync_inventory_items.py +++ b/pyinventorymgr/sync_inventory_items.py @@ -15,21 +15,23 @@ # See the License for the specific language governing permissions and # limitations under the License. - import sys import os import dbus +import uuid import argparse import subprocess +import obmc.mapper +import shutil - -INV_DBUS_NAME = 'org.openbmc.Inventory' -INV_INTF_NAME = 'org.openbmc.InventoryItem' +INV_INTF_NAME = 'xyz.openbmc_project.Inventory.Item.NetworkInterface' NET_DBUS_NAME = 'org.openbmc.NetworkManager' NET_OBJ_NAME = '/org/openbmc/NetworkManager/Interface' CHS_DBUS_NAME = 'org.openbmc.control.Chassis' +CHS_INTF_NAME = 'xyz.openbmc_project.Common.UUID' CHS_OBJ_NAME = '/org/openbmc/control/chassis0' PROP_INTF_NAME = 'org.freedesktop.DBus.Properties' +INVENTORY_ROOT = '/xyz/openbmc_project/inventory' FRUS = {} @@ -39,22 +41,61 @@ FRUS = {} MAC_LOCALLY_ADMIN_MASK = 0x20000000000 -# Get the inventory dbus path based on the requested fru -def get_inv_obj_path(fru_type, fru_name): - obj_path = '' - for f in FRUS.keys(): - import obmc.inventory - if (FRUS[f]['fru_type'] == fru_type and f.endswith(fru_name)): - obj_path = f.replace("<inventory_root>", obmc.inventory.INVENTORY_ROOT) - return obj_path +# Get inventory MACAddress value. +def get_bmc_mac_address(bus, prop): + mapper = obmc.mapper.Mapper(bus) + + # Get the inventory subtree, limited + # to objects that implement NetworkInterface. + for path, info in \ + mapper.get_subtree( + path=INVENTORY_ROOT, + interfaces=[INV_INTF_NAME]).iteritems(): + + # Find a NetworkInterface with 'bmc' in the path. + if 'bmc' not in path: + continue + + # Only expecting a single service to implement + # NetworkInterface. Get the service connection + # from the mapper response + conn = info.keys()[0] + # Get the inventory object implementing NetworkInterface. + obj = bus.get_object(conn, path) -# Get the inventory property value -def get_inv_value(obj, prop_name): - value = '' - dbus_method = obj.get_dbus_method("Get", PROP_INTF_NAME) - value = dbus_method(INV_INTF_NAME, prop_name) - return value + # Get the MAC address + mproxy = obj.get_dbus_method('Get', PROP_INTF_NAME) + return mproxy(INV_INTF_NAME, prop) + + +# Get inventory UUID value. +def get_uuid(bus, prop): + mapper = obmc.mapper.Mapper(bus) + + # Get the inventory subtree, limited + # to objects that implement UUID. + resp = mapper.get_subtree( + path=INVENTORY_ROOT, + interfaces=[CHS_INTF_NAME]) + + # Only expecting a single object to implement UUID. + try: + path, info = resp.items()[0] + except IndexError as e: + return None + + # Only expecting a single service to implement + # UUID. Get the service connection + # from the mapper response + conn = info.keys()[0] + + # Get the inventory object implementing UUID. + obj = bus.get_object(conn, path) + + # Get the uuid + mproxy = obj.get_dbus_method('Get', PROP_INTF_NAME) + return mproxy(CHS_INTF_NAME, prop) # Get the value of the mac on the system (from u-boot) without ':' separators @@ -88,14 +129,6 @@ def sync_mac(obj, inv_mac, sys_mac): dbus_method("eth0", mac_str) -# Get sys uuid -def get_sys_uuid(obj): - sys_uuid = '' - dbus_method = obj.get_dbus_method("Get", PROP_INTF_NAME) - sys_uuid = dbus_method(CHS_DBUS_NAME, "uuid") - return sys_uuid - - # Set sys uuid, this reboots the BMC for the value to take effect def set_sys_uuid(uuid): rc = subprocess.call(["fw_setenv", "uuid", uuid]) @@ -109,48 +142,28 @@ def set_sys_uuid(uuid): if __name__ == '__main__': arg = argparse.ArgumentParser() - arg.add_argument('-t') - arg.add_argument('-n') arg.add_argument('-p') arg.add_argument('-s') opt = arg.parse_args() - fru_type = opt.t - fru_name = opt.n prop_name = opt.p sync_type = opt.s - inventory = os.path.join( - sys.prefix, 'share', 'inventory', 'inventory.json') - if os.path.exists(inventory): - import json - with open(inventory, 'r') as f: - try: - inv = json.load(f) - except ValueError: - print "Invalid JSON detected in " + inventory - else: - FRUS = inv - else: - import obmc_system_config as System - FRUS = System.FRU_INSTANCES - bus = dbus.SystemBus() - inv_obj_path = get_inv_obj_path(fru_type, fru_name) - inv_obj = bus.get_object(INV_DBUS_NAME, inv_obj_path) - net_obj = bus.get_object(NET_DBUS_NAME, NET_OBJ_NAME) - chs_obj = bus.get_object(CHS_DBUS_NAME, CHS_OBJ_NAME) - - # Get the value of the requested inventory property - inv_value = get_inv_value(inv_obj, prop_name) - if sync_type == "mac": - sys_mac = get_sys_mac(net_obj) - if inv_value != sys_mac: - sync_mac(net_obj, inv_value, sys_mac) + inv_mac = get_bmc_mac_address(bus, prop_name) + if inv_mac: + net_obj = bus.get_object(NET_DBUS_NAME, NET_OBJ_NAME) + sys_mac = get_sys_mac(net_obj) + if inv_mac != sys_mac: + sync_mac(net_obj, inv_mac, sys_mac) elif sync_type == "uuid": - sys_uuid = get_sys_uuid(chs_obj) - if inv_value != sys_uuid: - set_sys_uuid(inv_value) + inv_uuid = get_uuid(bus, prop_name) + if inv_uuid: + inv_uuid = uuid.UUID(inv_uuid) + chs_obj = bus.get_object(CHS_DBUS_NAME, CHS_OBJ_NAME) + chs_uuid = get_sys_uuid(chs_obj) + if inv_uuid != sys_uuid: + set_sys_uuid(inv_uuid) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |