'Ensure all provided build_requests and instances end up in cell0.
Cell0 is the fake cell we schedule dead instances to when we can\'t
schedule them somewhere real. Requests that don\'t yet have instances
will get a new instance, created in cell0. Instances that have not yet
been created will be created in cell0. All build requests are destroyed
after we\'re done. Failure to delete a build request will trigger the
instance deletion, just like the happy path in
schedule_and_build_instances() below.'

def _bury_in_cell0(self, context, request_spec, exc, build_requests=None, instances=None):

    try:
        cell0 = objects.CellMapping.get_by_uuid(context, objects.CellMapping.CELL0_UUID)
    except exception.CellMappingNotFound:
        LOG.error('No    cell    mapping    found    for    cell0    while    trying    to    record    scheduling    failure.    Setup    is    incomplete.')
        return
    build_requests = (build_requests or [])
    instances = (instances or [])
    instances_by_uuid = {inst.uuid: inst for inst in instances}
    for build_request in build_requests:
        if (build_request.instance_uuid not in instances_by_uuid):
            instance = build_request.get_new_instance(context)
            instances_by_uuid[instance.uuid] = instance
    updates = {'vm_state': vm_states.ERROR, 'task_state': None}
    legacy_spec = request_spec.to_legacy_request_spec_dict()
    for instance in instances_by_uuid.values():
        with obj_target_cell(instance, cell0) as cctxt:
            instance.create()
            self._set_vm_state_and_notify(cctxt, instance.uuid, 'build_instances', updates, exc, legacy_spec)
            try:
                inst_mapping = objects.InstanceMapping.get_by_instance_uuid(context, instance.uuid)
                inst_mapping.cell_mapping = cell0
                inst_mapping.save()
            except exception.InstanceMappingNotFound:
                pass
    for build_request in build_requests:
        try:
            build_request.destroy()
        except exception.BuildRequestNotFound:
            inst = instances_by_uuid[build_request.instance_uuid]
            with obj_target_cell(inst, cell0):
                inst.destroy()
