2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.PCUs import PCU, PCUs
6 from PLC.Auth import Auth
8 can_update = lambda (field, value): field not in \
11 class UpdatePCU(Method):
13 Updates the parameters of an existing PCU with the values in
16 Non-admins may only update PCUs at their sites.
18 Returns 1 if successful, faults otherwise.
21 roles = ['admin', 'pi', 'tech']
23 update_fields = dict(filter(can_update, PCU.fields.items()))
31 returns = Parameter(int, '1 if successful')
33 def call(self, auth, pcu_id, pcu_fields):
34 pcu_fields = dict(filter(can_update, pcu_fields.items()))
36 # Get associated PCU details
37 pcus = PCUs(self.api, [pcu_id])
39 raise PLCInvalidArgument, "No such PCU"
42 if 'admin' not in self.caller['roles']:
43 if pcu['site_id'] not in self.caller['site_ids']:
44 raise PLCPermissionDenied, "Not allowed to update that PCU"
46 pcu.update(pcu_fields)
50 self.event_objects = {'PCU': [pcu['pcu_id']]}
51 self.message = 'PCU %d updated: %s' % \
52 (pcu['pcu_id'], ", ".join(pcu_fields.keys()))