[PATCH v2 5/5] cpu_models: add Python bindings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Giuseppe Scrivano <gscrivan@xxxxxxxxxx>
---
 python/generator.py             |  2 +-
 python/libvirt-override-api.xml |  7 ++++++
 python/libvirt-override.c       | 56 +++++++++++++++++++++++++++++++++++++++++
 python/libvirt-override.py      | 11 ++++++++
 4 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/python/generator.py b/python/generator.py
index 0301403..ba2cc3e 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -250,6 +250,7 @@ lxc_functions_failed = []
 qemu_functions_failed = []
 functions_skipped = [
     "virConnectListDomains",
+    "virConnectGetCPUModelNames",
 ]
 lxc_functions_skipped = []
 qemu_functions_skipped = []
@@ -366,7 +367,6 @@ foreign_encoding_args = (
 # Class methods which are written by hand in libvirt.c but the Python-level
 # code is still automatically generated (so they are not in skip_function()).
 skip_impl = (
-    "virConnectGetCPUModelNames",
     'virConnectGetVersion',
     'virConnectGetLibVersion',
     'virConnectListDomainsID',
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 9a88215..1bceb05 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -476,6 +476,13 @@
       <arg name='xmlCPUs' type='const char **' info='array of XML descriptions of host CPUs'/>
       <arg name='flags' type='unsigned int' info='fine-tuning flags, currently unused, pass 0.'/>
     </function>
+    <function name='virConnectGetCPUModelNames' file='python'>
+      <info>Get the list of supported CPU models.</info>
+      <return type='char *' info='list of supported CPU models'/>
+      <arg name='conn' type='virConnectPtr' info='virConnect connection'/>
+      <arg name='arch' type='const char *' info='arch'/>
+      <arg name='flags' type='unsigned int' info='fine-tuning flags, currently unused, pass 0.'/>
+    </function>
     <function name='virDomainSnapshotListNames' file='python'>
       <info>collect the list of snapshot names for the given domain</info>
       <arg name='dom' type='virDomainPtr' info='pointer to the domain'/>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index d16b9a2..8536561 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2276,6 +2276,62 @@ libvirt_virConnectGetVersion(PyObject *self ATTRIBUTE_UNUSED,
     return PyInt_FromLong(hvVersion);
 }
 
+PyObject *
+libvirt_virConnectGetCPUModelNames(PyObject *self ATTRIBUTE_UNUSED,
+                                   PyObject *args)
+{
+    int c_retval;
+    virConnectPtr conn;
+    PyObject *rv, *pyobj_conn;
+    char **it, **models = NULL;
+    int flags = 0;
+    const char *arch = NULL;
+    unsigned int len;
+
+    if (!PyArg_ParseTuple(args, (char *)"Osi:virConnectGetCPUModelNames",
+                          &pyobj_conn, &arch, &flags))
+        return NULL;
+    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+
+    c_retval = virConnectGetCPUModelNames(conn, arch, &models, flags);
+
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_retval == -1)
+        return VIR_PY_INT_FAIL;
+
+    len = 0;
+    for (it = models; *it; it++)
+        len++;
+
+    if ((rv = PyList_New(len)) == NULL)
+        goto error;
+
+    len = 0;
+    for (it = models; *it; it++){
+        PyObject *str;
+        if ((str = PyString_FromString(*it)) == NULL)
+            goto error;
+
+        PyList_SET_ITEM(rv, len++, str);
+    }
+
+done:
+    if (models) {
+        for (it = models; *it; it++)
+            VIR_FREE(*it);
+        VIR_FREE(models);
+    }
+
+    return rv;
+
+error:
+    rv = VIR_PY_INT_FAIL;
+    goto done;
+}
+
 static PyObject *
 libvirt_virConnectGetLibVersion(PyObject *self ATTRIBUTE_UNUSED,
                                 PyObject *args)
diff --git a/python/libvirt-override.py b/python/libvirt-override.py
index ccfec48..3471a43 100644
--- a/python/libvirt-override.py
+++ b/python/libvirt-override.py
@@ -207,3 +207,14 @@ def virEventAddTimeout(timeout, cb, opaque):
     ret = libvirtmod.virEventAddTimeout(timeout, cbData)
     if ret == -1: raise libvirtError ('virEventAddTimeout() failed')
     return ret
+
+def getCPUModelNames(conn, arch, flags=0):
+    """
+    get the list of supported CPU models.
+    @conn: virConnect connection
+    @arch: Architecture
+    @flags: extra flags; not used yet, so callers should always pass 0.
+    """
+    ret = libvirtmod.virConnectGetCPUModelNames(conn._o, arch, flags)
+    if ret == None: raise libvirtError ('virConnectGetCPUModelNames() failed', conn=self)
+    return ret
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]