Set slice id as vcVHI_SYSNAME.
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 14 Apr 2008 18:52:38 +0000 (18:52 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 14 Apr 2008 18:52:38 +0000 (18:52 +0000)
python/vserverimpl.c

index 98125c9..0ef09a3 100644 (file)
@@ -666,6 +666,43 @@ vserver_set_runlevel(PyObject *self, PyObject *args)
   return NONE;
 }
 
+static PyObject *
+vserver_set_name(PyObject *self, PyObject *args)
+{
+  xid_t       ctx, slice_id;
+  char        buf[sizeof(long int)*3+2];
+  PyObject    *ret;
+
+  if (!PyArg_ParseTuple(args, "II", &ctx, &slice_id))
+    return NULL;
+
+  name = snprintf(buf, sizeof(buf), "%d", slice_id); 
+
+  if (vc_set_vhi_name(ctx, vcVHI_SYSNAME, name, sizeof(name)) != 0) {
+    return PyErr_SetFromErrno(PyExc_OSError);
+  } else {
+    return NONE;
+  }
+}
+
+static PyObject *
+vserver_get_name(PyObject *self, PyObject *args)
+{
+  xid_t       ctx;
+  char        buf[sizeof(long int)*3+2];
+  PyObject    *ret;
+
+  if (!PyArg_ParseTuple(args, "I", &ctx))
+    return NULL;
+
+  if (vc_get_vhi_name(ctx, vcVHI_SYSNAME, buf, sizeof(buf)) !=0 ) {
+    ret = PyErr_SetFromErrno(PyExc_OSError);
+  } else {
+    ret = Py_BuildValue("i", atoi(buf));
+  }
+  return ret;
+}
+
 static PyMethodDef  methods[] = {
   { "chcontext", vserver_chcontext, METH_VARARGS,
     "chcontext to vserver with provided flags" },
@@ -705,6 +742,10 @@ static PyMethodDef  methods[] = {
     "Perform the umount2() system call" },
   { "setrunlevel", vserver_set_runlevel, METH_VARARGS,
     "Set the runlevel in utmp" },
+  { "setname", vserver_set_name, METH_VARARGS,
+    "Set the vcVHI_SYSNAME for a xid." },
+  { "getname", vserver_get_name, METH_VARARGS,
+    "Get the vcVHI_SYSNAME for a xid." },
   { NULL, NULL, 0, NULL }
 };