- change calling convention for Add slightly; if the Add function for
[plcapi.git] / PLC / Methods / AddConfFile.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.ConfFiles import ConfFile, ConfFiles
5 from PLC.Auth import PasswordAuth
6
7 can_update = lambda (field, value): field not in \
8              ['conf_file_id', 'source', 'dest', 'node_ids', 'nodegroup_ids']
9
10 class AddConfFile(Method):
11     """
12     Adds a new node configuration file. Any fields specified in
13     conf_file_fields are used, otherwise defaults are used.
14
15     Returns 1 if successful, faults otherwise.
16     """
17
18     roles = ['admin']
19
20     conf_file_fields = dict(filter(can_update, ConfFile.fields.items()))
21
22     accepts = [
23         PasswordAuth(),
24         conf_file_fields
25         ]
26
27     returns = Parameter(int, '1 if successful')
28
29     event_type = 'Add'
30     object_type = 'ConfFile'
31     object_ids = []
32
33     def call(self, auth, conf_file_fields):
34         conf_file_fields = dict(filter(can_update, conf_file_fields.items()))
35         conf_file = ConfFile(self.api, conf_file_fields)
36         conf_file.sync()
37
38         self.object_ids = [conf_file['conf_file_id']]
39
40         return 1