new functions
authorMark Huang <mlhuang@cs.princeton.edu>
Mon, 23 Oct 2006 19:27:35 +0000 (19:27 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Mon, 23 Oct 2006 19:27:35 +0000 (19:27 +0000)
PLC/Methods/AddConfFileToNode.py [new file with mode: 0644]
PLC/Methods/SliceCreate.py [new file with mode: 0644]
PLC/Methods/SliceDelete.py [new file with mode: 0644]

diff --git a/PLC/Methods/AddConfFileToNode.py b/PLC/Methods/AddConfFileToNode.py
new file mode 100644 (file)
index 0000000..eff9a52
--- /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.Nodes import Node, Nodes
+from PLC.Auth import PasswordAuth
+
+class AddConfFileToNode(Method):
+    """
+    Adds a configuration file to the specified node. If the node 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(Node.fields['node_id'],
+              Node.fields['hostname'])
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+    event_type = 'AddTo'
+    object_type = 'ConfFile'
+    object_ids = []
+
+    def call(self, auth, conf_file_id, node_id_or_hostname):
+       # 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
+       nodes = Nodes(self.api, [node_id_or_hostname])
+       if not nodes:
+               raise PLCInvalidArgument, "No such node"
+       node = nodes.values()[0]
+       
+       # Link configuration file to node
+        if node['node_id'] not in conf_file['node_ids']:
+            conf_file.add_node(node)
+
+        # Log affected objects
+        self.object_ids = [conf_file_id, node['node_id']]
+
+        return 1
diff --git a/PLC/Methods/SliceCreate.py b/PLC/Methods/SliceCreate.py
new file mode 100644 (file)
index 0000000..a749454
--- /dev/null
@@ -0,0 +1,8 @@
+from PLC.Methods.AddSlice import AddSlice
+
+class SliceCreate(AddSlice):
+    """
+    Deprecated. See AddSlice.
+    """
+
+    status = "deprecated"
diff --git a/PLC/Methods/SliceDelete.py b/PLC/Methods/SliceDelete.py
new file mode 100644 (file)
index 0000000..b009cc4
--- /dev/null
@@ -0,0 +1,8 @@
+from PLC.Methods.DeleteSlice import DeleteSlice
+
+class SliceDelete(DeleteSlice):
+    """
+    Deprecated. See DeleteSlice.
+    """
+
+    status = "deprecated"