353509e05c1333aab810d398da066963f0f2cb39
[plcapi.git] / PLC / Methods / DeleteAddressType.py
1 # $Id$
2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.AddressTypes import AddressType, AddressTypes
6 from PLC.Auth import Auth
7
8 class DeleteAddressType(Method):
9     """
10     Deletes an address type.
11
12     Returns 1 if successful, faults otherwise.
13     """
14
15     roles = ['admin']
16
17     accepts = [
18         Auth(),
19         Mixed(AddressType.fields['address_type_id'],
20               AddressType.fields['name'])
21         ]
22
23     returns = Parameter(int, '1 if successful')
24
25
26     def call(self, auth, address_type_id_or_name):
27         address_types = AddressTypes(self.api, [address_type_id_or_name])
28         if not address_types:
29             raise PLCInvalidArgument, "No such address type"
30         address_type = address_types[0]
31         address_type.delete()
32         self.event_objects = {'AddressType': [address_type['address_type_id']]}
33
34         return 1