'Build the beginning of a new instance.'

def _populate_instance_for_create(self, context, instance, image, index, security_groups, instance_type, num_instances, shutdown_terminate):

    instance.launch_index = index
    instance.vm_state = vm_states.BUILDING
    instance.task_state = task_states.SCHEDULING
    info_cache = objects.InstanceInfoCache()
    info_cache.instance_uuid = instance.uuid
    info_cache.network_info = network_model.NetworkInfo()
    instance.info_cache = info_cache
    instance.flavor = instance_type
    instance.old_flavor = None
    instance.new_flavor = None
    if CONF.ephemeral_storage_encryption.enabled:
        cipher = CONF.ephemeral_storage_encryption.cipher
        algorithm = (cipher.split('-')[0] if cipher else None)
        instance.ephemeral_key_uuid = self.key_manager.create_key(context, algorithm=algorithm, length=CONF.ephemeral_storage_encryption.key_size)
    else:
        instance.ephemeral_key_uuid = None
    if (not instance.obj_attr_is_set('system_metadata')):
        instance.system_metadata = {}
    instance.system_metadata = utils.instance_sys_meta(instance)
    system_meta = utils.get_system_metadata_from_image(image, instance_type)
    system_meta.setdefault('image_base_image_ref', instance.image_ref)
    system_meta['owner_user_name'] = context.user_name
    system_meta['owner_project_name'] = context.project_name
    instance.system_metadata.update(system_meta)
    if CONF.use_neutron:
        instance.security_groups = objects.SecurityGroupList()
    else:
        instance.security_groups = security_groups
    self._populate_instance_names(instance, num_instances)
    instance.shutdown_terminate = shutdown_terminate
    if ((num_instances > 1) and (self.cell_type != 'api')):
        instance = self._apply_instance_name_template(context, instance, index)
    return instance
