Re: [libvirt] [PATCH v2 4/9] virConnectBaselineCPU public API

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

 



On Thu, Feb 11, 2010 at 04:43:54PM +0100, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
> ---
>  include/libvirt/libvirt.h.in    |   18 +++++++++++++
>  python/generator.py             |    1 +
>  python/libvirt-override-api.xml |    7 +++++
>  python/libvirt-override.c       |   52 +++++++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms         |    1 +
>  5 files changed, 79 insertions(+), 0 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index 99a5c45..260505e 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -1769,6 +1769,24 @@ int virConnectCompareCPU(virConnectPtr conn,
>                           unsigned int flags);
>  
>  
> +/**
> + * virConnectBaselineCPU:
> + *
> + * @conn: virConnect connection
> + * @ncpus: number of CPUs in xmlCPUs
> + * @xmlCPUs: array of XML descriptions of host CPUs
> + * @flags: fine-tuning flags
> + *
> + * Computes the most feature-rich CPU which is compatible with all given
> + * host CPUs.
> + *
> + * Returns XML description of the computed CPU or NULL on error.
> + */
> +char *virConnectBaselineCPU(virConnectPtr conn,
> +                            const char **xmlCPUs,
> +                            unsigned int ncpus,
> +                            unsigned int flags);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> diff --git a/python/generator.py b/python/generator.py
> index 4182219..37c0169 100755
> --- a/python/generator.py
> +++ b/python/generator.py
> @@ -308,6 +308,7 @@ skip_impl = (
>      'virEventRegisterImpl',
>      'virNodeListDevices',
>      'virNodeDeviceListCaps',
> +    'virConnectBaselineCPU',
>  )
>  
>  
> diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
> index 3d8f46c..76a6fd5 100644
> --- a/python/libvirt-override-api.xml
> +++ b/python/libvirt-override-api.xml
> @@ -231,5 +231,12 @@
>        <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
>        <return type='str *' info='the list of Names of None in case of error'/>
>      </function>
> +    <function name='virConnectBaselineCPU' file='python'>
> +      <info>Computes the most feature-rich CPU which is compatible with all given host CPUs.</info>
> +      <return type='char *' info='XML description of the computed CPU or NULL on error.'/>
> +      <arg name='conn' type='virConnectPtr' info='virConnect connection'/>
> +      <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>
>    </symbols>
>  </api>
> diff --git a/python/libvirt-override.c b/python/libvirt-override.c
> index d90a763..a71766a 100644
> --- a/python/libvirt-override.c
> +++ b/python/libvirt-override.c
> @@ -2019,6 +2019,57 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
>      return(py_retval);
>  }
>  
> +
> +static PyObject *
> +libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
> +                              PyObject *args) {
> +    PyObject *pyobj_conn;
> +    PyObject *list;
> +    virConnectPtr conn;
> +    unsigned int flags;
> +    const char **xmlcpus = NULL;
> +    int ncpus = 0;
> +    char *base_cpu;
> +    PyObject *pybase_cpu;
> +
> +    if (!PyArg_ParseTuple(args, (char *)"OOi:virConnectBaselineCPU",
> +                          &pyobj_conn, &list, &flags))
> +        return(NULL);
> +    conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
> +
> +    if (PyList_Check(list)) {
> +        int i;
> +
> +        ncpus = PyList_Size(list);
> +        if ((xmlcpus = malloc(ncpus * sizeof(*xmlcpus))) == NULL)
> +            return VIR_PY_INT_FAIL;
> +
> +        for (i = 0; i < ncpus; i++) {
> +            xmlcpus[i] = PyString_AsString(PyList_GetItem(list, i));
> +            if (xmlcpus[i] == NULL)
> +                return VIR_PY_INT_FAIL;
> +        }
> +    }
> +
> +    LIBVIRT_BEGIN_ALLOW_THREADS;
> +    base_cpu = virConnectBaselineCPU(conn, xmlcpus, ncpus, flags);
> +    LIBVIRT_END_ALLOW_THREADS;
> +
> +    free(xmlcpus);
> +
> +    if (base_cpu == NULL)
> +        return VIR_PY_INT_FAIL;
> +
> +    pybase_cpu = PyString_FromString(base_cpu);
> +    free(base_cpu);
> +
> +    if (pybase_cpu == NULL)
> +        return VIR_PY_INT_FAIL;
> +
> +    return pybase_cpu;
> +}
> +
> +
>  /*******************************************
>   * Helper functions to avoid importing modules
>   * for every callback
> @@ -2734,6 +2785,7 @@ static PyMethodDef libvirtMethods[] = {
>      {(char *) "virSecretSetValue", libvirt_virSecretSetValue, METH_VARARGS, NULL},
>      {(char *) "virConnectListInterfaces", libvirt_virConnectListInterfaces, METH_VARARGS, NULL},
>      {(char *) "virConnectListDefinedInterfaces", libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
> +    {(char *) "virConnectBaselineCPU", libvirt_virConnectBaselineCPU, METH_VARARGS, NULL},
>      {NULL, NULL, 0, NULL}
>  };
>  
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index aa062e4..152aae4 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -353,6 +353,7 @@ LIBVIRT_0.7.7 {
>      global:
>          virDomainAttachDeviceFlags;
>          virDomainDetachDeviceFlags;
> +        virConnectBaselineCPU;
>  } LIBVIRT_0.7.5;
>  
>  # .... define new API here using predicted next version number ....

  Looks fine though maybe a bit complex, it's the first time we add
an API taking a list of XML instances. But I guess with the expected
use case that's not a bad choice, we will gather the XML from the set
of nodes in the cluster.

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
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]