AddConfFileToNodeGroup
authorMark Huang <mlhuang@cs.princeton.edu>
Tue, 24 Oct 2006 13:29:28 +0000 (13:29 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Tue, 24 Oct 2006 13:29:28 +0000 (13:29 +0000)
PLC/Methods/AddConfFileToNodeGroup.py [new file with mode: 0644]

diff --git a/PLC/Methods/AddConfFileToNodeGroup.py b/PLC/Methods/AddConfFileToNodeGroup.py
new file mode 100644 (file)
index 0000000..af4d574
--- /dev/null
@@ -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