From: Thierry Parmentelat Date: Mon, 23 Sep 2024 16:23:33 +0000 (+0200) Subject: allow GetSlices dict filter to mention the 'ALL' key to retrieve even expired ones X-Git-Tag: plcapi-7.2-1~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=de10a8de3d5c00a8d66703fa64afda1d07cb33fa;p=plcapi.git allow GetSlices dict filter to mention the 'ALL' key to retrieve even expired ones --- diff --git a/PLC/Methods/GetSlices.py b/PLC/Methods/GetSlices.py index fff2c393..f6ba0d67 100644 --- a/PLC/Methods/GetSlices.py +++ b/PLC/Methods/GetSlices.py @@ -19,6 +19,11 @@ class GetSlices(Method): query any of the slices at their sites. Admins and nodes may query any slice. If a slice that cannot be queried is specified in slice_filter, details about that slice will not be returned. + + In addition to the usual filter mechanism, when using a dictionary as filter, + it is possible to add the 'ALL' key - its value being then ignored - + that will return all slices even the ones that have been deleted + because they have expired. """ roles = ['admin', 'pi', 'user', 'node'] diff --git a/PLC/Slices.py b/PLC/Slices.py index 41ff56a2..c53e3752 100644 --- a/PLC/Slices.py +++ b/PLC/Slices.py @@ -280,7 +280,8 @@ class Slices(Table): view = f"{view} left join {table} using ({Slice.primary_key})" selected = ", ".join(list(self.columns.keys())+list(self.tag_columns.keys())) - sql = f"SELECT {selected} FROM {view} WHERE is_deleted IS False" + sql = f"SELECT {selected} FROM {view} WHERE TRUE" + remove_deleted = True if expires is not None: if expires >= 0: @@ -297,6 +298,9 @@ class Slices(Table): slice_filter = Filter(Slice.fields, {'slice_id': ints, 'name': strs}) sql += " AND (%s) %s" % slice_filter.sql(api, "OR") elif isinstance(slice_filter, dict): + if 'ALL' in slice_filter: + remove_deleted = False + del slice_filter['ALL'] allowed_fields = dict(list(Slice.fields.items())+list(Slice.tags.items())) slice_filter = Filter(allowed_fields, slice_filter) sql += " AND (%s) %s" % slice_filter.sql(api, "AND") @@ -309,4 +313,7 @@ class Slices(Table): else: raise PLCInvalidArgument(f"Wrong slice filter {slice_filter!r}") + if remove_deleted: + sql += " AND is_deleted IS False" + self.selectall(sql)