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.TagTypes import TagTypes, TagType
10 from PLC.Nodes import Node
11 from PLC.Slices import Slice, Slices
12 from PLC.SliceTags import SliceTag, SliceTags
13 from PLC.InitScripts import InitScript, InitScripts
15 from PLC.AuthorizeHelpers import AuthorizeHelpers
17 # need to import so the core classes get decorated with caller_may_write_tag
18 from PLC.AuthorizeHelpers import AuthorizeHelpers
20 class UpdateSliceTag(Method):
22 Updates the value of an existing slice or sliver attribute.
24 Users may only update attributes of slices or slivers of which
25 they are members. PIs may only update attributes of slices or
26 slivers at their sites, or of which they are members. Admins may
27 update attributes of any slice or sliver.
29 Returns 1 if successful, faults otherwise.
32 roles = ['admin', 'pi', 'user', 'node']
36 SliceTag.fields['slice_tag_id'],
37 Mixed(SliceTag.fields['value'],
38 InitScript.fields['name'])
41 returns = Parameter(int, '1 if successful')
43 def call(self, auth, slice_tag_id, value):
44 slice_tags = SliceTags(self.api, [slice_tag_id])
46 raise PLCInvalidArgument("No such slice attribute")
47 slice_tag = slice_tags[0]
49 tag_type_id = slice_tag['tag_type_id']
50 tag_type = TagTypes (self.api,[tag_type_id])[0]
52 slices = Slices(self.api, [slice_tag['slice_id']])
54 raise PLCInvalidArgument("No such slice %d"%slice_tag['slice_id'])
57 assert slice_tag['slice_tag_id'] in slice['slice_tag_ids']
59 # check authorizations
60 node_id_or_hostname=slice_tag['node_id']
61 nodegroup_id_or_name=slice_tag['nodegroup_id']
62 slice.caller_may_write_tag(self.api,self.caller,tag_type,node_id_or_hostname,nodegroup_id_or_name)
64 if slice_tag['tagname'] in ['initscript']:
65 initscripts = InitScripts(self.api, {'enabled': True, 'name': value})
67 raise PLCInvalidArgument("No such plc initscript")
69 slice_tag['value'] = str(value)
71 self.event_objects = {'SliceTag': [slice_tag['slice_tag_id']]}