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']
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 \
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")
if remove_deleted:
sql += " AND is_deleted IS False"
+ print(sql)
self.selectall(sql)