'Return the subnets for a given port.'

def _get_subnets_from_port(self, context, port, client=None):

    fixed_ips = port['fixed_ips']
    if (not fixed_ips):
        return []
    if (not client):
        client = get_client(context)
    search_opts = {'id': [ip['subnet_id'] for ip in fixed_ips]}
    data = client.list_subnets(**search_opts)
    ipam_subnets = data.get('subnets', [])
    subnets = []
    for subnet in ipam_subnets:
        subnet_dict = {'cidr': subnet['cidr'], 'gateway': network_model.IP(address=subnet['gateway_ip'], type='gateway')}
        if subnet.get('ipv6_address_mode'):
            subnet_dict['ipv6_address_mode'] = subnet['ipv6_address_mode']
        search_opts = {'network_id': subnet['network_id'], 'device_owner': 'network:dhcp'}
        data = client.list_ports(**search_opts)
        dhcp_ports = data.get('ports', [])
        for p in dhcp_ports:
            for ip_pair in p['fixed_ips']:
                if (ip_pair['subnet_id'] == subnet['id']):
                    subnet_dict['dhcp_server'] = ip_pair['ip_address']
                    break
        subnet_object = network_model.Subnet(**subnet_dict)
        for dns in subnet.get('dns_nameservers', []):
            subnet_object.add_dns(network_model.IP(address=dns, type='dns'))
        for route in subnet.get('host_routes', []):
            subnet_object.add_route(network_model.Route(cidr=route['destination'], gateway=network_model.IP(address=route['nexthop'], type='gateway')))
        subnets.append(subnet_object)
    return subnets
