3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Auth import Auth
7 from PLC.Peers import Peer, Peers
9 can_update = lambda (field, value): field in \
10 ['peername', 'peer_url', 'key', 'cacert', 'shortname', 'hrn_root']
12 class UpdatePeer(Method):
14 Updates a peer. Only the fields specified in peer_fields are
15 updated, all other fields are left untouched.
17 Returns 1 if successful, faults otherwise.
22 peer_fields = dict(filter(can_update, Peer.fields.items()))
26 Mixed(Peer.fields['peer_id'],
27 Peer.fields['peername']),
31 returns = Parameter(int, "1 if successful")
33 def call(self, auth, peer_id_or_name, peer_fields):
34 peer_fields = dict(filter(can_update, peer_fields.items()))
36 # Get account information
37 peers = Peers(self.api, [peer_id_or_name])
39 raise PLCInvalidArgument, "No such peer"
42 if isinstance(self.caller, Peer):
43 if self.caller['peer_id'] != peer['peer_id']:
44 raise PLCPermissionDenied, "Not allowed to update specified peer"
46 peer.update(peer_fields)
49 # Log affected objects
50 self.event_objects = {'Peer': [peer['peer_id']]}