renaming SliceAttribute into SliceTag and InterfaceSetting into InterfaceTag
[plcapi.git] / PLC / Methods / DeleteSliceTag.py
1 g# $Id#
2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.SliceTags import SliceTag, SliceTags
6 from PLC.Slices import Slice, Slices
7 from PLC.Nodes import Node, Nodes
8 from PLC.Auth import Auth
9
10 class DeleteSliceTag(Method):
11     """
12     Deletes the specified slice or sliver attribute.
13
14     Attributes may require the caller to have a particular role in
15     order to be deleted. Users may only delete attributes of
16     slices or slivers of which they are members. PIs may only delete
17     attributes of slices or slivers at their sites, or of which they
18     are members. Admins may delete attributes of any slice or sliver.
19
20     Returns 1 if successful, faults otherwise.
21     """
22
23     roles = ['admin', 'pi', 'user']
24
25     accepts = [
26         Auth(),
27         SliceTag.fields['slice_tag_id']
28         ]
29
30     returns = Parameter(int, '1 if successful')
31
32     def call(self, auth, slice_tag_id):
33         slice_tags = SliceTags(self.api, [slice_tag_id])
34         if not slice_tags:
35             raise PLCInvalidArgument, "No such slice attribute"
36         slice_tag = slice_tags[0]
37
38         slices = Slices(self.api, [slice_tag['slice_id']])
39         if not slices:
40             raise PLCInvalidArgument, "No such slice"
41         slice = slices[0]
42
43         assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
44
45         if 'admin' not in self.caller['roles']:
46             if self.caller['person_id'] in slice['person_ids']:
47                 pass
48             elif 'pi' not in self.caller['roles']:
49                 raise PLCPermissionDenied, "Not a member of the specified slice"
50             elif slice['site_id'] not in self.caller['site_ids']:
51                 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
52
53             if slice_tag['min_role_id'] is not None and \
54                min(self.caller['role_ids']) > slice_tag['min_role_id']:
55                 raise PLCPermissioinDenied, "Not allowed to delete the specified attribute"
56
57         slice_tag.delete()
58         self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}
59
60         return 1