]> git.proxmox.com Git - mirror_lxc.git/commitdiff
python3: binding update
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 16 Jan 2014 16:49:40 +0000 (11:49 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 16 Jan 2014 21:23:51 +0000 (16:23 -0500)
This adds rename(new_name) to the binding as well as two new const,
LXC_CLONE_KEEPBDEVTYPE and LXC_CLONE_MAYBE_SNAPSHOT.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/python-lxc/lxc.c
src/python-lxc/lxc/__init__.py

index 4381ab82937f93cd8723f44403ded9cbf7ed4c39..33b3e41823ed3c3131453c696dbd6d37a5c94864 100644 (file)
@@ -1037,6 +1037,23 @@ Container_reboot(Container *self, PyObject *args, PyObject *kwds)
     Py_RETURN_FALSE;
 }
 
+static PyObject *
+Container_rename(Container *self, PyObject *args, PyObject *kwds)
+{
+    char *new_name = NULL;
+    static char *kwlist[] = {"new_name", NULL};
+
+    if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|", kwlist,
+                                      &new_name))
+        return NULL;
+
+    if (self->container->rename(self->container, new_name)) {
+        Py_RETURN_TRUE;
+    }
+
+    Py_RETURN_FALSE;
+}
+
 static PyObject *
 Container_remove_device_node(Container *self, PyObject *args, PyObject *kwds)
 {
@@ -1529,6 +1546,12 @@ static PyMethodDef Container_methods[] = {
      "\n"
      "Ask the container to reboot."
     },
+    {"rename", (PyCFunction)Container_rename,
+     METH_VARARGS|METH_KEYWORDS,
+     "rename(new_name) -> boolean\n"
+     "\n"
+     "Rename the container."
+    },
     {"remove_device_node", (PyCFunction)Container_remove_device_node,
      METH_VARARGS|METH_KEYWORDS,
      "remove_device_node(src_path, dest_path) -> boolean\n"
@@ -1740,8 +1763,10 @@ PyInit__lxc(void)
     PYLXC_EXPORT_CONST(LXC_ATTACH_SET_PERSONALITY);
 
     /* clone: clone flags */
+    PYLXC_EXPORT_CONST(LXC_CLONE_KEEPBDEVTYPE);
     PYLXC_EXPORT_CONST(LXC_CLONE_KEEPMACADDR);
     PYLXC_EXPORT_CONST(LXC_CLONE_KEEPNAME);
+    PYLXC_EXPORT_CONST(LXC_CLONE_MAYBE_SNAPSHOT);
     PYLXC_EXPORT_CONST(LXC_CLONE_SNAPSHOT);
 
     /* create: create flags */
index c274a12a12e9c4bd95657d414bae9e3b7043bb9b..43fb07dbaf81347c7a03e94c2e7f04ee8a990f2b 100644 (file)
@@ -327,6 +327,18 @@ class Container(_lxc.Container):
 
         return ips
 
+    def rename(self, new_name):
+        """
+            Rename the container.
+            On success, returns the new Container object.
+            On failure, returns False.
+        """
+
+        if _lxc.Container.rename(self, new_name):
+            return Container(new_name)
+
+        return False
+
     def set_config_item(self, key, value):
         """
             Set a config key to a provided value.
@@ -460,8 +472,10 @@ LXC_ATTACH_REMOUNT_PROC_SYS = _lxc.LXC_ATTACH_REMOUNT_PROC_SYS
 LXC_ATTACH_SET_PERSONALITY = _lxc.LXC_ATTACH_SET_PERSONALITY
 
 # clone: clone flags
+LXC_CLONE_KEEPBDEVTYPE = _lxc.LXC_CLONE_KEEPBDEVTYPE
 LXC_CLONE_KEEPMACADDR = _lxc.LXC_CLONE_KEEPMACADDR
 LXC_CLONE_KEEPNAME = _lxc.LXC_CLONE_KEEPNAME
+LXC_CLONE_MAYBE_SNAPSHOT = _lxc.LXC_CLONE_MAYBE_SNAPSHOT
 LXC_CLONE_SNAPSHOT = _lxc.LXC_CLONE_SNAPSHOT
 
 # create: create flags