X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPeer.py;h=868ce11bbe36be2d3bb8ccc7d34d05bdc05c82fc;hb=19d4a01ccf66af9e00914351b3eacd5fc880f988;hp=f636add1e571ac298ce9167e8deb3b8a8fc57285;hpb=286e4963a987e2478baca5050e805516e2b7fbd0;p=plcapi.git diff --git a/PLC/Methods/AddPeer.py b/PLC/Methods/AddPeer.py index f636add..868ce11 100644 --- a/PLC/Methods/AddPeer.py +++ b/PLC/Methods/AddPeer.py @@ -1,34 +1,36 @@ -from PLC.Faults import * +# +# Thierry Parmentelat - INRIA +# + from PLC.Method import Method from PLC.Parameter import Parameter, Mixed from PLC.Auth import Auth - from PLC.Peers import Peer, Peers -can_update = lambda(k,v): k in ['peername','peer_url','person_id'] +can_update = lambda (field, value): field in \ + ['peername', 'peer_url', 'key', 'cacert', 'shortname', 'hrn_root'] -class AddPeer (Method): +class AddPeer(Method): """ - Creates a peer entry in the database and returns its id - Temporarily, requires to provide a person_id - this is used to store the credentials that we'll - use when connecting to the peer's API + Adds a new peer. + + Returns the new peer_id (> 0) if successful, faults otherwise. """ roles = ['admin'] - peer_fields = dict( [x for x in Peer.fields.iteritems() if can_update(x)] ) - accepts = [ Auth(), - peer_fields - ] + peer_fields = dict(filter(can_update, Peer.fields.items())) - returns = Parameter (int, "peer_id") + accepts = [ + Auth(), + peer_fields + ] - def call (self, auth, fields): + returns = Parameter(int, "New peer_id (> 0) if successful") - peer = Peer (self.api,fields); - peer.sync() - - return peer['peer_id'] - + def call(self, auth, peer_fields): + peer = Peer(self.api, peer_fields); + peer.sync() + self.event_objects = {'Peer': [peer['peer_id']]} + return peer['peer_id']