'Check requested networks using the Neutron API.
Check the user has access to the network they requested, and that
it is a suitable network to connect to. This includes getting the
network details for any ports that have been passed in, because the
request will have been updated with the network_id in
_validate_requested_port_ids.
If the user has not requested any ports or any networks, we get back
a full list of networks the user has access to, and if there is only
one network, we update ordered_networks so we will connect the
instance to that network.
:param context: The request context.
:param instance: nova.objects.instance.Instance object.
:param requested_networks: value containing
network_id, fixed_ip, and port_id
:param ordered_networks: output from _validate_requested_port_ids
that will be used to create and update ports'

def _validate_requested_network_ids(self, context, instance, neutron, requested_networks, ordered_networks):

    auto_allocate = (requested_networks and requested_networks.auto_allocate)
    net_ids = [request.network_id for request in ordered_networks]
    nets = self._get_available_networks(context, instance.project_id, net_ids, neutron=neutron, auto_allocate=auto_allocate)
    if (not nets):
        if requested_networks:
            if auto_allocate:
                nets = [self._auto_allocate_network(instance, neutron)]
            else:
                for request in requested_networks:
                    if ((not request.port_id) and request.network_id):
                        raise exception.NetworkNotFound(network_id=request.network_id)
        else:
            return {}
    if ((not requested_networks) or requested_networks.is_single_unspecified or requested_networks.auto_allocate):
        if (not nets):
            raise exception.InterfaceAttachFailedNoNetwork(project_id=instance.project_id)
        if (len(nets) > 1):
            msg = _('Multiple    possible    networks    found,    use    a    Network    ID    to    be    more    specific.')
            raise exception.NetworkAmbiguous(msg)
        ordered_networks.append(objects.NetworkRequest(network_id=nets[0]['id']))
    self._check_external_network_attach(context, nets)
    return {net['id']: net for net in nets}
