9d333a4b7beba961d9baa2c2dbd91d1f2155729f
[plcapi.git] / PLC / Methods / DeleteInterfaceTag.py
1 #
2 # Thierry Parmentelat - INRIA
3 #
4 from PLC.Faults import *
5 from PLC.Method import Method
6 from PLC.Parameter import Parameter, Mixed
7 from PLC.Auth import Auth
8
9 from PLC.Sites import Sites
10 from PLC.Nodes import Nodes
11 from PLC.Interfaces import Interface, Interfaces
12 from PLC.TagTypes import TagType, TagTypes
13 from PLC.InterfaceTags import InterfaceTag, InterfaceTags
14
15 class DeleteInterfaceTag(Method):
16     """
17     Deletes the specified interface setting
18
19     Admins have full access.  Non-admins need to 
20     (1) have at least one of the roles attached to the tagtype, 
21     and (2) belong in the same site as the tagged subject.
22
23     Returns 1 if successful, faults otherwise.
24     """
25
26     roles = ['admin', 'pi', 'user', 'tech']
27
28     accepts = [
29         Auth(),
30         InterfaceTag.fields['interface_tag_id']
31         ]
32
33     returns = Parameter(int, '1 if successful')
34
35     def call(self, auth, interface_tag_id):
36         interface_tags = InterfaceTags(self.api, [interface_tag_id])
37         if not interface_tags:
38             raise PLCInvalidArgument, "No such interface tag %r"%interface_tag_id
39         interface_tag = interface_tags[0]
40
41         tag_type_id = interface_tag['tag_type_id']
42         tag_type = TagTypes (self.api,[tag_type_id])[0]
43
44         interfaces = Interfaces (self.api, interface_tag['interface_id'])
45         if not interfaces:
46             raise PLCInvalidArgument, "No such interface %d"%interface_tag['interface_id']
47         interface=interfaces[0]
48
49         # check authorizations
50         interface.caller_may_write_tag(self.api,self.caller,tag_type)
51
52         interface_tag.delete()
53         self.object_ids = [interface_tag['interface_tag_id']]
54
55         return 1