2 # Thierry Parmentelat - INRIA
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
9 from PLC.SliceTags import SliceTag, SliceTags
10 from PLC.Slices import Slice, Slices
11 from PLC.Nodes import Node, Nodes
13 from PLC.AuthorizeHelpers import AuthorizeHelpers
15 class DeleteSliceTag(Method):
17 Deletes the specified slice or sliver attribute.
19 Attributes may require the caller to have a particular role in
20 order to be deleted. Users may only delete attributes of
21 slices or slivers of which they are members. PIs may only delete
22 attributes of slices or slivers at their sites, or of which they
23 are members. Admins may delete attributes of any slice or sliver.
25 Returns 1 if successful, faults otherwise.
28 roles = ['admin', 'pi', 'user', 'tech']
32 SliceTag.fields['slice_tag_id']
35 returns = Parameter(int, '1 if successful')
37 def call(self, auth, slice_tag_id):
38 slice_tags = SliceTags(self.api, [slice_tag_id])
40 raise PLCInvalidArgument, "No such slice attribute"
41 slice_tag = slice_tags[0]
43 slices = Slices(self.api, [slice_tag['slice_id']])
45 raise PLCInvalidArgument, "No such slice"
48 assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
50 if 'admin' not in self.caller['roles']:
51 if self.caller['person_id'] in slice['person_ids']:
53 elif 'pi' not in self.caller['roles']:
54 raise PLCPermissionDenied, "Not a member of the specified slice"
55 elif slice['site_id'] not in self.caller['site_ids']:
56 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
58 if slice_tag['min_role_id'] is not None and \
59 min(self.caller['role_ids']) > slice_tag['min_role_id']:
60 raise PLCPermissioinDenied, "Not allowed to delete the specified attribute"
63 self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}