'Allocate network resources for the instance.
:param context: The request context.
:param instance: nova.objects.instance.Instance object.
:param vpn: A boolean, ignored by this driver.
:param requested_networks: objects.NetworkRequestList object.
:param macs: None or a set of MAC addresses that the instance
should use. macs is supplied by the hypervisor driver (contrast
with requested_networks which is user supplied).
NB: NeutronV2 currently assigns hypervisor supplied MAC addresses
to arbitrary networks, which requires openflow switches to
function correctly if more than one network is being used with
the bare metal hypervisor (which is the only one known to limit
MAC addresses).
:param security_groups: None or security groups to allocate for
instance.
:param dhcp_options: None or a set of key/value pairs that should
determine the DHCP BOOTP response, eg. for PXE booting an instance
configured with the baremetal hypervisor. It is expected that these
are already formatted for the neutron v2 api.
See nova/virt/driver.py:dhcp_options_for_instance for an example.
:param bind_host_id: the host ID to attach to the ports being created.
:returns: network info as from get_instance_nw_info()'

def allocate_for_instance(self, context, instance, vpn, requested_networks, macs=None, security_groups=None, dhcp_options=None, bind_host_id=None):

    LOG.debug('allocate_for_instance()', instance=instance)
    if (not instance.project_id):
        msg = _('empty    project    id    for    instance    %s')
        raise exception.InvalidInput(reason=(msg % instance.uuid))
    neutron = get_client(context)
    (ports, ordered_networks) = self._validate_requested_port_ids(context, instance, neutron, requested_networks)
    nets = self._validate_requested_network_ids(context, instance, neutron, requested_networks, ordered_networks)
    if (not nets):
        LOG.debug('No    network    configured', instance=instance)
        return network_model.NetworkInfo([])
    security_groups = self._clean_security_groups(security_groups)
    security_group_ids = self._process_security_groups(instance, neutron, security_groups)
    requests_and_created_ports = self._create_ports_for_instance(context, instance, ordered_networks, nets, neutron, security_group_ids)
    available_macs = _filter_hypervisor_macs(instance, ports, macs)
    admin_client = get_client(context, admin=True)
    (ordered_nets, ordered_ports, preexisting_port_ids, created_port_ids) = self._update_ports_for_instance(context, instance, neutron, admin_client, requests_and_created_ports, nets, bind_host_id, dhcp_options, available_macs)
    nw_info = self.get_instance_nw_info(context, instance, networks=ordered_nets, port_ids=ordered_ports, admin_client=admin_client, preexisting_port_ids=preexisting_port_ids, update_cells=True)
    return network_model.NetworkInfo([vif for vif in nw_info if (vif['id'] in (created_port_ids + preexisting_port_ids))])
