def create_consistencygroup_from_src(self, context, group, cgsnapshot=None, source_cg=None):
    'Creates the consistency group from source.\n\n        The source can be a CG snapshot or a source CG.\n        '
    source_name = None
    snapshots = None
    source_vols = None
    try:
        volumes = self.db.volume_get_all_by_group(context, group.id)
        if cgsnapshot:
            try:
                cgsnapshot = objects.CGSnapshot.get_by_id(context, cgsnapshot.id)
            except exception.CgSnapshotNotFound:
                LOG.error(_LE('Create consistency group from snapshot-%(snap)s failed: SnapshotNotFound.'), {'snap': cgsnapshot.id}, resource={'type': 'consistency_group', 'id': group.id})
                raise
            source_name = (_('snapshot-%s') % cgsnapshot.id)
            snapshots = objects.SnapshotList.get_all_for_cgsnapshot(context, cgsnapshot.id)
            for snap in snapshots:
                if (snap.status not in VALID_CREATE_CG_SRC_SNAP_STATUS):
                    msg = (_('Cannot create consistency group %(group)s because snapshot %(snap)s is not in a valid state. Valid states are: %(valid)s.') % {'group': group.id, 'snap': snap['id'], 'valid': VALID_CREATE_CG_SRC_SNAP_STATUS})
                    raise exception.InvalidConsistencyGroup(reason=msg)
        if source_cg:
            try:
                source_cg = objects.ConsistencyGroup.get_by_id(context, source_cg.id)
            except exception.ConsistencyGroupNotFound:
                LOG.error(_LE('Create consistency group from source cg-%(cg)s failed: ConsistencyGroupNotFound.'), {'cg': source_cg.id}, resource={'type': 'consistency_group', 'id': group.id})
                raise
            source_name = (_('cg-%s') % source_cg.id)
            source_vols = self.db.volume_get_all_by_group(context, source_cg.id)
            for source_vol in source_vols:
                if (source_vol['status'] not in VALID_CREATE_CG_SRC_CG_STATUS):
                    msg = (_('Cannot create consistency group %(group)s because source volume %(source_vol)s is not in a valid state. Valid states are: %(valid)s.') % {'group': group.id, 'source_vol': source_vol['id'], 'valid': VALID_CREATE_CG_SRC_CG_STATUS})
                    raise exception.InvalidConsistencyGroup(reason=msg)
        sorted_snapshots = None
        if (cgsnapshot and snapshots):
            sorted_snapshots = self._sort_snapshots(volumes, snapshots)
        sorted_source_vols = None
        if (source_cg and source_vols):
            sorted_source_vols = self._sort_source_vols(volumes, source_vols)
        self._notify_about_consistencygroup_usage(context, group, 'create.start')
        utils.require_driver_initialized(self.driver)
        (model_update, volumes_model_update) = self.driver.create_consistencygroup_from_src(context, group, volumes, cgsnapshot, sorted_snapshots, source_cg, sorted_source_vols)
        if volumes_model_update:
            for update in volumes_model_update:
                self.db.volume_update(context, update['id'], update)
        if model_update:
            group.update(model_update)
            group.save()
    except Exception:
        with excutils.save_and_reraise_exception():
            group.status = 'error'
            group.save()
            LOG.error(_LE('Create consistency group from source %(source)s failed.'), {'source': source_name}, resource={'type': 'consistency_group', 'id': group.id})
            for vol in volumes:
                self.db.volume_update(context, vol['id'], {'status': 'error'})
    now = timeutils.utcnow()
    status = 'available'
    for vol in volumes:
        update = {'status': status, 'created_at': now}
        self._update_volume_from_src(context, vol, update, group=group)
        self._update_allocated_capacity(vol)
    group.status = status
    group.created_at = now
    group.save()
    self._notify_about_consistencygroup_usage(context, group, 'create.end')
    LOG.info(_LI('Create consistency group from source-%(source)s completed successfully.'), {'source': source_name}, resource={'type': 'consistency_group', 'id': group.id})
    return group
Creates the consistency group from source.

