def create_cgsnapshot(self, context, cgsnapshot):
    'Creates the cgsnapshot.'
    caller_context = context
    context = context.elevated()
    LOG.info(_LI('Cgsnapshot %s: creating.'), cgsnapshot.id)
    snapshots = objects.SnapshotList.get_all_for_cgsnapshot(context, cgsnapshot.id)
    self._notify_about_cgsnapshot_usage(context, cgsnapshot, 'create.start')
    snapshots_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        LOG.debug('Cgsnapshot %(cgsnap_id)s: creating.', {'cgsnap_id': cgsnapshot.id})
        cgsnapshot.context = caller_context
        for snapshot in snapshots:
            snapshot.context = caller_context
        (model_update, snapshots_model_update) = self.driver.create_cgsnapshot(context, cgsnapshot, snapshots)
        if snapshots_model_update:
            for snap_model in snapshots_model_update:
                self.db.snapshot_update(context, snap_model['id'], snap_model)
                if ((snap_model['status'] in [fields.SnapshotStatus.ERROR_DELETING, fields.SnapshotStatus.ERROR]) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = snap_model['status']
        if model_update:
            if (model_update['status'] == 'error'):
                msg = (_('Error occurred when creating cgsnapshot %s.') % cgsnapshot.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            cgsnapshot.update(model_update)
            cgsnapshot.save()
    except exception.CinderException:
        with excutils.save_and_reraise_exception():
            cgsnapshot.status = 'error'
            cgsnapshot.save()
            if (not snapshots_model_update):
                for snapshot in snapshots:
                    snapshot.status = fields.SnapshotStatus.ERROR
                    snapshot.save()
    for snapshot in snapshots:
        volume_id = snapshot['volume_id']
        snapshot_id = snapshot['id']
        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.CinderException as ex:
                LOG.error(_LE('Failed updating %(snapshot_id)s metadata using the provided volumes %(volume_id)s metadata'), {'volume_id': volume_id, 'snapshot_id': snapshot_id})
                self.db.snapshot_update(context, snapshot_id, {'status': fields.SnapshotStatus.ERROR})
                raise exception.MetadataCopyFailure(reason=six.text_type(ex))
        self.db.snapshot_update(context, snapshot['id'], {'status': fields.SnapshotStatus.AVAILABLE, 'progress': '100%'})
    cgsnapshot.status = 'available'
    cgsnapshot.save()
    LOG.info(_LI('cgsnapshot %s: created successfully'), cgsnapshot.id)
    self._notify_about_cgsnapshot_usage(context, cgsnapshot, 'create.end')
    return cgsnapshot
Creates the cgsnapshot.
def create_cgsnapshot(self, context, cgsnapshot):
    
    caller_context = context
    context = context.elevated()
    LOG.info(_LI('Cgsnapshot %s: creating.'), cgsnapshot.id)
    snapshots = objects.SnapshotList.get_all_for_cgsnapshot(context, cgsnapshot.id)
    self._notify_about_cgsnapshot_usage(context, cgsnapshot, 'create.start')
    snapshots_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        LOG.debug('Cgsnapshot %(cgsnap_id)s: creating.', {'cgsnap_id': cgsnapshot.id})
        cgsnapshot.context = caller_context
        for snapshot in snapshots:
            snapshot.context = caller_context
        (model_update, snapshots_model_update) = self.driver.create_cgsnapshot(context, cgsnapshot, snapshots)
        if snapshots_model_update:
            for snap_model in snapshots_model_update:
                self.db.snapshot_update(context, snap_model['id'], snap_model)
                if ((snap_model['status'] in [fields.SnapshotStatus.ERROR_DELETING, fields.SnapshotStatus.ERROR]) and (model_update['status'] not in ['error_deleting', 'error'])):
                    model_update['status'] = snap_model['status']
        if model_update:
            if (model_update['status'] == 'error'):
                msg = (_('Error occurred when creating cgsnapshot %s.') % cgsnapshot.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            cgsnapshot.update(model_update)
            cgsnapshot.save()
    except exception.CinderException:
        with excutils.save_and_reraise_exception():
            cgsnapshot.status = 'error'
            cgsnapshot.save()
            if (not snapshots_model_update):
                for snapshot in snapshots:
                    snapshot.status = fields.SnapshotStatus.ERROR
                    snapshot.save()
    for snapshot in snapshots:
        volume_id = snapshot['volume_id']
        snapshot_id = snapshot['id']
        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.CinderException as ex:
                LOG.error(_LE('Failed updating %(snapshot_id)s metadata using the provided volumes %(volume_id)s metadata'), {'volume_id': volume_id, 'snapshot_id': snapshot_id})
                self.db.snapshot_update(context, snapshot_id, {'status': fields.SnapshotStatus.ERROR})
                raise exception.MetadataCopyFailure(reason=six.text_type(ex))
        self.db.snapshot_update(context, snapshot['id'], {'status': fields.SnapshotStatus.AVAILABLE, 'progress': '100%'})
    cgsnapshot.status = 'available'
    cgsnapshot.save()
    LOG.info(_LI('cgsnapshot %s: created successfully'), cgsnapshot.id)
    self._notify_about_cgsnapshot_usage(context, cgsnapshot, 'create.end')
    return cgsnapshot