'Determine whether the metadata proxy is needed for a network
This method returns True for truly isolated networks (ie: not attached
to a router) when enable_isolated_metadata is True, or for all the
networks when the force_metadata flags is True.
This method also returns True when enable_metadata_network is True,
and the network passed as a parameter has a subnet in the link-local
CIDR, thus characterizing it as a "metadata" network. The metadata
network is used by solutions which do not leverage the l3 agent for
providing access to the metadata service via logical routers built
with 3rd party backends.'

@classmethod
def should_enable_metadata(cls, conf, network):

    all_subnets = cls._get_all_subnets(network)
    v4_dhcp_subnets = [s for s in all_subnets if ((s.ip_version == 4) and s.enable_dhcp)]
    if (not v4_dhcp_subnets):
        return False
    if conf.force_metadata:
        return True
    if (not conf.enable_isolated_metadata):
        return False
    if conf.enable_metadata_network:
        meta_cidr = netaddr.IPNetwork(METADATA_DEFAULT_CIDR)
        if any(((netaddr.IPNetwork(s.cidr) in meta_cidr) for s in all_subnets)):
            return True
    isolated_subnets = cls.get_isolated_subnets(network)
    return any((isolated_subnets[s.id] for s in v4_dhcp_subnets))
