DMTF/python-redfish-library

Getting the each Network Adapters MAC addresses for Cisco UCS Servers

nagaphani23 opened this issue · 6 comments

Is there a method to identify the MAC address of the each Network adapter of the Cisco UCS server.
I was trying to automate PXE boot tasks and getting these MAC addresses is quite important.
I was not able to find a proper method to fetch the MAC address of each network adapter using redfish API.

Does anyone has any idea regarding this ?

I don't have access to a Cisco UCS server, but the basic idea is to just traverse the resources from the Chassis to the NetworkAdapters, etc. If that service follows the standard schemas, something like this should work:

import redfish


def main():
    context = redfish.redfish_client(base_url='https://contoso.com',
                                     username='...', password='...')
    context.login(auth="session")

    service_root = context.get("/redfish/v1/")
    if 'Chassis' not in service_root.dict:
        print('No Chassis found')
        return

    chassis_col = context.get(service_root.dict["Chassis"]["@odata.id"])
    for chassis_member in chassis_col.dict["Members"]:
        chassis = context.get(chassis_member["@odata.id"])
        print('Chassis: %s' % chassis.dict['Id'])
        if 'NetworkAdapters' in chassis.dict:
            na_col = context.get(chassis.dict['NetworkAdapters']["@odata.id"])
            for na_member in na_col.dict["Members"]:
                na_res = context.get(na_member["@odata.id"])
                print('  NetworkAdapter: %s' % na_res.dict['Id'])
                if 'NetworkDeviceFunctions' in na_res.dict:
                    ndf_col = context.get(na_res.dict['NetworkDeviceFunctions']['@odata.id'])
                    for ndf_member in ndf_col.dict["Members"]:
                        ndf_res = context.get(ndf_member["@odata.id"])
                        print('    NetworkDeviceFunction: %s' % ndf_res.dict['Id'])
                        if 'Ethernet' in ndf_res.dict:
                            if 'MACAddress' in ndf_res.dict['Ethernet']:
                                mac = ndf_res.dict['Ethernet']['MACAddress']
                                print('      MACAddress: %s' % mac)


if __name__ == "__main__":
    main()

I have already tried that and unfortunately i am getting nil under NetworkAdapters response.

{
"Members":[{
"@odata.id":"/redfish/v1/Chassis/1/NetworkAdapters/nil"
}]

Let me know in case if there's any other way to find this.

Is the service actually returning the URI /redfish/v1/Chassis/1/NetworkAdapters/nil? Can you open that URI in a browser?

This sounds like an issue with the implementation you're working with and may need to contact the vendor for support.

The other thing to consider is some implementations might only support the EthernetInterfaces resource for this, which would be found under the respective ComputerSystem resource.

@nagaphani23 do the previous responses answer your question? Can we close out this issue?

@mraineri I was not able to get the proper output with the above url. This might differ from specific vendor to vendor.
Anyways I am closing this now and will reopen in case if required.