svn keywords
[plcapi.git] / PLC / Methods / GetPeers.py
1 # $Id$
2 # $URL$
3 #
4 # Thierry Parmentelat - INRIA
5
6
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Filter import Filter
11 from PLC.Auth import Auth
12
13 from PLC.Persons import Person
14 from PLC.Peers import Peer, Peers
15
16 class GetPeers (Method):
17     """
18     Returns an array of structs containing details about peers. If
19     person_filter is specified and is an array of peer identifiers or
20     peer names, or a struct of peer attributes, only peers matching
21     the filter will be returned. If return_fields is specified, only the
22     specified details will be returned.
23     """
24
25     roles = ['admin', 'node','pi','user']
26
27     accepts = [
28         Auth(),
29         Mixed([Mixed(Peer.fields['peer_id'],
30                      Peer.fields['peername'])],
31               Filter(Peer.fields)),
32         Parameter([str], "List of fields to return", nullok = True)        
33         ]
34
35     returns = [Peer.fields]
36
37     def call (self, auth, peer_filter = None, return_fields = None):
38         
39         peers = Peers(self.api, peer_filter, return_fields)
40
41         # Remove admin only fields
42         if not isinstance(self.caller, Person) or \
43                 'admin' not in self.caller['roles']:
44             for peer in peers:    
45                 for field in ['key', 'cacert']:
46                     if field in peer:
47                         del peer[field]
48
49         return peers