def _create_domain_and_network(self, context, xml, instance, network_info, block_device_info=None, power_on=True, reboot=False, vifs_already_plugged=False):
    'Do required network setup and create domain.'
    block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
    for vol in block_device_mapping:
        connection_info = vol['connection_info']
        disk_info = blockinfo.get_info_from_bdm(CONF.libvirt.virt_type, vol)
        conf = self._connect_volume(connection_info, disk_info)
        if ('data' in connection_info):
            connection_info['data']['device_path'] = conf.source_path
            vol['connection_info'] = connection_info
            vol.save(context)
        if ((not reboot) and ('data' in connection_info) and ('volume_id' in connection_info['data'])):
            volume_id = connection_info['data']['volume_id']
            encryption = encryptors.get_encryption_metadata(context, self._volume_api, volume_id, connection_info)
            if encryption:
                encryptor = self._get_volume_encryptor(connection_info, encryption)
                encryptor.attach_volume(context, **encryption)
    timeout = CONF.vif_plugging_timeout
    if (self._conn_supports_start_paused and utils.is_neutron() and (not vifs_already_plugged) and power_on and timeout):
        events = self._get_neutron_events(network_info)
    else:
        events = []
    launch_flags = ((events and libvirt.VIR_DOMAIN_START_PAUSED) or 0)
    domain = None
    try:
        with self.virtapi.wait_for_instance_event(instance, events, deadline=timeout, error_callback=self._neutron_failed_callback):
            self.plug_vifs(instance, network_info)
            self.firewall_driver.setup_basic_filtering(instance, network_info)
            self.firewall_driver.prepare_instance_filter(instance, network_info)
            domain = self._create_domain(xml, instance=instance, launch_flags=launch_flags, power_on=power_on)
            self.firewall_driver.apply_instance_filter(instance, network_info)
    except exception.VirtualInterfaceCreateException:
        with excutils.save_and_reraise_exception():
            if domain:
                domain.destroy()
            self.cleanup(context, instance, network_info=network_info, block_device_info=block_device_info)
    except eventlet.timeout.Timeout:
        LOG.warn(_LW('Timeout waiting for vif plugging callback for instance %(uuid)s'), {'uuid': instance['uuid']})
        if CONF.vif_plugging_is_fatal:
            if domain:
                domain.destroy()
            self.cleanup(context, instance, network_info=network_info, block_device_info=block_device_info)
            raise exception.VirtualInterfaceCreateException()
    if (launch_flags & libvirt.VIR_DOMAIN_START_PAUSED):
        domain.resume()
    return domain
Do required network setup and create domain.
def _create_domain_and_network(self, context, xml, instance, network_info, block_device_info=None, power_on=True, reboot=False, vifs_already_plugged=False):
    
    block_device_mapping = driver.block_device_info_get_mapping(block_device_info)
    for vol in block_device_mapping:
        connection_info = vol['connection_info']
        disk_info = blockinfo.get_info_from_bdm(CONF.libvirt.virt_type, vol)
        conf = self._connect_volume(connection_info, disk_info)
        if ('data' in connection_info):
            connection_info['data']['device_path'] = conf.source_path
            vol['connection_info'] = connection_info
            vol.save(context)
        if ((not reboot) and ('data' in connection_info) and ('volume_id' in connection_info['data'])):
            volume_id = connection_info['data']['volume_id']
            encryption = encryptors.get_encryption_metadata(context, self._volume_api, volume_id, connection_info)
            if encryption:
                encryptor = self._get_volume_encryptor(connection_info, encryption)
                encryptor.attach_volume(context, **encryption)
    timeout = CONF.vif_plugging_timeout
    if (self._conn_supports_start_paused and utils.is_neutron() and (not vifs_already_plugged) and power_on and timeout):
        events = self._get_neutron_events(network_info)
    else:
        events = []
    launch_flags = ((events and libvirt.VIR_DOMAIN_START_PAUSED) or 0)
    domain = None
    try:
        with self.virtapi.wait_for_instance_event(instance, events, deadline=timeout, error_callback=self._neutron_failed_callback):
            self.plug_vifs(instance, network_info)
            self.firewall_driver.setup_basic_filtering(instance, network_info)
            self.firewall_driver.prepare_instance_filter(instance, network_info)
            domain = self._create_domain(xml, instance=instance, launch_flags=launch_flags, power_on=power_on)
            self.firewall_driver.apply_instance_filter(instance, network_info)
    except exception.VirtualInterfaceCreateException:
        with excutils.save_and_reraise_exception():
            if domain:
                domain.destroy()
            self.cleanup(context, instance, network_info=network_info, block_device_info=block_device_info)
    except eventlet.timeout.Timeout:
        LOG.warn(_LW('Timeout waiting for vif plugging callback for instance %(uuid)s'), {'uuid': instance['uuid']})
        if CONF.vif_plugging_is_fatal:
            if domain:
                domain.destroy()
            self.cleanup(context, instance, network_info=network_info, block_device_info=block_device_info)
            raise exception.VirtualInterfaceCreateException()
    if (launch_flags & libvirt.VIR_DOMAIN_START_PAUSED):
        domain.resume()
    return domain