X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPeers.py;h=bce911e60b1edb42b83f0d899b1aa2c98cd378fe;hb=71a2b50be6b8cea74ae3f55afecbff3b28e5798d;hp=e4fd4591c56ee461f5962cb6e227c96f5cb3a893;hpb=51577ccbfa01fffba04b84e502a35f6a3915b68b;p=plcapi.git diff --git a/PLC/Methods/GetPeers.py b/PLC/Methods/GetPeers.py index e4fd459..bce911e 100644 --- a/PLC/Methods/GetPeers.py +++ b/PLC/Methods/GetPeers.py @@ -1,6 +1,8 @@ +# $Id$ +# $URL$ # # Thierry Parmentelat - INRIA -# +# from PLC.Faults import * from PLC.Method import Method @@ -8,6 +10,7 @@ from PLC.Parameter import Parameter, Mixed from PLC.Filter import Filter from PLC.Auth import Auth +from PLC.Persons import Person from PLC.Peers import Peer, Peers class GetPeers (Method): @@ -15,19 +18,32 @@ class GetPeers (Method): Returns an array of structs containing details about peers. If person_filter is specified and is an array of peer identifiers or peer names, or a struct of peer attributes, only peers matching - the filter will be returned. + the filter will be returned. If return_fields is specified, only the + specified details will be returned. """ - roles = ['admin'] + roles = ['admin', 'node','pi','user'] accepts = [ Auth(), Mixed([Mixed(Peer.fields['peer_id'], Peer.fields['peername'])], - Filter(Peer.fields)) + Filter(Peer.fields)), + Parameter([str], "List of fields to return", nullok = True) ] returns = [Peer.fields] - def call (self, auth, peer_filter = None): - return Peers(self.api, peer_filter).values() + def call (self, auth, peer_filter = None, return_fields = None): + + peers = Peers(self.api, peer_filter, return_fields) + + # Remove admin only fields + if not isinstance(self.caller, Person) or \ + 'admin' not in self.caller['roles']: + for peer in peers: + for field in ['key', 'cacert']: + if field in peer: + del peer[field] + + return peers