def update_consistencygroup(self, context, group, add_volumes=None, remove_volumes=None):
    'Updates consistency group.\n\n        Update consistency group by adding volumes to the group,\n        or removing volumes from the group.\n        '
    add_volumes_ref = []
    remove_volumes_ref = []
    add_volumes_list = []
    remove_volumes_list = []
    if add_volumes:
        add_volumes_list = add_volumes.split(',')
    if remove_volumes:
        remove_volumes_list = remove_volumes.split(',')
    for add_vol in add_volumes_list:
        try:
            add_vol_ref = self.db.volume_get(context, add_vol)
        except exception.VolumeNotFound:
            LOG.error(_LE('Update consistency group failed to add volume-%(volume_id)s: VolumeNotFound.'), {'volume_id': add_vol_ref['id']}, resource={'type': 'consistency_group', 'id': group.id})
            raise
        if (add_vol_ref['status'] not in VALID_ADD_VOL_TO_CG_STATUS):
            msg = (_('Cannot add volume %(volume_id)s to consistency group %(group_id)s because volume is in an invalid state: %(status)s. Valid states are: %(valid)s.') % {'volume_id': add_vol_ref['id'], 'group_id': group.id, 'status': add_vol_ref['status'], 'valid': VALID_ADD_VOL_TO_CG_STATUS})
            raise exception.InvalidVolume(reason=msg)
        new_host = vol_utils.extract_host(add_vol_ref['host'])
        if (new_host != self.host):
            raise exception.InvalidVolume(reason=_('Volume is not local to this node.'))
        add_volumes_ref.append(add_vol_ref)
    for remove_vol in remove_volumes_list:
        try:
            remove_vol_ref = self.db.volume_get(context, remove_vol)
        except exception.VolumeNotFound:
            LOG.error(_LE('Update consistency group failed to remove volume-%(volume_id)s: VolumeNotFound.'), {'volume_id': remove_vol_ref['id']}, resource={'type': 'consistency_group', 'id': group.id})
            raise
        if (remove_vol_ref['status'] not in VALID_REMOVE_VOL_FROM_CG_STATUS):
            msg = (_('Cannot remove volume %(volume_id)s from consistency group %(group_id)s because volume is in an invalid state: %(status)s. Valid states are: %(valid)s.') % {'volume_id': remove_vol_ref['id'], 'group_id': group.id, 'status': remove_vol_ref['status'], 'valid': VALID_REMOVE_VOL_FROM_CG_STATUS})
            raise exception.InvalidVolume(reason=msg)
        remove_volumes_ref.append(remove_vol_ref)
    self._notify_about_consistencygroup_usage(context, group, 'update.start')
    try:
        utils.require_driver_initialized(self.driver)
        (model_update, add_volumes_update, remove_volumes_update) = self.driver.update_consistencygroup(context, group, add_volumes=add_volumes_ref, remove_volumes=remove_volumes_ref)
        if add_volumes_update:
            for update in add_volumes_update:
                self.db.volume_update(context, update['id'], update)
        if remove_volumes_update:
            for update in remove_volumes_update:
                self.db.volume_update(context, update['id'], update)
        if model_update:
            if (model_update['status'] in [fields.ConsistencyGroupStatus.ERROR]):
                msg = (_('Error occurred when updating consistency group %s.') % group.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            group.update(model_update)
            group.save()
    except exception.VolumeDriverException:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE('Error occurred in the volume driver when updating consistency group %(group_id)s.'), {'group_id': group.id})
            group.status = 'error'
            group.save()
            for add_vol in add_volumes_ref:
                self.db.volume_update(context, add_vol['id'], {'status': 'error'})
            for rem_vol in remove_volumes_ref:
                self.db.volume_update(context, rem_vol['id'], {'status': 'error'})
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE('Error occurred when updating consistency group %(group_id)s.'), {'group_id': group.id})
            group.status = 'error'
            group.save()
            for add_vol in add_volumes_ref:
                self.db.volume_update(context, add_vol['id'], {'status': 'error'})
            for rem_vol in remove_volumes_ref:
                self.db.volume_update(context, rem_vol['id'], {'status': 'error'})
    now = timeutils.utcnow()
    group.status = 'available'
    group.update_at = now
    group.save()
    for add_vol in add_volumes_ref:
        self.db.volume_update(context, add_vol['id'], {'consistencygroup_id': group.id, 'updated_at': now})
    for rem_vol in remove_volumes_ref:
        self.db.volume_update(context, rem_vol['id'], {'consistencygroup_id': None, 'updated_at': now})
    self._notify_about_consistencygroup_usage(context, group, 'update.end')
    LOG.info(_LI('Update consistency group completed successfully.'), resource={'type': 'consistency_group', 'id': group.id})
Updates consistency group.

