def node_url_sort_key(node_url):
    """
    >>> node_url_sort_key("m3-2.grenoble.iot-lab.info")
    ('grenoble', 'm3', 2)

    >>> node_url_sort_key("3")  # for alias nodes
    3

    >>> node_url_sort_key("a8-2.grenoble.iot-lab.info")
    ('grenoble', 'a8', 2)
    >>> node_url_sort_key("node-a8-2.grenoble.iot-lab.info")
    ('grenoble', 'node-a8', 2)

    # Also support incomplete urls
    >>> node_url_sort_key("m3-2")
    ('', 'm3', 2)
    >>> node_url_sort_key("node-a8-2")
    ('', 'node-a8', 2)

    """
    if node_url.isdigit():
        return int(node_url)
    _node, _, domain = node_url.partition('.')
    site = domain.split('.')[0]
    node_type, num_str = _node.rsplit('-', 1)
    return site, node_type, int(num_str)
