(most) all functions now take SessionAuth in addition to PasswordAuth
[plcapi.git] / PLC / Methods / AddNetworkMethod.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 AddNetworkMethod(Method):
8     """
9     Adds a new network method.
10
11     Returns 1 if successful, faults otherwise.
12     """
13
14     roles = ['admin']
15
16     accepts = [
17         Auth(),
18         NetworkMethod.fields['method']
19         ]
20
21     returns = Parameter(int, '1 if successful')
22
23     event_type = 'Add'
24     object_type = 'NetworkMethod'
25
26     def call(self, auth, name):
27         network_method = NetworkMethod(self.api)
28         network_method['method'] = name
29         network_method.sync()
30
31         return 1