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