import yaml


def get_dpdk_nics_mapping(module, dpdk_mapping_file, mac):
    """Gets the DPDK NIC's mapping with NIC physical name and
    driver info for the given MAC."""

    # Reads dpdk mapping file
    cmd = "cat " + dpdk_mapping_file
    result = module.run_command(cmd)
    if (not result or (result[0] != 0) or not (str(result[1]).strip(' '))):
        err = "Unable to determine DPDK NIC's details"
        module.fail_json(msg=err)
    else:
        dpdk_nics_map = yaml.load(str(result[1]), Loader=yaml.SafeLoader)
        for dpdk_nic_map in dpdk_nics_map:
            if dpdk_nic_map['mac_address'] == mac:
                return dpdk_nic_map
        else:
            err = ("Unable to determine DPDK NIC Mapping for MAC: '%(mac)s'" % {'mac': mac})
            module.fail_json(msg=err)