]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
python: add Python binding for virDomainPinVcpusFlags API
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Mon, 25 Jul 2011 07:00:11 +0000 (15:00 +0800)
committerDaniel Veillard <veillard@redhat.com>
Mon, 25 Jul 2011 07:00:11 +0000 (15:00 +0800)
This patch adds the Python bindings for virDomainPinVcpuFlags API.
* python/generator.py: add it to the generator skip list
* python/libvirt-override-api.xml: provide override description
* python/libvirt-override.c: provide override bindings implementation

python/generator.py
python/libvirt-override-api.xml
python/libvirt-override.c

index d0d3ae6e84a67939225572267d998e774afa85d4..672b38f7255133ee6f09dcb4d61a9895f29298e3 100755 (executable)
@@ -344,6 +344,7 @@ skip_impl = (
     'virDomainGetMemoryParameters',
     'virDomainGetVcpus',
     'virDomainPinVcpu',
+    'virDomainPinVcpuFlags',
     'virSecretGetValue',
     'virSecretSetValue',
     'virSecretGetUUID',
index 0dca045eb1e84383b937504e056d703424aeea64..4d9f54b556ee6b235af7962c531e3e1e7e4929b2 100644 (file)
       <arg name='vcpu' type='unsigned int' info='virtual CPU number'/>
       <arg name='cpumap' type='unsigned char *' info='pointer to a bit map of real CPUs (in 8-bit bytes) (IN) Each bit set to 1 means that corresponding CPU is usable. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit.'/>
     </function>
+    <function name='virDomainPinVcpuFlags' file='python'>
+      <info>Dynamically change the real CPUs which can be allocated to a virtual CPU. This function requires privileged access to the hypervisor.</info>
+      <return type='int' info='0 in case of success, -1 in case of failure.'/>
+      <arg name='domain' type='virDomainPtr' info='pointer to domain object, or NULL for Domain0'/>
+      <arg name='vcpu' type='unsigned int' info='virtual CPU number'/>
+      <arg name='cpumap' type='unsigned char *' info='pointer to a bit map of real CPUs (in 8-bit bytes) (IN) Each bit set to 1 means that corresponding CPU is usable. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit.'/>
+      <arg name='flags' type='int' info='flags to specify'/>
+    </function>
     <function name='virDomainSetSchedulerParameters' file='python'>
       <info>Change the scheduler parameters</info>
       <return type='int' info='-1 in case of error, 0 in case of success.'/>
index 22c4d1de65b0f8b7344468333be9ff5138d0d0e3..678840e0edd812cd0f2909372bec2a52fbd96c04 100644 (file)
@@ -736,6 +736,53 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED,
     return VIR_PY_INT_SUCCESS;
 }
 
+static PyObject *
+libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED,
+                              PyObject *args) {
+    virDomainPtr domain;
+    PyObject *pyobj_domain, *pycpumap, *truth;
+    virNodeInfo nodeinfo;
+    unsigned char *cpumap;
+    int cpumaplen, i, vcpu;
+    unsigned int flags;
+    int i_retval;
+
+    if (!PyArg_ParseTuple(args, (char *)"OiOi:virDomainPinVcpuFlags",
+                          &pyobj_domain, &vcpu, &pycpumap, &flags))
+        return(NULL);
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (i_retval < 0)
+        return VIR_PY_INT_FAIL;
+
+    cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
+    if ((cpumap = malloc(cpumaplen)) == NULL)
+        return VIR_PY_INT_FAIL;
+    memset(cpumap, 0, cpumaplen);
+
+    truth = PyBool_FromLong(1);
+    for (i = 0 ; i < VIR_NODEINFO_MAXCPUS(nodeinfo) ; i++) {
+        PyObject *flag = PyTuple_GetItem(pycpumap, i);
+        if (flag == truth)
+            VIR_USE_CPU(cpumap, i);
+        else
+            VIR_UNUSE_CPU(cpumap, i);
+    }
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+    Py_DECREF(truth);
+    free(cpumap);
+
+    if (i_retval < 0)
+        return VIR_PY_INT_FAIL;
+
+    return VIR_PY_INT_SUCCESS;
+}
 
 /************************************************************************
  *                                                                     *
@@ -4109,6 +4156,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetMemoryParameters", libvirt_virDomainGetMemoryParameters, METH_VARARGS, NULL},
     {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
     {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
+    {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
     {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
     {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
     {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},