'Creates the group_snapshot.'

def create_group_snapshot(self, context, group_snapshot):

    caller_context = context
    context = context.elevated()
    LOG.info('GroupSnapshot    %s:    creating.', group_snapshot.id)
    snapshots = objects.SnapshotList.get_all_for_group_snapshot(context, group_snapshot.id)
    self._notify_about_group_snapshot_usage(context, group_snapshot, 'create.start')
    snapshots_model_update = None
    model_update = None
    try:
        utils.require_driver_initialized(self.driver)
        LOG.debug('Group    snapshot    %(grp_snap_id)s:    creating.', {'grp_snap_id': group_snapshot.id})
        group_snapshot.context = caller_context
        for snapshot in snapshots:
            snapshot.context = caller_context
        try:
            (model_update, snapshots_model_update) = self.driver.create_group_snapshot(context, group_snapshot, snapshots)
        except NotImplementedError:
            cgsnap_type = group_types.get_default_cgsnapshot_type()
            if (group_snapshot.group_type_id != cgsnap_type['id']):
                (model_update, snapshots_model_update) = self._create_group_snapshot_generic(context, group_snapshot, snapshots)
            else:
                (cgsnapshot, snapshots) = self._convert_group_snapshot_to_cgsnapshot(group_snapshot, snapshots, context)
                (model_update, snapshots_model_update) = self.driver.create_cgsnapshot(context, cgsnapshot, snapshots)
                self._remove_cgsnapshot_id_from_snapshots(snapshots)
        if snapshots_model_update:
            for snap_model in snapshots_model_update:
                snap_id = snap_model.pop('id')
                snap_obj = objects.Snapshot.get_by_id(context, snap_id)
                snap_obj.update(snap_model)
                snap_obj.save()
                if ((snap_model['status'] in [fields.SnapshotStatus.ERROR_DELETING, fields.SnapshotStatus.ERROR]) and (model_update['status'] not in [fields.GroupSnapshotStatus.ERROR_DELETING, fields.GroupSnapshotStatus.ERROR])):
                    model_update['status'] = snap_model['status']
        if model_update:
            if (model_update['status'] == fields.GroupSnapshotStatus.ERROR):
                msg = (_('Error    occurred    when    creating    group_snapshot    %s.') % group_snapshot.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            group_snapshot.update(model_update)
            group_snapshot.save()
    except exception.CinderException:
        with excutils.save_and_reraise_exception():
            group_snapshot.status = fields.GroupSnapshotStatus.ERROR
            group_snapshot.save()
            self._remove_cgsnapshot_id_from_snapshots(snapshots)
            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_obj = objects.Volume.get_by_id(context, volume_id)
        if vol_obj.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.error('Failed    updating    %(snapshot_id)s    metadata    using    the    provided    volumes    %(volume_id)s    metadata.', {'volume_id': volume_id, 'snapshot_id': snapshot_id})
                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()
    group_snapshot.status = fields.GroupSnapshotStatus.AVAILABLE
    group_snapshot.save()
    LOG.info('group_snapshot    %s:    created    successfully', group_snapshot.id)
    self._notify_about_group_snapshot_usage(context, group_snapshot, 'create.end')
    return group_snapshot
