1 # $Id: UpdateSiteTag.py 14587 2009-07-19 13:18:50Z thierry $
2 # $URL: http://svn.planet-lab.org/svn/PLCAPI/tags/PLCAPI-4.3-27/PLC/Methods/UpdateSiteTag.py $
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
12 from PLC.SiteTags import SiteTag, SiteTags
13 from PLC.Sites import Site, Sites
15 from PLC.Nodes import Nodes
16 from PLC.Sites import Sites
18 class UpdateSiteTag(Method):
20 Updates the value of an existing site setting
22 Access rights depend on the tag type.
24 Returns 1 if successful, faults otherwise.
27 roles = ['admin', 'pi', 'tech', 'user']
31 SiteTag.fields['site_tag_id'],
32 SiteTag.fields['value']
35 returns = Parameter(int, '1 if successful')
39 def call(self, auth, site_tag_id, value):
40 site_tags = SiteTags(self.api, [site_tag_id])
42 raise PLCInvalidArgument, "No such site setting %r"%site_tag_id
43 site_tag = site_tags[0]
45 ### reproducing a check from UpdateSliceTag, looks dumb though
46 sites = Sites(self.api, [site_tag['site_id']])
48 raise PLCInvalidArgument, "No such site %r"%site_tag['site_id']
51 assert site_tag['site_tag_id'] in site['site_tag_ids']
53 # check permission : it not admin, is the user affiliated with the right site
54 if 'admin' not in self.caller['roles']:
55 # check caller is affiliated with this site
56 if self.caller['person_id'] not in site['person_ids']:
57 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
59 required_min_role = tag_type ['min_role_id']
60 if required_min_role is not None and \
61 min(self.caller['role_ids']) > required_min_role:
62 raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
64 site_tag['value'] = value
67 self.object_ids = [site_tag['site_tag_id']]