From: Mark Huang Date: Tue, 24 Oct 2006 13:29:28 +0000 (+0000) Subject: AddConfFileToNodeGroup X-Git-Tag: pycurl-7_13_1~472 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=b29e03efc1ee9b0616c058455faf3680a3fc37f3;p=plcapi.git AddConfFileToNodeGroup --- diff --git a/PLC/Methods/AddConfFileToNodeGroup.py b/PLC/Methods/AddConfFileToNodeGroup.py new file mode 100644 index 00000000..af4d574d --- /dev/null +++ b/PLC/Methods/AddConfFileToNodeGroup.py @@ -0,0 +1,52 @@ +from PLC.Faults import * +from PLC.Method import Method +from PLC.Parameter import Parameter, Mixed +from PLC.ConfFiles import ConfFile, ConfFiles +from PLC.NodeGroups import NodeGroup, NodeGroups +from PLC.Auth import PasswordAuth + +class AddConfFileToNodeGroup(Method): + """ + Adds a configuration file to the specified node group. If the node + group is already linked to the configuration file, no errors are + returned. + + Returns 1 if successful, faults otherwise. + """ + + roles = ['admin'] + + accepts = [ + PasswordAuth(), + ConfFile.fields['conf_file_id'], + Mixed(NodeGroup.fields['nodegroup_id'], + NodeGroup.fields['name']) + ] + + returns = Parameter(int, '1 if successful') + + event_type = 'AddTo' + object_type = 'ConfFile' + object_ids = [] + + def call(self, auth, conf_file_id, nodegroup_id_or_name): + # Get configuration file + conf_files = ConfFiles(self.api, [conf_file_id]) + if not conf_files: + raise PLCInvalidArgument, "No such configuration file" + conf_file = conf_files.values()[0] + + # Get node + nodegroups = NodeGroups(self.api, [nodegroup_id_or_name]) + if not nodegroups: + raise PLCInvalidArgument, "No such node group" + nodegroup = nodegroups.values()[0] + + # Link configuration file to node + if nodegroup['nodegroup_id'] not in conf_file['nodegroup_ids']: + conf_file.add_nodegroup(nodegroup) + + # Log affected objects + self.object_ids = [conf_file_id, nodegroup['nodegroup_id']] + + return 1