a single tag type for slice attributes, iterface settings, node tags and ilinks
[plcapi.git] / PLC / Methods / UpdateIlink.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 # $Revision: 9423 $
5 #
6
7 from PLC.Faults import *
8 from PLC.Method import Method
9 from PLC.Parameter import Parameter, Mixed
10 from PLC.Auth import Auth
11
12 from PLC.Ilinks import Ilink, Ilinks
13 from PLC.Interfaces import Interface, Interfaces
14
15 from PLC.Sites import Sites
16
17 class UpdateIlink(Method):
18     """
19     Updates the value of an existing ilink
20
21     Access rights depend on the tag type.
22
23     Returns 1 if successful, faults otherwise.
24     """
25
26     roles = ['admin', 'pi', 'tech', 'user']
27
28     accepts = [
29         Auth(),
30         Ilink.fields['ilink_id'],
31         Ilink.fields['value']
32         ]
33
34     returns = Parameter(int, '1 if successful')
35
36     object_type = 'Interface'
37
38     def call(self, auth, ilink_id, value):
39         ilinks = Ilinks(self.api, [ilink_id])
40         if not ilinks:
41             raise PLCInvalidArgument, "No such ilink %r"%ilink_id
42         ilink = ilinks[0]
43
44         if 'admin' not in self.caller['roles']:
45 #       # check permission : it not admin, is the user affiliated with the right site
46 #           # locate node
47 #           node = Nodes (self.api,[node['node_id']])[0]
48 #           # locate site
49 #           site = Sites (self.api, [node['site_id']])[0]
50 #           # check caller is affiliated with this site
51 #           if self.caller['person_id'] not in site['person_ids']:
52 #               raise PLCPermissionDenied, "Not a member of the hosting site %s"%site['abbreviated_site']
53             
54             required_min_role = tag_type ['min_role_id']
55             if required_min_role is not None and \
56                     min(self.caller['role_ids']) > required_min_role:
57                 raise PLCPermissionDenied, "Not allowed to modify the specified ilink, requires role %d",required_min_role
58
59         ilink['value'] = value
60         ilink.sync()
61
62         self.object_ids = [ilink['src_interface_id'],ilink['dst_interface_id']]
63         return 1