diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-08-28 17:34:53 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-08-30 02:22:38 +0000 |
commit | f1470e9b1add411c2ad3d87b7bf6a61329859b18 (patch) | |
tree | f7de5407435c3edf7d9b6534d45e06be0591b5a5 | |
parent | c47c6a6b8f08912b07990511ca362e26cdaebc80 (diff) | |
download | talos-skeleton-f1470e9b1add411c2ad3d87b7bf6a61329859b18.tar.gz talos-skeleton-f1470e9b1add411c2ad3d87b7bf6a61329859b18.zip |
SyncInventory: Move to the xyz namespace for property mac
Change-Id: I1db7b44d8fdff7876af83c8fb24fc77b5c7c61b7
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rw-r--r-- | pyinventorymgr/sync_inventory_items.py | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/pyinventorymgr/sync_inventory_items.py b/pyinventorymgr/sync_inventory_items.py index 5fcca42..b00ef5c 100644 --- a/pyinventorymgr/sync_inventory_items.py +++ b/pyinventorymgr/sync_inventory_items.py @@ -32,6 +32,9 @@ 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' +NETWORK_ROOT = '/xyz/openbmc_project/network' +ETHERNET_INTF_NAME = 'xyz.openbmc_project.Network.EthernetInterface' +MAC_INTF_NAME = 'xyz.openbmc_project.Network.MACAddress' FRUS = {} @@ -68,6 +71,25 @@ def get_bmc_mac_address(bus, prop): mproxy = obj.get_dbus_method('Get', PROP_INTF_NAME) return mproxy(INV_INTF_NAME, prop) +# Get Network Interface object. +def get_network_interface_object(bus): + mapper = obmc.mapper.Mapper(bus) + + # Get the network subtree, limited + # to objects that implements EthernetInterface. + for path, info in \ + mapper.get_subtree( + path=NETWORK_ROOT, + interfaces=[ETHERNET_INTF_NAME]).iteritems(): + + # Find the one which is having physical interface,it may happen + # that vlan interface is there and we want the physical + # interface here. + if path.split('/')[-1].find('_') < 0: + service = info.keys()[0] + net_obj = bus.get_object(service, path) + return net_obj + # Get inventory UUID value. def get_uuid(bus, prop): @@ -106,7 +128,6 @@ def get_sys_mac(obj): except: # Handle when mac does not exist in u-boot return sys_mac - sys_mac = sys_mac.replace(":", "") return sys_mac @@ -116,17 +137,15 @@ def get_sys_mac(obj): def sync_mac(obj, inv_mac, sys_mac): if sys_mac: # Convert sys MAC to int to perform bitwise '&' + sys_mac = sys_mac.replace(":", "") int_sys_mac = int(sys_mac, 16) else: # Set mac to 0 for when u-boot mac is not present int_sys_mac = 0 if not int_sys_mac & MAC_LOCALLY_ADMIN_MASK: # Sys MAC is not locally administered, go replace it with inv value - # Add the ':' separators - mac_str = ':'.join([inv_mac[i]+inv_mac[i+1] for i in range(0, 12, 2)]) - # The Set HW Method already has checking for mac format - dbus_method = obj.get_dbus_method("SetHwAddress", NET_DBUS_NAME) - dbus_method("eth0", mac_str) + intf = dbus.Interface(obj, dbus.PROPERTIES_IFACE) + intf.Set(MAC_INTF_NAME, "MACAddress", inv_mac) # Set sys uuid, this reboots the BMC for the value to take effect @@ -151,12 +170,17 @@ if __name__ == '__main__': bus = dbus.SystemBus() if sync_type == "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) + inv_mac = get_bmc_mac_address(bus, prop_name) + if not inv_mac: + sys.exit(1) + net_obj = get_network_interface_object(bus) + if not net_obj: + print "Unable to get the network object" + sys.exit(1) + sys_mac = get_sys_mac(net_obj) + if inv_mac != sys_mac: + print "Inventory MAC=%s,System MAC=%s" % (inv_mac, sys_mac) + sync_mac(net_obj, inv_mac, sys_mac) elif sync_type == "uuid": inv_uuid = get_uuid(bus, prop_name) if inv_uuid: |