- Change .py files to use 4-space indents and no hard tab characters.
[plcapi.git] / PLC / Methods / AddConfFile.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.ConfFiles import ConfFile, ConfFiles
7 from PLC.Auth import Auth
8
9 can_update = lambda (field, value): field not in \
10              ['conf_file_id', 'node_ids', 'nodegroup_ids']
11
12 class AddConfFile(Method):
13     """
14     Adds a new node configuration file. Any fields specified in
15     conf_file_fields are used, otherwise defaults are used.
16
17     Returns the new conf_file_id (> 0) if successful, faults otherwise.
18     """
19
20     roles = ['admin']
21
22     conf_file_fields = dict(filter(can_update, ConfFile.fields.items()))
23
24     accepts = [
25         Auth(),
26         conf_file_fields
27         ]
28
29     returns = Parameter(int, 'New conf_file_id (> 0) if successful')
30
31
32     def call(self, auth, conf_file_fields):
33         conf_file_fields = dict(filter(can_update, conf_file_fields.items()))
34         conf_file = ConfFile(self.api, conf_file_fields)
35         conf_file.sync()
36
37         self.event_objects = {'ConfFile': [conf_file['conf_file_id']]}
38
39         return conf_file['conf_file_id']