import re


def extract_namenode(path):
    """
    extract namenode from URI
    Args:
        path(str): HDFS path or AFS path

    Returns:
        str: namenode of path

    >>>extract_namenode("hdfs://host:port/tmp")
    "hdfs://host:port"
    >>>extract_namenode("hdfs://fs/tmp")
    "hdfs://fs"
    >>>extract_namenode("hdfs:///tmp")
    "hdfs://"
    """
    match = re.match(r'((hdfs|afs)://[^/]*)/(.*)', path, re.M | re.I)
    return match.group(1) if match else None