1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.SliceAttributes import SliceAttribute, SliceAttributes
5 from PLC.Slices import Slice, Slices
6 from PLC.Nodes import Node, Nodes
7 from PLC.Auth import Auth
9 class DeleteSliceAttribute(Method):
11 Deletes the specified slice or sliver attribute.
13 Attributes may require the caller to have a particular role in
14 order to be deleted. Users may only delete attributes of
15 slices or slivers of which they are members. PIs may only delete
16 attributes of slices or slivers at their sites, or of which they
17 are members. Admins may delete attributes of any slice or sliver.
19 Returns 1 if successful, faults otherwise.
22 roles = ['admin', 'pi', 'user']
26 SliceAttribute.fields['slice_attribute_id']
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, slice_attribute_id):
32 slice_attributes = SliceAttributes(self.api, [slice_attribute_id])
33 if not slice_attributes:
34 raise PLCInvalidArgument, "No such slice attribute"
35 slice_attribute = slice_attributes[0]
37 slices = Slices(self.api, [slice_attribute['slice_id']])
39 raise PLCInvalidArgument, "No such slice"
42 assert slice_attribute['slice_attribute_id'] in slice['slice_attribute_ids']
44 if 'admin' not in self.caller['roles']:
45 if self.caller['person_id'] in slice['person_ids']:
47 elif 'pi' not in self.caller['roles']:
48 raise PLCPermissionDenied, "Not a member of the specified slice"
49 elif slice['site_id'] not in self.caller['site_ids']:
50 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
52 if slice_attribute['min_role_id'] is not None and \
53 min(self.caller['role_ids']) > slice_attribute['min_role_id']:
54 raise PLCPermissionDenied, "Not allowed to delete the specified attribute"
56 slice_attribute.delete()