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.NodeTags import NodeTag, NodeTags
15 from PLC.Nodes import Node, Nodes
17 from PLC.Nodes import Node, Nodes
18 from PLC.Sites import Site, Sites
20 class DeleteNodeTag(Method):
22 Deletes the specified node tag
24 Attributes may require the caller to have a particular role in order
25 to be deleted, depending on the related node 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 NodeTag.fields['node_tag_id']
38 returns = Parameter(int, '1 if successful')
43 def call(self, auth, node_tag_id):
44 node_tags = NodeTags(self.api, [node_tag_id])
46 raise PLCInvalidArgument, "No such node tag %r"%node_tag_id
47 node_tag = node_tags[0]
49 ### reproducing a check from UpdateSliceTag, looks dumb though
50 nodes = Nodes(self.api, [node_tag['node_id']])
52 raise PLCInvalidArgument, "No such node %r"%node_tag['node_id']
55 assert node_tag['node_tag_id'] in node['node_tag_ids']
57 # check permission : it not admin, is the user affiliated with the right site
58 if 'admin' not in self.caller['roles']:
60 node = Nodes (self.api,[node['node_id']])[0]
62 site = Sites (self.api, [node['site_id']])[0]
63 # check caller is affiliated with this site
64 if self.caller['person_id'] not in site['person_ids']:
65 raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
67 required_min_role = tag_type ['min_role_id']
68 if required_min_role is not None and \
69 min(self.caller['role_ids']) > required_min_role:
70 raise PLCPermissionDenied, "Not allowed to modify the specified node tag, requires role %d",required_min_role
73 self.object_ids = [node_tag['node_tag_id']]