Update consistency group by adding volumes to the group,
or removing volumes from the group.
def update_consistencygroup(self, context, group, add_volumes=None, remove_volumes=None):
    'Updates consistency group.\n\n        Update consistency group by adding volumes to the group,\n        or removing volumes from the group.\n        '
    add_volumes_ref = []
    remove_volumes_ref = []
    add_volumes_list = []
    remove_volumes_list = []
    if add_volumes:
        add_volumes_list = add_volumes.split(',')
    if remove_volumes:
        remove_volumes_list = remove_volumes.split(',')
    for add_vol in add_volumes_list:
        try:
            add_vol_ref = self.db.volume_get(context, add_vol)
        except exception.VolumeNotFound:
            LOG.error(_LE('Update consistency group failed to add volume-%(volume_id)s: VolumeNotFound.'), {'volume_id': add_vol_ref['id']}, resource={'type': 'consistency_group', 'id': group.id})
            raise
        if (add_vol_ref['status'] not in VALID_ADD_VOL_TO_CG_STATUS):
            msg = (_('Cannot add volume %(volume_id)s to consistency group %(group_id)s because volume is in an invalid state: %(status)s. Valid states are: %(valid)s.') % {'volume_id': add_vol_ref['id'], 'group_id': group.id, 'status': add_vol_ref['status'], 'valid': VALID_ADD_VOL_TO_CG_STATUS})
            raise exception.InvalidVolume(reason=msg)
        new_host = vol_utils.extract_host(add_vol_ref['host'])
        if (new_host != self.host):
            raise exception.InvalidVolume(reason=_('Volume is not local to this node.'))
        add_volumes_ref.append(add_vol_ref)
    for remove_vol in remove_volumes_list:
        try:
            remove_vol_ref = self.db.volume_get(context, remove_vol)
        except exception.VolumeNotFound:
            LOG.error(_LE('Update consistency group failed to remove volume-%(volume_id)s: VolumeNotFound.'), {'volume_id': remove_vol_ref['id']}, resource={'type': 'consistency_group', 'id': group.id})
            raise
        if (remove_vol_ref['status'] not in VALID_REMOVE_VOL_FROM_CG_STATUS):
            msg = (_('Cannot remove volume %(volume_id)s from consistency group %(group_id)s because volume is in an invalid state: %(status)s. Valid states are: %(valid)s.') % {'volume_id': remove_vol_ref['id'], 'group_id': group.id, 'status': remove_vol_ref['status'], 'valid': VALID_REMOVE_VOL_FROM_CG_STATUS})
            raise exception.InvalidVolume(reason=msg)
        remove_volumes_ref.append(remove_vol_ref)
    self._notify_about_consistencygroup_usage(context, group, 'update.start')
    try:
        utils.require_driver_initialized(self.driver)
        (model_update, add_volumes_update, remove_volumes_update) = self.driver.update_consistencygroup(context, group, add_volumes=add_volumes_ref, remove_volumes=remove_volumes_ref)
        if add_volumes_update:
            for update in add_volumes_update:
                self.db.volume_update(context, update['id'], update)
        if remove_volumes_update:
            for update in remove_volumes_update:
                self.db.volume_update(context, update['id'], update)
        if model_update:
            if (model_update['status'] in [fields.ConsistencyGroupStatus.ERROR]):
                msg = (_('Error occurred when updating consistency group %s.') % group.id)
                LOG.error(msg)
                raise exception.VolumeDriverException(message=msg)
            group.update(model_update)
            group.save()
    except exception.VolumeDriverException:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE('Error occurred in the volume driver when updating consistency group %(group_id)s.'), {'group_id': group.id})
            group.status = 'error'
            group.save()
            for add_vol in add_volumes_ref:
                self.db.volume_update(context, add_vol['id'], {'status': 'error'})
            for rem_vol in remove_volumes_ref:
                self.db.volume_update(context, rem_vol['id'], {'status': 'error'})
    except Exception:
        with excutils.save_and_reraise_exception():
            LOG.error(_LE('Error occurred when updating consistency group %(group_id)s.'), {'group_id': group.id})
            group.status = 'error'
            group.save()
            for add_vol in add_volumes_ref:
                self.db.volume_update(context, add_vol['id'], {'status': 'error'})
            for rem_vol in remove_volumes_ref:
                self.db.volume_update(context, rem_vol['id'], {'status': 'error'})
    now = timeutils.utcnow()
    group.status = 'available'
    group.update_at = now
    group.save()
    for add_vol in add_volumes_ref:
        self.db.volume_update(context, add_vol['id'], {'consistencygroup_id': group.id, 'updated_at': now})
    for rem_vol in remove_volumes_ref:
        self.db.volume_update(context, rem_vol['id'], {'consistencygroup_id': None, 'updated_at': now})
    self._notify_about_consistencygroup_usage(context, group, 'update.end')
    LOG.info(_LI('Update consistency group completed successfully.'), resource={'type': 'consistency_group', 'id': group.id})