blind 2to3
[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.TagTypes import TagTypes, TagType
10 from PLC.Nodes import Node, Nodes
11 from PLC.Slices import Slice, Slices
12 from PLC.SliceTags import SliceTag, SliceTags
13
14 # need to import so the core classes get decorated with caller_may_write_tag
15 from PLC.AuthorizeHelpers import AuthorizeHelpers
16
17 class DeleteSliceTag(Method):
18     """
19     Deletes the specified slice or sliver attribute.
20
21     Attributes may require the caller to have a particular role in
22     order to be deleted. Users may only delete attributes of
23     slices or slivers of which they are members. PIs may only delete
24     attributes of slices or slivers at their sites, or of which they
25     are members. Admins may delete attributes of any slice or sliver.
26
27     Returns 1 if successful, faults otherwise.
28     """
29
30     roles = ['admin', 'pi', 'user', 'tech', 'node']
31
32     accepts = [
33         Auth(),
34         SliceTag.fields['slice_tag_id']
35         ]
36
37     returns = Parameter(int, '1 if successful')
38
39     def call(self, auth, slice_tag_id):
40         slice_tags = SliceTags(self.api, [slice_tag_id])
41         if not slice_tags:
42             raise PLCInvalidArgument("No such slice attribute")
43         slice_tag = slice_tags[0]
44
45         tag_type_id = slice_tag['tag_type_id']
46         tag_type = TagTypes (self.api,[tag_type_id])[0]
47
48         slices = Slices(self.api, [slice_tag['slice_id']])
49         if not slices:
50             raise PLCInvalidArgument("No such slice %d"%slice_tag['slice_id'])
51         slice = slices[0]
52
53         assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
54
55         # check authorizations
56         node_id_or_hostname=slice_tag['node_id']
57         nodegroup_id_or_name=slice_tag['nodegroup_id']
58         slice.caller_may_write_tag(self.api,self.caller,tag_type,node_id_or_hostname,nodegroup_id_or_name)
59
60         slice_tag.delete()
61         self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
62
63         return 1