'Creates and exports the snapshot.'

@objects.Snapshot.set_workers
def create_snapshot(self, context, snapshot):

    context = context.elevated()
    self._notify_about_snapshot_usage(context, snapshot, 'create.start')
    try:
        utils.require_driver_initialized(self.driver)
        snapshot.context = context
        model_update = self.driver.create_snapshot(snapshot)
        if model_update:
            snapshot.update(model_update)
            snapshot.save()
    except Exception:
        with excutils.save_and_reraise_exception():
            snapshot.status = fields.SnapshotStatus.ERROR
            snapshot.save()
    vol_ref = self.db.volume_get(context, snapshot.volume_id)
    if vol_ref.bootable:
        try:
            self.db.volume_glance_metadata_copy_to_snapshot(context, snapshot.id, snapshot.volume_id)
        except exception.GlanceMetadataNotFound:
            pass
        except exception.CinderException as ex:
            LOG.exception('Failed    updating    snapshot    metadata    using    the    provided    volumes    %(volume_id)s    metadata', {'volume_id': snapshot.volume_id}, resource=snapshot)
            snapshot.status = fields.SnapshotStatus.ERROR
            snapshot.save()
            raise exception.MetadataCopyFailure(reason=six.text_type(ex))
    snapshot.status = fields.SnapshotStatus.AVAILABLE
    snapshot.progress = '100%'
    snapshot.save()
    self._notify_about_snapshot_usage(context, snapshot, 'create.end')
    LOG.info('Create    snapshot    completed    successfully', resource=snapshot)
    return snapshot.id
