'Update group.'

@wrap_check_policy
def update(self, context, group, name, description, add_volumes, remove_volumes):

    if (group.status != c_fields.GroupStatus.AVAILABLE):
        msg = (_('Group    status    must    be    available,    but    current    status    is:    %s.') % group.status)
        raise exception.InvalidGroup(reason=msg)
    add_volumes_list = []
    remove_volumes_list = []
    if add_volumes:
        add_volumes = add_volumes.strip(',')
        add_volumes_list = add_volumes.split(',')
    if remove_volumes:
        remove_volumes = remove_volumes.strip(',')
        remove_volumes_list = remove_volumes.split(',')
    invalid_uuids = []
    for uuid in add_volumes_list:
        if (uuid in remove_volumes_list):
            invalid_uuids.append(uuid)
    if invalid_uuids:
        msg = (_('UUIDs    %s    are    in    both    add    and    remove    volume    list.') % invalid_uuids)
        raise exception.InvalidVolume(reason=msg)
    volumes = self.db.volume_get_all_by_generic_group(context, group.id)
    if (name == group.name):
        name = None
    if (description == group.description):
        description = None
    add_volumes_new = ''
    remove_volumes_new = ''
    if add_volumes_list:
        add_volumes_new = self._validate_add_volumes(context, volumes, add_volumes_list, group)
    if remove_volumes_list:
        remove_volumes_new = self._validate_remove_volumes(volumes, remove_volumes_list, group)
    if ((name is None) and (description is None) and (not add_volumes_new) and (not remove_volumes_new)):
        msg = (_('Cannot    update    group    %(group_id)s    because    no    valid    name,    description,    add_volumes,    or    remove_volumes    were    provided.') % {'group_id': group.id})
        raise exception.InvalidGroup(reason=msg)
    fields = {'updated_at': timeutils.utcnow()}
    if (name is not None):
        fields['name'] = name
    if (description is not None):
        fields['description'] = description
    if ((not add_volumes_new) and (not remove_volumes_new)):
        fields['status'] = c_fields.GroupStatus.AVAILABLE
    else:
        fields['status'] = c_fields.GroupStatus.UPDATING
    group.update(fields)
    group.save()
    if (add_volumes_new or remove_volumes_new):
        self.volume_rpcapi.update_group(context, group, add_volumes=add_volumes_new, remove_volumes=remove_volumes_new)
