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 PasswordAuth
7 class UpdatePCU(Method):
9 Updates the parameters of an existing PCU with the values in
12 Non-admins may only update PCUs at their sites.
14 Returns 1 if successful, faults otherwise.
17 roles = ['admin', 'pi', 'tech']
19 can_update = lambda (field, value): field not in \
21 update_fields = dict(filter(can_update, PCU.fields.items()))
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, pcu_id, pcu_fields):
32 # Make sure only valid fields are specified
33 if filter(lambda field: field not in self.update_fields, pcu_fields):
34 raise PLCInvalidArgument, "Invalid field specified"
36 # Get associated PCU details
37 pcus = PCUs(self.api, [pcu_id]).values()
39 raise PLCInvalidArgument, "No such PCU"
42 if 'admin' not in self.caller['roles']:
45 sites = Sites(self.api, self.caller['site_ids']).values()
47 if pcu['pcu_id'] in site['pcu_ids']:
51 raise PLCPermissionDenied, "Not allowed to update that PCU"
53 pcu.update(pcu_fields)