From: Thierry Parmentelat Date: Tue, 24 Sep 2024 08:05:27 +0000 (+0200) Subject: further changes in GetSlices; first iteration was not good enough X-Git-Tag: plcapi-7.2-1~1 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=873c808c25c15d4908d3ecf0de64ca44c22529d5;p=plcapi.git further changes in GetSlices; first iteration was not good enough pass 'DELETED' in the filter dict, not ALL, to turn off filtering of deleted slices pass 'EXPIRED' as well to turn off automatic filtering of expired slices --- diff --git a/PLC/Methods/GetSlices.py b/PLC/Methods/GetSlices.py index 43ce6053..5438aa0f 100644 --- a/PLC/Methods/GetSlices.py +++ b/PLC/Methods/GetSlices.py @@ -17,21 +17,29 @@ from PLC.Slices import Slice, Slices class GetSlices(Method): """ - Returns an array of structs containing details about slices. If - slice_filter is specified and is an array of slice identifiers or - slice names, or a struct of slice attributes, only slices matching - the filter will be returned. If return_fields is specified, only the - specified details will be returned. - - Users may only query slices of which they are members. PIs may - 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. + Returns an array of structs containing details about slices. If slice_filter + is specified and is an array of slice identifiers or slice names, or a + struct of slice attributes, only slices matching the filter will be + returned. If return_fields is specified, only the specified details will be + returned. + + Users may only query slices of which they are members. PIs may 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. + + Note that there is a special treatment of expired slices; by default, they + are not returned. And there are two mechanisms at work here, one is to + filter out deleted slices, and the other is to filter out the ones that have + expired (slices may exist in a metastable state where they have expired but + are not yet deleted). + + In order to overcome this behaviour, in addition to the usual filter mechanism, + you can + (1) use a dict filter and add the `DELETED` key - with any value, e.g. True - + that will return all slices even the ones that have been deleted + (2) also add a `EXPIRED` key to the dict filter - with any value, e.g. True - + to disable automatic filtering of expired slices. """ roles = ['admin', 'pi', 'user', 'node'] @@ -79,7 +87,13 @@ class GetSlices(Method): else: added_fields = False - slices = Slices(self.api, slice_filter, return_fields) + # 2024 sept: we need a way to pass a None 'expires' argument to Slices + # which by default is now() + expires_kwd = {} + if isinstance(slice_filter, dict) and 'EXPIRED' in slice_filter: + expires_kwd = {'expires': None} + del slice_filter['EXPIRED'] + slices = Slices(self.api, slice_filter, return_fields, **expires_kwd) # Filter out slices that are not viewable if isinstance(self.caller, Person) and \ diff --git a/PLC/Slices.py b/PLC/Slices.py index c53e3752..f47894ee 100644 --- a/PLC/Slices.py +++ b/PLC/Slices.py @@ -298,9 +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: + if 'DELETED' in slice_filter: remove_deleted = False - del slice_filter['ALL'] + del slice_filter['DELETED'] 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") @@ -315,5 +315,6 @@ class Slices(Table): if remove_deleted: sql += " AND is_deleted IS False" + print(sql) self.selectall(sql)