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.Nodes import Node, Nodes
6 from PLC.Auth import Auth
8 class AddConfFileToNode(Method):
10 Adds a configuration file to the specified node. If the node is
11 already linked to the configuration file, no errors are returned.
13 Returns 1 if successful, faults otherwise.
20 ConfFile.fields['conf_file_id'],
21 Mixed(Node.fields['node_id'],
22 Node.fields['hostname'])
25 returns = Parameter(int, '1 if successful')
27 def call(self, auth, conf_file_id, node_id_or_hostname):
28 # Get configuration file
29 conf_files = ConfFiles(self.api, [conf_file_id])
31 raise PLCInvalidArgument("No such configuration file")
32 conf_file = conf_files[0]
35 nodes = Nodes(self.api, [node_id_or_hostname])
37 raise PLCInvalidArgument("No such node")
40 if node['peer_id'] is not None:
41 raise PLCInvalidArgument("Not a local node")
43 # Link configuration file to node
44 if node['node_id'] not in conf_file['node_ids']:
45 conf_file.add_node(node)
47 # Log affected objects
48 self.event_objects = {'ConfFile': [conf_file_id],
49 'Node': [node['node_id']] }