1 # Thierry Parmentelat -- INRIA
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.Leases import Lease, Leases, LeaseFilter
9 class GetLeases(Method):
11 Returns an array of structs containing details about leases. If
12 lease_filter is specified and is an array of lease identifiers or
13 lease names, or a struct of lease attributes, only leases matching
14 the filter will be returned. If return_fields is specified, only the
15 specified details will be returned.
17 All leases are exposed to all users.
19 In addition to the usual filter capabilities, the following are supported:
20 * GetLeases ({ 'alive' : '2010-02-20 20:00' , <regular_filter_fields...> })
21 returns the leases that are active at that point in time
22 * GetLeases ({ 'alive' : ('2010-02-20 20:00' , '2010-02-20 21:00' ) , ... })
23 ditto for a time range
25 This is implemented in the LeaseFilter class; negation actually is supported
26 through the usual '~alive' form, although maybe not really useful.
30 roles = ['admin', 'pi', 'user', 'node', 'anonymous']
34 Mixed(Lease.fields['lease_id'],
35 [Lease.fields['lease_id']],
36 LeaseFilter(Lease.fields)),
37 Parameter([str], "List of fields to return", nullok = True)
40 returns = [Lease.fields]
42 def call(self, auth, lease_filter = None, return_fields = None):
44 # Must query at least lease_id (see below)
45 if return_fields is not None and 'lease_id' not in return_fields:
46 return_fields.append('lease_id')
51 leases = Leases(self.api, lease_filter, return_fields)
53 # Remove lease_id if not specified
56 if 'lease_id' in lease: