d5d57c90170b48a6f7e8b02b110624eec905edb4
[plcapi.git] / PLC / Methods / DeleteTagType.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.TagTypes import TagType, TagTypes
8 from PLC.Auth import Auth
9
10 class DeleteTagType(Method):
11     """
12     Deletes the specified node tag type.
13
14     Returns 1 if successful, faults otherwise.
15     """
16
17     roles = ['admin']
18
19     accepts = [
20         Auth(),
21         Mixed(TagType.fields['tag_type_id'],
22               TagType.fields['tagname']),
23         ]
24
25     returns = Parameter(int, '1 if successful')
26
27
28     def call(self, auth, tag_type_id_or_name):
29         tag_types = TagTypes(self.api, [tag_type_id_or_name])
30         if not tag_types:
31             raise PLCInvalidArgument, "No such node tag type"
32         tag_type = tag_types[0]
33
34         tag_type.delete()
35         self.object_ids = [tag_type['tag_type_id']]
36
37         return 1