'Deploy an instance.
:param context: The security context.
:param instance: The instance object.
:param image_meta: Image dict returned by nova.image.glance
that defines the image from which to boot this instance.
:param injected_files: User files to inject into instance.
:param admin_password: Administrator password to set in
instance.
:param network_info: Instance network information.
:param block_device_info: Instance block device
information.'

def spawn(self, context, instance, image_meta, injected_files, admin_password, network_info=None, block_device_info=None):

    LOG.debug('Spawn    called    for    instance', instance=instance)
    node_uuid = instance.get('node')
    if (not node_uuid):
        raise ironic.exc.BadRequest((_('Ironic    node    uuid    not    supplied    to    driver    for    instance    %s.') % instance.uuid))
    node = self._get_node(node_uuid)
    flavor = instance.flavor
    self._add_instance_info_to_node(node, instance, image_meta, flavor, block_device_info=block_device_info)
    try:
        self._add_volume_target_info(context, instance, block_device_info)
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error('Error    preparing    deploy    for    instance    on    baremetal    node    %(node)s.', {'node': node_uuid}, instance=instance)
            self._cleanup_deploy(node, instance, network_info)
    if flavor.ephemeral_gb:
        instance.default_ephemeral_device = '/dev/sda1'
        instance.save()
    validate_chk = self.ironicclient.call('node.validate', node_uuid)
    if ((not validate_chk.deploy.get('result')) or (not validate_chk.power.get('result')) or (not validate_chk.storage.get('result'))):
        self._cleanup_deploy(node, instance, network_info)
        raise exception.ValidationError((_('Ironic    node:    %(id)s    failed    to    validate.    (deploy:    %(deploy)s,    power:    %(power)s,    storage:    %(storage)s)') % {'id': node.uuid, 'deploy': validate_chk.deploy, 'power': validate_chk.power, 'storage': validate_chk.storage}))
    try:
        self._plug_vifs(node, instance, network_info)
        self._start_firewall(instance, network_info)
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error('Error    preparing    deploy    for    instance    %(instance)s    on    baremetal    node    %(node)s.', {'instance': instance.uuid, 'node': node_uuid})
            self._cleanup_deploy(node, instance, network_info)
    configdrive_value = None
    if configdrive.required_by(instance):
        extra_md = {}
        if admin_password:
            extra_md['admin_pass'] = admin_password
        try:
            configdrive_value = self._generate_configdrive(context, instance, node, network_info, extra_md=extra_md, files=injected_files)
        except Exception as e:
            with excutils.save_and_reraise_exception():
                msg = ('Failed    to    build    configdrive:    %s' % six.text_type(e))
                LOG.error(msg, instance=instance)
                self._cleanup_deploy(node, instance, network_info)
        LOG.info('Config    drive    for    instance    %(instance)s    on    baremetal    node    %(node)s    created.', {'instance': instance['uuid'], 'node': node_uuid})
    try:
        self.ironicclient.call('node.set_provision_state', node_uuid, ironic_states.ACTIVE, configdrive=configdrive_value)
    except Exception as e:
        with excutils.save_and_reraise_exception():
            LOG.error('Failed    to    request    Ironic    to    provision    instance    %(inst)s:    %(reason)s', {'inst': instance.uuid, 'reason': six.text_type(e)})
            self._cleanup_deploy(node, instance, network_info)
    timer = loopingcall.FixedIntervalLoopingCall(self._wait_for_active, instance)
    try:
        timer.start(interval=CONF.ironic.api_retry_interval).wait()
        LOG.info('Successfully    provisioned    Ironic    node    %s', node.uuid, instance=instance)
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error('Error    deploying    instance    %(instance)s    on    baremetal    node    %(node)s.', {'instance': instance.uuid, 'node': node_uuid})
