def get_by_name(yaml, ifname):
    """Returns the interface or sub-interface by a given name, or None,None if it does not exist"""
    if "." in ifname:
        try:
            phy_ifname, subid = ifname.split(".")
            subid = int(subid)
            iface = yaml["interfaces"][phy_ifname]["sub-interfaces"][subid]
            return ifname, iface
        except ValueError:
            return None, None
        except KeyError:
            return None, None

    try:
        iface = yaml["interfaces"][ifname]
        return ifname, iface
    except KeyError:
        pass
    return None, None