Merge from trunk
[plcapi.git] / trunk / PLC / Methods / AddSliceInstantiation.py
diff --git a/trunk/PLC/Methods/AddSliceInstantiation.py b/trunk/PLC/Methods/AddSliceInstantiation.py
new file mode 100644 (file)
index 0000000..0374957
--- /dev/null
@@ -0,0 +1,29 @@
+from PLC.Faults import *
+from PLC.Method import Method
+from PLC.Parameter import Parameter, Mixed
+from PLC.SliceInstantiations import SliceInstantiation, SliceInstantiations
+from PLC.Auth import Auth
+
+class AddSliceInstantiation(Method):
+    """
+    Adds a new slice instantiation state.
+
+    Returns 1 if successful, faults otherwise.
+    """
+
+    roles = ['admin']
+
+    accepts = [
+        Auth(),
+        SliceInstantiation.fields['instantiation']
+        ]
+
+    returns = Parameter(int, '1 if successful')
+
+
+    def call(self, auth, name):
+        slice_instantiation = SliceInstantiation(self.api)
+        slice_instantiation['instantiation'] = name
+        slice_instantiation.sync(insert = True)
+
+        return 1