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