The source can be a CG snapshot or a source CG.
def create_consistencygroup_from_src(self, context, group, cgsnapshot=None, source_cg=None):
    'Creates the consistency group from source.\n\n        The source can be a CG snapshot or a source CG.\n        '
    source_name = None
    snapshots = None
    source_vols = None
    try:
        volumes = self.db.volume_get_all_by_group(context, group.id)
        if cgsnapshot:
            try:
                cgsnapshot = objects.CGSnapshot.get_by_id(context, cgsnapshot.id)
            except exception.CgSnapshotNotFound:
                LOG.error(_LE('Create consistency group from snapshot-%(snap)s failed: SnapshotNotFound.'), {'snap': cgsnapshot.id}, resource={'type': 'consistency_group', 'id': group.id})
                raise
            source_name = (_('snapshot-%s') % cgsnapshot.id)
            snapshots = objects.SnapshotList.get_all_for_cgsnapshot(context, cgsnapshot.id)
            for snap in snapshots:
                if (snap.status not in VALID_CREATE_CG_SRC_SNAP_STATUS):
                    msg = (_('Cannot create consistency group %(group)s because snapshot %(snap)s is not in a valid state. Valid states are: %(valid)s.') % {'group': group.id, 'snap': snap['id'], 'valid': VALID_CREATE_CG_SRC_SNAP_STATUS})
                    raise exception.InvalidConsistencyGroup(reason=msg)
        if source_cg:
            try:
                source_cg = objects.ConsistencyGroup.get_by_id(context, source_cg.id)
            except exception.ConsistencyGroupNotFound:
                LOG.error(_LE('Create consistency group from source cg-%(cg)s failed: ConsistencyGroupNotFound.'), {'cg': source_cg.id}, resource={'type': 'consistency_group', 'id': group.id})
                raise
            source_name = (_('cg-%s') % source_cg.id)
            source_vols = self.db.volume_get_all_by_group(context, source_cg.id)
            for source_vol in source_vols:
                if (source_vol['status'] not in VALID_CREATE_CG_SRC_CG_STATUS):
                    msg = (_('Cannot create consistency group %(group)s because source volume %(source_vol)s is not in a valid state. Valid states are: %(valid)s.') % {'group': group.id, 'source_vol': source_vol['id'], 'valid': VALID_CREATE_CG_SRC_CG_STATUS})
                    raise exception.InvalidConsistencyGroup(reason=msg)
        sorted_snapshots = None
        if (cgsnapshot and snapshots):
            sorted_snapshots = self._sort_snapshots(volumes, snapshots)
        sorted_source_vols = None
        if (source_cg and source_vols):
            sorted_source_vols = self._sort_source_vols(volumes, source_vols)
        self._notify_about_consistencygroup_usage(context, group, 'create.start')
        utils.require_driver_initialized(self.driver)
        (model_update, volumes_model_update) = self.driver.create_consistencygroup_from_src(context, group, volumes, cgsnapshot, sorted_snapshots, source_cg, sorted_source_vols)
        if volumes_model_update:
            for update in volumes_model_update:
                self.db.volume_update(context, update['id'], update)
        if model_update:
            group.update(model_update)
            group.save()
    except Exception:
        with excutils.save_and_reraise_exception():
            group.status = 'error'
            group.save()
            LOG.error(_LE('Create consistency group from source %(source)s failed.'), {'source': source_name}, resource={'type': 'consistency_group', 'id': group.id})
            for vol in volumes:
                self.db.volume_update(context, vol['id'], {'status': 'error'})
    now = timeutils.utcnow()
    status = 'available'
    for vol in volumes:
        update = {'status': status, 'created_at': now}
        self._update_volume_from_src(context, vol, update, group=group)
        self._update_allocated_capacity(vol)
    group.status = status
    group.created_at = now
    group.save()
    self._notify_about_consistencygroup_usage(context, group, 'create.end')
    LOG.info(_LI('Create consistency group from source-%(source)s completed successfully.'), {'source': source_name}, resource={'type': 'consistency_group', 'id': group.id})
    return group