X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FGetPeers.py;h=97f96d09a0acf9bcc28b6bbdb42a1c30acec6c30;hb=5afb8089a48433612fb10bed3c609006882b9859;hp=cc85ef17ca0ffd73346f820f05bbbfbcec57790e;hpb=1f6ee420de8747ad6d801104e24bb1fa386de2bb;p=plcapi.git diff --git a/PLC/Methods/GetPeers.py b/PLC/Methods/GetPeers.py index cc85ef1..97f96d0 100644 --- a/PLC/Methods/GetPeers.py +++ b/PLC/Methods/GetPeers.py @@ -1,3 +1,5 @@ +# $Id$ +# $URL$ # # Thierry Parmentelat - INRIA # @@ -5,24 +7,43 @@ from PLC.Faults import * from PLC.Method import Method 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): """ - returns information on known peers + 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. If return_fields is specified, only the + specified details will be returned. """ - roles = ['admin'] + roles = ['admin', 'node','pi','user'] - accepts = [Auth(), - [Mixed(Peer.fields['peer_id'], - Peer.fields['peername'])], - ] + accepts = [ + Auth(), + Mixed([Mixed(Peer.fields['peer_id'], + Peer.fields['peername'])], + Filter(Peer.fields)), + Parameter([str], "List of fields to return", nullok = True) + ] returns = [Peer.fields] - def call (self, auth, peer_id_or_peername_list = None): + def call (self, auth, peer_filter = None, return_fields = None): + + peers = Peers(self.api, peer_filter, return_fields) - return Peers (self.api, peer_id_or_peername_list).values() + # 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