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