[libvirt] [PATCH 6/8] api: Add API to get domain title and description

Peter Krempa pkrempa at redhat.com
Wed Jan 18 14:24:03 UTC 2012


This patch add a helper API as a counterpart to virDomainSetDescription
to allow easy getting of the <description> and <title> fields from
domain's config.
---
 include/libvirt/libvirt.h.in |    3 +++
 src/driver.h                 |    4 ++++
 src/libvirt.c                |   40 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    1 +
 src/remote/remote_driver.c   |    1 +
 src/remote/remote_protocol.x |   12 +++++++++++-
 6 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 40e0032..04a2050 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1415,6 +1415,9 @@ int                     virDomainSetDescription(virDomainPtr domain,
                                                 const char *description,
                                                 unsigned int flags);

+char                    *virDomainGetDescription(virDomainPtr domain,
+                                                 unsigned int flags);
+
 /*
  * XML domain description
  */
diff --git a/src/driver.h b/src/driver.h
index afb8f3c..59718cb 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -797,6 +797,9 @@ typedef int
     (*virDrvDomainSetDescription)(virDomainPtr dom,
                                   const char *description,
                                   unsigned int flags);
+typedef char *
+    (*virDrvDomainGetDescription)(virDomainPtr dom,
+                                  unsigned int flags);

 /**
  * _virDriver:
@@ -967,6 +970,7 @@ struct _virDriver {
     virDrvDomainSetBlockIoTune domainSetBlockIoTune;
     virDrvDomainGetBlockIoTune domainGetBlockIoTune;
     virDrvDomainSetDescription domainSetDescription;
+    virDrvDomainGetDescription domainGetDescription;
 };

 typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index 177d52d..99514b7 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8798,6 +8798,46 @@ error:
 }

 /**
+ * virDomainGetDescription:
+ * @domain: a domain object
+ * @flags: bitwise-OR of virDomainDescriptionFlags
+ *
+ * Gets the domain description field or title field depending on the flags
+ * parameter.
+ *
+ * Returns NULL on error or the requested description field on success. The
+ * caller must free the returned pointer.
+ */
+char *
+virDomainGetDescription(virDomainPtr domain,
+                        unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "flags=%x", flags);
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        goto error;
+    }
+
+    conn = domain->conn;
+
+    if (conn->driver->domainGetDescription) {
+        char *ret;
+        if (!(ret = conn->driver->domainGetDescription(domain, flags)))
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return NULL;
+}
+
+/**
  * virNodeGetSecurityModel:
  * @conn: a connection object
  * @secmodel: pointer to a virSecurityModel structure
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 882b746..62d19a2 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -519,6 +519,7 @@ LIBVIRT_0.9.9 {
 LIBVIRT_0.9.10 {
     global:
         virDomainSetDescription;
+        virDomainGetDescription;
 } LIBVIRT_0.9.9;

 # .... define new API here using predicted next version number ....
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 4d64bc9..c3ff1c7 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4751,6 +4751,7 @@ static virDriver remote_driver = {
     .domainSetNumaParameters = remoteDomainSetNumaParameters, /* 0.9.9 */
     .domainGetNumaParameters = remoteDomainGetNumaParameters, /* 0.9.9 */
     .domainSetDescription = remoteDomainSetDescription, /* 0.9.10 */
+    .domainGetDescription = remoteDomainGetDescription, /* 0.9.10 */
 };

 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index ad3e12f..c2fe40a 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1101,6 +1101,15 @@ struct remote_domain_set_description_args {
     unsigned int flags;
 };

+struct remote_domain_get_description_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
+
+struct remote_domain_get_description_ret {
+    remote_string xml;
+};
+
 struct remote_domain_block_job_abort_args {
     remote_nonnull_domain dom;
     remote_nonnull_string path;
@@ -2660,7 +2669,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255, /* skipgen skipgen */
     REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256, /* autogen autogen */
     REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */
-    REMOTE_PROC_DOMAIN_SET_DESCRIPTION = 258 /* autogen autogen */
+    REMOTE_PROC_DOMAIN_SET_DESCRIPTION = 258, /* autogen autogen */
+    REMOTE_PROC_DOMAIN_GET_DESCRIPTION = 259 /* autogen autogen */

     /*
      * Notice how the entries are grouped in sets of 10 ?
-- 
1.7.3.4




More information about the libvir-list mailing list