2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import Auth
6 from PLC.Peers import Peer, Peers
8 can_update = lambda (field, value): field in \
9 ['peername', 'peer_url', 'key', 'cacert', 'shortname', 'hrn_root']
11 class UpdatePeer(Method):
13 Updates a peer. Only the fields specified in peer_fields are
14 updated, all other fields are left untouched.
16 Returns 1 if successful, faults otherwise.
21 peer_fields = dict(filter(can_update, Peer.fields.items()))
25 Mixed(Peer.fields['peer_id'],
26 Peer.fields['peername']),
30 returns = Parameter(int, "1 if successful")
32 def call(self, auth, peer_id_or_name, peer_fields):
33 peer_fields = dict(filter(can_update, peer_fields.items()))
35 # Get account information
36 peers = Peers(self.api, [peer_id_or_name])
38 raise PLCInvalidArgument, "No such peer"
41 if isinstance(self.caller, Peer):
42 if self.caller['peer_id'] != peer['peer_id']:
43 raise PLCPermissionDenied, "Not allowed to update specified peer"
45 peer.update(peer_fields)
48 # Log affected objects
49 self.event_objects = {'Peer': [peer['peer_id']]}