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.Nodes import Node
11 from PLC.Slices import Slice, Slices
12 from PLC.InitScripts import InitScript, InitScripts
14 from PLC.AuthorizeHelpers import AuthorizeHelpers
16 class UpdateSliceTag(Method):
18 Updates the value of an existing slice or sliver attribute.
20 Users may only update attributes of slices or slivers of which
21 they are members. PIs may only update attributes of slices or
22 slivers at their sites, or of which they are members. Admins may
23 update attributes of any slice or sliver.
25 Returns 1 if successful, faults otherwise.
28 roles = ['admin', 'pi', 'user', 'node']
32 SliceTag.fields['slice_tag_id'],
33 Mixed(SliceTag.fields['value'],
34 InitScript.fields['name'])
37 returns = Parameter(int, '1 if successful')
39 def call(self, auth, slice_tag_id, value):
40 slice_tags = SliceTags(self.api, [slice_tag_id])
42 raise PLCInvalidArgument, "No such slice attribute"
43 slice_tag = slice_tags[0]
45 slices = Slices(self.api, [slice_tag['slice_id']])
47 raise PLCInvalidArgument, "No such slice"
50 assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
52 if not isinstance(self.caller, Node):
53 if 'admin' not in self.caller['roles']:
54 if self.caller['person_id'] in slice['person_ids']:
56 elif 'pi' not in self.caller['roles']:
57 raise PLCPermissionDenied, "Not a member of the specified slice"
58 elif slice['site_id'] not in self.caller['site_ids']:
59 raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
61 if slice_tag['min_role_id'] is not None and \
62 min(self.caller['role_ids']) > slice_tag['min_role_id']:
63 raise PLCPermissionDenied, "Not allowed to update the specified attribute"
65 ### make node's min_role_id == PI min_role_id
67 if slice_tag['min_role_id'] is not None and node_role_id > slice_tag['min_role_id']:
68 raise PLCPermissionDenied, "Not allowed to update the specified slice attribute"
70 if slice_tag['tagname'] in ['initscript']:
71 initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
73 raise PLCInvalidArgument, "No such plc initscript"
75 slice_tag['value'] = unicode(value)
77 self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}