all tag types use permission helpers in AuthorizeHelpers
[plcapi.git] / PLC / Methods / DeleteSliceTag.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
8
9 from PLC.SliceTags import SliceTag, SliceTags
10 from PLC.Slices import Slice, Slices
11 from PLC.Nodes import Node, Nodes
12
13 class DeleteSliceTag(Method):
14     """
15     Deletes the specified slice or sliver attribute.
16
17     Attributes may require the caller to have a particular role in
18     order to be deleted. Users may only delete attributes of
19     slices or slivers of which they are members. PIs may only delete
20     attributes of slices or slivers at their sites, or of which they
21     are members. Admins may delete attributes of any slice or sliver.
22
23     Returns 1 if successful, faults otherwise.
24     """
25
26     roles = ['admin', 'pi', 'user', 'tech']
27
28     accepts = [
29         Auth(),
30         SliceTag.fields['slice_tag_id']
31         ]
32
33     returns = Parameter(int, '1 if successful')
34
35     def call(self, auth, slice_tag_id):
36         slice_tags = SliceTags(self.api, [slice_tag_id])
37         if not slice_tags:
38             raise PLCInvalidArgument, "No such slice attribute"
39         slice_tag = slice_tags[0]
40
41         slices = Slices(self.api, [slice_tag['slice_id']])
42         if not slices:
43             raise PLCInvalidArgument, "No such slice %d"%slice_tag['slice_id']
44         slice = slices[0]
45
46         assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
47
48         # check authorizations
49         node_id_or_hostname=slice_tag['node_id']
50         nodegroup_id_or_name=slice_tag['nodegroup_id']
51         slice.caller_may_write_tag(self.api,self.caller,tag_type,node_id_or_hostname,nodegroup_id_or_name)
52
53         slice_tag.delete()
54         self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
55
56         return 1