for federation : Peers and ForeignNodes
[plcapi.git] / PLC / Methods / AddPeer.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import Auth
5
6 from PLC.Peers import Peer, Peers
7
8 can_update = lambda(k,v): k in ['peername','peer_url','person_id']
9
10 class AddPeer (Method):
11     """
12     Creates a peer entry in the database and returns its id
13     Temporarily, requires to provide a person_id 
14     this is used to store the credentials that we'll
15     use when connecting to the peer's API
16     """
17
18     roles = ['admin']
19     peer_fields = dict( [x for x in Peer.fields.iteritems() if can_update(x)] )
20
21     accepts = [ Auth(),
22                 peer_fields
23                 ]
24
25     returns = Parameter (int, "peer_id")
26
27     def call (self, auth, fields):
28
29         peer = Peer (self.api,fields);
30         peer.sync()
31         
32         return peer['peer_id']
33         
34