cd6fb56962ab54bd3aff4f8d623ff9660df07545
[plcapi.git] / PLC / Methods / DeletePCUProtocolType.py
1 # $Id$
2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.PCUProtocolTypes import PCUProtocolType, PCUProtocolTypes
6 from PLC.Auth import Auth
7
8 class DeletePCUProtocolType(Method):
9     """
10     Deletes a PCU protocol type.
11
12     Returns 1 if successful, faults otherwise.  
13     """
14
15     roles = ['admin']
16
17     accepts = [
18         Auth(),
19         PCUProtocolType.fields['pcu_protocol_type_id']
20         ]
21
22     returns = Parameter(int, '1 if successful')
23     
24
25     def call(self, auth, protocol_type_id):
26         protocol_types = PCUProtocolTypes(self.api, [protocol_type_id])
27         if not protocol_types:
28             raise PLCInvalidArgument, "No such pcu protocol type"
29
30         protocol_type = protocol_types[0]
31         protocol_type.delete()
32         self.event_objects = {'PCUProtocolType': [protocol_type['pcu_protocol_type_id']]}
33
34         return 1