3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.PCUs import PCU, PCUs
7 from PLC.Auth import Auth
9 can_update = lambda (field, value): field not in \
12 class UpdatePCU(Method):
14 Updates the parameters of an existing PCU with the values in
17 Non-admins may only update PCUs at their sites.
19 Returns 1 if successful, faults otherwise.
22 roles = ['admin', 'pi', 'tech']
24 update_fields = dict(filter(can_update, PCU.fields.items()))
32 returns = Parameter(int, '1 if successful')
34 def call(self, auth, pcu_id, pcu_fields):
35 pcu_fields = dict(filter(can_update, pcu_fields.items()))
37 # Get associated PCU details
38 pcus = PCUs(self.api, [pcu_id])
40 raise PLCInvalidArgument, "No such PCU"
43 if 'admin' not in self.caller['roles']:
44 if pcu['site_id'] not in self.caller['site_ids']:
45 raise PLCPermissionDenied, "Not allowed to update that PCU"
47 pcu.update(pcu_fields)
51 self.event_objects = {'PCU': [pcu['pcu_id']]}
52 self.message = 'PCU %d updated: %s' % \
53 (pcu['pcu_id'], ", ".join(pcu_fields.keys()))