svn keywords
[plcapi.git] / PLC / Methods / AddPeer.py
1 # $Id$
2 # $URL$
3 #
4 # Thierry Parmentelat - INRIA
5
6
7 from PLC.Method import Method
8 from PLC.Parameter import Parameter, Mixed
9 from PLC.Auth import Auth
10 from PLC.Peers import Peer, Peers
11
12 can_update = lambda (field, value): field in \
13              ['peername', 'peer_url', 'key', 'cacert', 'shortname', 'hrn_root']
14
15 class AddPeer(Method):
16     """
17     Adds a new peer.
18
19     Returns the new peer_id (> 0) if successful, faults otherwise.
20     """
21
22     roles = ['admin']
23
24     peer_fields = dict(filter(can_update, Peer.fields.items()))
25
26     accepts = [
27         Auth(),
28         peer_fields
29         ]
30
31     returns = Parameter(int, "New peer_id (> 0) if successful")
32
33     def call(self, auth, peer_fields):
34         peer = Peer(self.api, peer_fields);
35         peer.sync()
36         self.event_objects = {'Peer': [peer['peer_id']]}
37
38         return peer['peer_id']