'Create group snapshot.'

@huawei_utils.check_whether_operate_consistency_group
def create_group_snapshot(self, context, group_snapshot, snapshots):

    LOG.info('Create    group    snapshot    for    group:    %(group_id)s', {'group_id': group_snapshot.group_id})
    model_update = {}
    snapshots_model_update = []
    added_snapshots_info = []
    try:
        for snapshot in snapshots:
            volume = snapshot.volume
            if (not volume):
                msg = (_("Can't    get    volume    id    from    snapshot,    snapshot:    %(id)s") % {'id': snapshot.id})
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)
            (lun_id, lun_wwn) = huawei_utils.get_volume_lun_id(self.client, volume)
            snapshot_name = huawei_utils.encode_name(snapshot.id)
            snapshot_description = snapshot.id
            info = self.client.create_snapshot(lun_id, snapshot_name, snapshot_description)
            location = huawei_utils.to_string(huawei_snapshot_id=info['ID'])
            snap_model_update = {'id': snapshot.id, 'status': fields.SnapshotStatus.AVAILABLE, 'provider_location': location}
            snapshots_model_update.append(snap_model_update)
            added_snapshots_info.append(info)
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error('Create    group    snapshots    failed.    Group    snapshot    id:    %s.', group_snapshot.id)
    snapshot_ids = [added_snapshot['ID'] for added_snapshot in added_snapshots_info]
    try:
        self.client.activate_snapshot(snapshot_ids)
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error('Active    group    snapshots    failed.    Group    snapshot    id:    %s.', group_snapshot.id)
    model_update['status'] = fields.GroupSnapshotStatus.AVAILABLE
    return (model_update, snapshots_model_update)
