From: Mark Huang Date: Fri, 15 Dec 2006 19:41:02 +0000 (+0000) Subject: - add UpdatePeer method X-Git-Tag: pycurl-7_13_1~189 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2e6564e6f95f81710d3e1f43b36ab3fdfaec0ab0;p=plcapi.git - add UpdatePeer method --- diff --git a/PLC/Methods/UpdatePeer.py b/PLC/Methods/UpdatePeer.py new file mode 100644 index 0000000..5a298d9 --- /dev/null +++ b/PLC/Methods/UpdatePeer.py @@ -0,0 +1,45 @@ +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.Auth import Auth +from PLC.Peers import Peer, Peers + +can_update = lambda (field, value): field in \ + ['peername', 'peer_url', 'key', 'cacert'] + +class UpdatePeer(Method): + """ + Updates a peer. Only the fields specified in peer_fields are + updated, all other fields are left untouched. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin'] + + peer_fields = dict(filter(can_update, Peer.fields.items())) + + accepts = [ + Auth(), + Mixed(Peer.fields['peer_id'], + Peer.fields['peername']), + peer_fields + ] + + returns = Parameter(int, "1 if successful") + + def call(self, auth, peer_id_or_name, peer_fields): + peer_fields = dict(filter(can_update, peer_fields.items())) + + # Get account information + peers = Peers(self.api, [peer_id_or_name]) + if not peers: + raise PLCInvalidArgument, "No such peer" + + peer = peers[0] + peer.update(peer_fields) + peer.sync() + + # Log affected objects + self.object_ids = [peer['peer_id']] + + return 1