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 from PLC.Peers import Peer, Peers
7 can_update = lambda field_value: field_value[0] in \
8 ['peername', 'peer_url', 'key', 'cacert', 'shortname', 'hrn_root']
10 class UpdatePeer(Method):
12 Updates a peer. Only the fields specified in peer_fields are
13 updated, all other fields are left untouched.
15 Returns 1 if successful, faults otherwise.
20 peer_fields = dict(list(filter(can_update, list(Peer.fields.items()))))
24 Mixed(Peer.fields['peer_id'],
25 Peer.fields['peername']),
29 returns = Parameter(int, "1 if successful")
31 def call(self, auth, peer_id_or_name, peer_fields):
32 peer_fields = dict(list(filter(can_update, list(peer_fields.items()))))
34 # Get account information
35 peers = Peers(self.api, [peer_id_or_name])
37 raise PLCInvalidArgument("No such peer")
40 if isinstance(self.caller, Peer):
41 if self.caller['peer_id'] != peer['peer_id']:
42 raise PLCPermissionDenied("Not allowed to update specified peer")
44 peer.update(peer_fields)
47 # Log affected objects
48 self.event_objects = {'Peer': [peer['peer_id']]}