c31c181070cef45f7d4277bb996763c2772c98cd
[plcapi.git] / PLC / Methods / DeleteNetworkMethod.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.NetworkMethods import NetworkMethod, NetworkMethods
5 from PLC.Auth import Auth
6
7 class DeleteNetworkMethod(Method):
8     """
9     Deletes a network method.
10
11     WARNING: This will cause the deletion of all network interfaces
12     that use this method.
13
14     Returns 1 if successful, faults otherwise.
15     """
16
17     roles = ['admin']
18
19     accepts = [
20         Auth(),
21         NetworkMethod.fields['method']
22         ]
23
24     returns = Parameter(int, '1 if successful')
25    
26     event_type = 'Delete'
27     object_type = 'NetworkMethod'
28
29     def call(self, auth, name):
30         network_methods = NetworkMethods(self.api, [name])
31         if not network_methods:
32             raise PLCInvalidArgument, "No such network method"
33         network_method = network_methods[0]
34
35         network_method.delete()
36
37         return 1