'Check if segment can be bound for agent.
:param segment: segment dictionary describing segment to bind
:param agent: agents_db entry describing agent to bind
:returns: True iff segment can be bound for agent
Called outside any transaction during bind_port so that derived
MechanismDrivers can use agent_db data along with built-in
knowledge of the corresponding agent\'s capabilities to
determine whether or not the specified network segment can be
bound for the agent.'

def check_segment_for_agent(self, segment, agent):

    mappings = self.get_mappings(agent)
    allowed_network_types = self.get_allowed_network_types(agent)
    LOG.debug('Checking    segment:    %(segment)s    for    mappings:    %(mappings)s    with    network    types:    %(network_types)s', {'segment': segment, 'mappings': mappings, 'network_types': allowed_network_types})
    network_type = segment[api.NETWORK_TYPE]
    if (network_type not in allowed_network_types):
        LOG.debug('Network    %(network_id)s    with    segment    %(id)s    is    type    of    %(network_type)s    but    agent    %(agent)s    or    mechanism    driver    only    support    %(allowed_network_types)s.', {'network_id': segment['network_id'], 'id': segment['id'], 'network_type': network_type, 'agent': agent['host'], 'allowed_network_types': allowed_network_types})
        return False
    if (network_type in [p_constants.TYPE_FLAT, p_constants.TYPE_VLAN]):
        physnet = segment[api.PHYSICAL_NETWORK]
        if (not self.physnet_in_mappings(physnet, mappings)):
            LOG.debug('Network    %(network_id)s    with    segment    %(id)s    is    connected    to    physical    network    %(physnet)s,    but    agent    %(agent)s    reported    physical    networks    %(mappings)s.    The    physical    network    must    be    configured    on    the    agent    if    binding    is    to    succeed.', {'network_id': segment['network_id'], 'id': segment['id'], 'physnet': physnet, 'agent': agent['host'], 'mappings': mappings})
            return False
    return True
