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