- now using event_objects to log affected objects
[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 Auth
6
7 can_update = lambda (field, value): field not in \
8              ['conf_file_id', '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 the new conf_file_id (> 0) 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         Auth(),
24         conf_file_fields
25         ]
26
27     returns = Parameter(int, 'New conf_file_id (> 0) if successful')
28
29
30     def call(self, auth, conf_file_fields):
31         conf_file_fields = dict(filter(can_update, conf_file_fields.items()))
32         conf_file = ConfFile(self.api, conf_file_fields)
33         conf_file.sync()
34
35         self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
36
37         return conf_file['conf_file_id']