further changes in GetSlices; first iteration was not good enough
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 24 Sep 2024 08:05:27 +0000 (10:05 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 24 Sep 2024 08:05:27 +0000 (10:05 +0200)
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

PLC/Methods/GetSlices.py
PLC/Slices.py

index 43ce605..5438aa0 100644 (file)
@@ -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 \
index c53e375..f47894e 100644 (file)
@@ -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)