1 # $Id: DeleteSiteTag.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/DeleteSiteTag.py $
4 # Thierry Parmentelat - INRIA
9 from PLC.Faults import *
10 from PLC.Method import Method
11 from PLC.Parameter import Parameter, Mixed
12 from PLC.Auth import Auth
14 from PLC.SiteTags import SiteTag, SiteTags
15 from PLC.Sites import Site, Sites
17 from PLC.Nodes import Node, Nodes
18 from PLC.Sites import Site, Sites
20 class DeleteSiteTag(Method):
22 Deletes the specified site setting
24 Attributes may require the caller to have a particular role in order
25 to be deleted, depending on the related tag type.
26 Admins may delete attributes of any slice or sliver.
28 Returns 1 if successful, faults otherwise.
31 roles = ['admin', 'pi', 'user']
35 SiteTag.fields['site_tag_id']
38 returns = Parameter(int, '1 if successful')
43 def call(self, auth, site_tag_id):
44 site_tags = SiteTags(self.api, [site_tag_id])
46 raise PLCInvalidArgument, "No such site tag %r"%site_tag_id
47 site_tag = site_tags[0]
49 ### reproducing a check from UpdateSliceTag, looks dumb though
50 sites = Sites(self.api, [site_tag['site_id']])
52 raise PLCInvalidArgument, "No such site %r"%site_tag['site_id']
55 assert site_tag['site_tag_id'] in site['site_tag_ids']
57 # check permission : it not admin, is the user affiliated with the right site
58 if 'admin' not in self.caller['roles']:
59 # check caller is affiliated with this site
60 if self.caller['person_id'] not in site['person_ids']:
61 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
63 required_min_role = tag_type ['min_role_id']
64 if required_min_role is not None and \
65 min(self.caller['role_ids']) > required_min_role:
66 raise PLCPermissionDenied, "Not allowed to modify the specified site setting, requires role %d",required_min_role
69 self.object_ids = [site_tag['site_tag_id']]