def create_snapshot(self, context, volume_id, snapshot):
    'Creates and exports the 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, volume_id)
    if vol_ref.bootable:
        try:
            self.db.volume_glance_metadata_copy_to_snapshot(context, snapshot.id, volume_id)
        except exception.GlanceMetadataNotFound:
            pass
        except exception.CinderException as ex:
            LOG.exception(_LE('Failed updating snapshot metadata using the provided volumes %(volume_id)s metadata'), {'volume_id': 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(_LI('Create snapshot completed successfully'), resource=snapshot)
    return snapshot.id
Creates and exports the snapshot.
def create_snapshot(self, context, volume_id, 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, volume_id)
    if vol_ref.bootable:
        try:
            self.db.volume_glance_metadata_copy_to_snapshot(context, snapshot.id, volume_id)
        except exception.GlanceMetadataNotFound:
            pass
        except exception.CinderException as ex:
            LOG.exception(_LE('Failed updating snapshot metadata using the provided volumes %(volume_id)s metadata'), {'volume_id': 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(_LI('Create snapshot completed successfully'), resource=snapshot)
    return snapshot.id