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.Nodes import Node
8 from PLC.Slices import Slice, Slices
9 from PLC.InitScripts import InitScript, InitScripts
10 from PLC.Auth import Auth
12 class UpdateSliceTag(Method):
14 Updates the value of an existing slice or sliver attribute.
16 Users may only update attributes of slices or slivers of which
17 they are members. PIs may only update attributes of slices or
18 slivers at their sites, or of which they are members. Admins may
19 update attributes of any slice or sliver.
21 Returns 1 if successful, faults otherwise.
24 roles = ['admin', 'pi', 'user', 'node']
28 SliceTag.fields['slice_tag_id'],
29 Mixed(SliceTag.fields['value'],
30 InitScript.fields['name'])
33 returns = Parameter(int, '1 if successful')
35 def call(self, auth, slice_tag_id, value):
36 slice_tags = SliceTags(self.api, [slice_tag_id])
38 raise PLCInvalidArgument, "No such slice attribute"
39 slice_tag = slice_tags[0]
41 slices = Slices(self.api, [slice_tag['slice_id']])
43 raise PLCInvalidArgument, "No such slice"
46 assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
48 if not isinstance(self.caller, Node):
49 if 'admin' not in self.caller['roles']:
50 if self.caller['person_id'] in slice['person_ids']:
52 elif 'pi' not in self.caller['roles']:
53 raise PLCPermissionDenied, "Not a member of the specified slice"
54 elif slice['site_id'] not in self.caller['site_ids']:
55 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
57 if slice_tag['min_role_id'] is not None and \
58 min(self.caller['role_ids']) > slice_tag['min_role_id']:
59 raise PLCPermissionDenied, "Not allowed to update the specified attribute"
61 ### make node's min_role_id == PI min_role_id
63 if slice_tag['min_role_id'] is not None and node_role_id > slice_tag['min_role_id']:
64 raise PLCPermissionDenied, "Not allowed to update the specified slice attribute"
66 if slice_tag['tagname'] in ['initscript']:
67 initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
69 raise PLCInvalidArgument, "No such plc initscript"
71 slice_tag['value'] = unicode(value)
73 self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}