[PATCH 2/8] Introduce new virDomainNormalizeXML API

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 include/libvirt/libvirt.h.in    |  5 ++++
 python/generator.py             |  1 +
 python/libvirt-override-api.xml |  7 ++++++
 python/libvirt-override.c       | 30 ++++++++++++++++++++++++
 src/driver.h                    |  7 ++++++
 src/libvirt.c                   | 51 +++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms         |  5 ++++
 7 files changed, 106 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index a47e33c..2aa63a3 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -5055,6 +5055,11 @@ int virDomainFSTrim(virDomainPtr dom,
                     unsigned long long minimum,
                     unsigned int flags);
 
+int virDomainNormalizeXML(virDomainPtr dom,
+                          const char *xmlIn,
+                          char **xmlOut,
+                          unsigned int flags);
+
 /**
  * virSchedParameterType:
  *
diff --git a/python/generator.py b/python/generator.py
index a91dde8..085f39d 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -460,6 +460,7 @@ skip_impl = (
     'virNodeGetCPUMap',
     'virDomainMigrate3',
     'virDomainMigrateToURI3',
+    'virDomainNormalizeXML',
 )
 
 lxc_skip_impl = (
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 9a88215..55554d6 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -602,5 +602,12 @@
       <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
       <arg name='flags' type='int' info='unused, pass 0'/>
     </function>
+    <function name='virDomainNormalizeXML' file='python'>
+      <info>Normalize XML snippets</info>
+      <return type='char *' info='Normalized XML'/>
+      <arg name='domain' type='virDomainPtr' info='a domain object'/>
+      <arg name='xml' type='const char *' info='XML to normalize'/>
+      <arg name='flags' type='unsigned int' info='an OR&apos;ed set of virDomainXMLFlags'/>
+    </function>
   </symbols>
 </api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index d16b9a2..1ad06da 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -7162,6 +7162,35 @@ cleanup:
 }
 
 
+static PyObject *
+libvirt_virDomainNormalizeXML(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
+    PyObject *py_retval = NULL;
+    virDomainPtr domain;
+    PyObject *pyobj_domain;
+    int c_retval;
+    char *xmlIn, *xmlOut;
+    unsigned int flags;
+
+    if (!PyArg_ParseTuple(args, (char *)"Ozi:virDomainNormalizeXML",
+                          &pyobj_domain, &xmlIn, &flags))
+        return NULL;
+
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    c_retval = virDomainNormalizeXML(domain, xmlIn, &xmlOut, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+
+    if (c_retval < 0)
+        goto cleanup;
+
+    py_retval = libvirt_charPtrWrap(xmlOut);
+
+cleanup:
+    return py_retval;
+}
+
+
 /************************************************************************
  *									*
  *			The registration stuff				*
@@ -7289,6 +7318,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
     {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL},
     {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL},
+    {(char *) "virDomainNormalizeXML", libvirt_virDomainNormalizeXML, METH_VARARGS, NULL},
     {NULL, NULL, 0, NULL}
 };
 
diff --git a/src/driver.h b/src/driver.h
index be64333..dcbee72 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1122,6 +1122,12 @@ typedef int
                                      unsigned int flags,
                                      int cancelled);
 
+typedef int
+(*virDrvDomainNormalizeXML)(virDomainPtr domain,
+                            const char *xmlIn,
+                            char **xmlOut,
+                            unsigned int flas);
+
 typedef struct _virDriver virDriver;
 typedef virDriver *virDriverPtr;
 
@@ -1332,6 +1338,7 @@ struct _virDriver {
     virDrvDomainMigratePerform3Params domainMigratePerform3Params;
     virDrvDomainMigrateFinish3Params domainMigrateFinish3Params;
     virDrvDomainMigrateConfirm3Params domainMigrateConfirm3Params;
+    virDrvDomainNormalizeXML domainNormalizeXML;
 };
 
 
diff --git a/src/libvirt.c b/src/libvirt.c
index 3f65f12..e5eb231 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -21967,3 +21967,54 @@ error:
     virDispatchError(dom->conn);
     return -1;
 }
+
+/**
+ * virDomainNormalizeXML:
+ * @domain: a domain object
+ * @xmlIn: XML to normalize
+ * @xmlOut: the result of normalization
+ * @flags: bitwise-OR of subset of virDomainXMLFlags
+ *
+ * Intruct libvirt to take @xmlIn, parse it and format again. This has effect
+ * that all returned values are formated as they would be a part of @dom. For
+ * example, if among passed @xmlIn and address='0x00008' occurs, it is
+ * formatted as address='0x08'. The result of normalization is returned in @xmlOut
+ * (automatically allocated array which is supposed to be freed by caller once
+ * no longer needed). However, if only validation of @xmlIn is desired, pass
+ * NULL as @xmlOut.
+ *
+ * Returns 0 on success -1 otherwise.
+ */
+int
+virDomainNormalizeXML(virDomainPtr domain,
+                      const char *xmlIn,
+                      char **xmlOut,
+                      unsigned int flags)
+{
+    int ret = -1;
+    VIR_DOMAIN_DEBUG(domain, "xmlIn=%s, xmlOut=%p, flags=%x",
+                     NULLSTR(xmlIn), xmlOut, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        goto error;
+    }
+
+    virCheckNonNullArgGoto(xmlIn, error);
+
+    if (domain->conn->driver->domainNormalizeXML) {
+        ret = domain->conn->driver->domainNormalizeXML(domain, xmlIn,
+                                                       xmlOut, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index bbdf78a..7246266 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -634,4 +634,9 @@ LIBVIRT_1.1.1 {
         virDomainSetMemoryStatsPeriod;
 } LIBVIRT_1.1.0;
 
+LIBVIRT_1.1.3 {
+    global:
+        virDomainNormalizeXML;
+} LIBVIRT_1.1.1;
+
 # .... define new API here using predicted next version number ....
-- 
1.8.1.5

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