'Processes and validates requested networks for allocation.
Iterates over the list of NetworkRequest objects, validating the
request and building sets of ports, networks and MAC addresses to
use for allocating ports for the instance.
:param instance: allocate networks on this instance
:type instance: nova.objects.Instance
:param neutron: neutron client session
:type neutron: neutronclient.v2_0.client.Client
:returns: tuple of:
- ports: dict mapping of port id to port dict
- ordered_networks: list of nova.objects.NetworkRequest objects
for requested networks (either via explicit network request
or the network for an explicit port request)
:raises nova.exception.PortNotFound: If a requested port is not found
in Neutron.
:raises nova.exception.PortNotUsable: If a requested port is not owned
by the same tenant that the instance is created under.
:raises nova.exception.PortInUse: If a requested port is already
attached to another instance.
:raises nova.exception.PortNotUsableDNS: If a requested port has a
value assigned to its dns_name attribute.'

def _validate_requested_port_ids(self, context, instance, neutron, requested_networks):

    ports = {}
    ordered_networks = []
    if (requested_networks and (not requested_networks.auto_allocate)):
        for request in requested_networks:
            if request.port_id:
                port = self._show_port(context, request.port_id, neutron_client=neutron)
                if (port['tenant_id'] != instance.project_id):
                    raise exception.PortNotUsable(port_id=request.port_id, instance=instance.uuid)
                if port.get('device_id'):
                    raise exception.PortInUse(port_id=request.port_id)
                if port.get('dns_name'):
                    if (port['dns_name'] != instance.hostname):
                        raise exception.PortNotUsableDNS(port_id=request.port_id, instance=instance.uuid, value=port['dns_name'], hostname=instance.hostname)
                _ensure_no_port_binding_failure(port)
                request.network_id = port['network_id']
                ports[request.port_id] = port
            if request.network_id:
                ordered_networks.append(request)
    return (ports, ordered_networks)
