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