'Return list of ordered VIFs attached to instance.
:param context: Request context.
:param instance: Instance we are returning network info for.
:param networks: List of networks being attached to an instance.
If value is None this value will be populated
from the existing cached value.
:param port_ids: List of port_ids that are being attached to an
instance in order of attachment. If value is None
this value will be populated from the existing
cached value.
:param admin_client: A neutron client for the admin context.
:param preexisting_port_ids: List of port_ids that nova didn\'t
allocate and there shouldn\'t be deleted when
an instance is de-allocated. Supplied list will
be added to the cached list of preexisting port
IDs for this instance.'

def _build_network_info_model(self, context, instance, networks=None, port_ids=None, admin_client=None, preexisting_port_ids=None):

    search_opts = {'tenant_id': instance.project_id, 'device_id': instance.uuid}
    if (admin_client is None):
        client = get_client(context, admin=True)
    else:
        client = admin_client
    data = client.list_ports(**search_opts)
    current_neutron_ports = data.get('ports', [])
    nw_info_refresh = ((networks is None) and (port_ids is None))
    (networks, port_ids) = self._gather_port_ids_and_networks(context, instance, networks, port_ids, client)
    nw_info = network_model.NetworkInfo()
    if (preexisting_port_ids is None):
        preexisting_port_ids = []
    preexisting_port_ids = set((preexisting_port_ids + self._get_preexisting_port_ids(instance)))
    current_neutron_port_map = {}
    for current_neutron_port in current_neutron_ports:
        current_neutron_port_map[current_neutron_port['id']] = current_neutron_port
    for port_id in port_ids:
        current_neutron_port = current_neutron_port_map.get(port_id)
        if current_neutron_port:
            vif_active = False
            if ((current_neutron_port['admin_state_up'] is False) or (current_neutron_port['status'] == 'ACTIVE')):
                vif_active = True
            network_IPs = self._nw_info_get_ips(client, current_neutron_port)
            subnets = self._nw_info_get_subnets(context, current_neutron_port, network_IPs, client)
            devname = ('tap' + current_neutron_port['id'])
            devname = devname[:network_model.NIC_NAME_LEN]
            (network, ovs_interfaceid) = self._nw_info_build_network(current_neutron_port, networks, subnets)
            preserve_on_delete = (current_neutron_port['id'] in preexisting_port_ids)
            nw_info.append(network_model.VIF(id=current_neutron_port['id'], address=current_neutron_port['mac_address'], network=network, vnic_type=current_neutron_port.get('binding:vnic_type', network_model.VNIC_TYPE_NORMAL), type=current_neutron_port.get('binding:vif_type'), profile=current_neutron_port.get(BINDING_PROFILE), details=current_neutron_port.get('binding:vif_details'), ovs_interfaceid=ovs_interfaceid, devname=devname, active=vif_active, preserve_on_delete=preserve_on_delete))
        elif nw_info_refresh:
            LOG.info(_LI('Port    %s    from    network    info_cache    is    no    longer    associated    with    instance    in    Neutron.    Removing    from    network    info_cache.'), port_id, instance=instance)
    return nw_info
