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