17a1290fe9def60e6b7e4e2e2485951d94b4c8a7
[plcapi.git] / PLC / Methods / ResolveSlices.py
1 # $Id: ResolveSlices.py 12217 2009-02-24 17:28:54Z thierry $
2
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Filter import Filter
6 from PLC.Auth import Auth
7 from PLC.Slices import Slice, Slices
8
9 class ResolveSlices(Method):
10     """
11     This method is similar to GetSlices, except that (1) the returned
12     columns are restricted to 'name' and 'slice_id', and (2) it
13     returns expired slices too. This method is designed to help
14     third-party software solve slice names from their slice_id
15     (e.g. PlanetFlow Central). For this reason it is accessible with
16     anonymous authentication (among others).
17     """
18
19     roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
20
21     applicable_fields = { 
22         'slice_id' : Slice.fields['slice_id'],
23         'name' : Slice.fields['name'],
24         }
25
26     accepts = [
27         Auth(),
28         Mixed([Mixed(Slice.fields['slice_id'],
29                      Slice.fields['name'])],
30               Parameter(str,"name"),
31               Parameter(int,"slice_id"),
32               Filter(applicable_fields))
33         ]
34
35     returns = [applicable_fields]
36
37     def call(self, auth, slice_filter = None):
38
39         # Must query at least slice_id (see below)
40         return_fields = self.applicable_fields.keys()
41         # pass expires=0
42         slices = Slices(self.api, slice_filter, return_fields, 0)
43         return slices