[Pkg-libvirt-commits] [libguestfs] 188/266: v2v: Implement binding for `virsh pool-dumpxml'.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.

commit f527c22b009e2a7005b186db8889e553b935e9e6
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Tue Aug 26 17:48:02 2014 +0100

    v2v: Implement binding for `virsh pool-dumpxml'.
    
    Add a mini-binding to libvirt virStoragePoolGetXMLDesc to get the pool
    XML directly using the libvirt API.  Change existing external calls to
    `virsh pool-dumpxml' to use this API instead.
---
 v2v/domainxml-c.c     | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 v2v/domainxml.ml      |  1 +
 v2v/domainxml.mli     |  4 ++++
 v2v/output_libvirt.ml |  8 +-------
 4 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c
index fc2993d..b8d7d9a 100644
--- a/v2v/domainxml-c.c
+++ b/v2v/domainxml-c.c
@@ -114,6 +114,53 @@ v2v_dumpxml (value connv, value domnamev)
   CAMLreturn (retv);
 }
 
+value
+v2v_pool_dumpxml (value connv, value poolnamev)
+{
+  CAMLparam2 (connv, poolnamev);
+  CAMLlocal1 (retv);
+  const char *conn_uri = NULL;
+  const char *poolname;
+  virConnectPtr conn;
+  virStoragePoolPtr pool;
+  char *xml;
+
+  if (connv != Val_int (0))
+    conn_uri = String_val (Field (connv, 0)); /* Some conn */
+
+  /* We have to call the default authentication handler, not least
+   * since it handles all the PolicyKit crap.  However it also makes
+   * coding this simpler.
+   */
+  conn = virConnectOpenAuth (conn_uri, virConnectAuthPtrDefault, VIR_CONNECT_RO);
+  if (conn == NULL) {
+    if (conn_uri)
+      raise_error ("cannot open libvirt connection '%s'", conn_uri);
+    else
+      raise_error ("cannot open libvirt connection");
+  }
+
+  /* Look up the pool. */
+  poolname = String_val (poolnamev);
+
+  pool = virStoragePoolLookupByName (conn, poolname);
+  if (!pool) {
+    virConnectClose (conn);
+    raise_error ("cannot find libvirt pool '%s'", poolname);
+  }
+
+  xml = virStoragePoolGetXMLDesc (pool, 0);
+  virStoragePoolFree (pool);
+  virConnectClose (conn);
+  if (xml == NULL)
+    raise_error ("cannot fetch XML description of guest '%s'", poolname);
+
+  retv = caml_copy_string (xml);
+  free (xml);
+
+  CAMLreturn (retv);
+}
+
 #else /* !HAVE_LIBVIRT */
 
 value
@@ -122,4 +169,10 @@ v2v_dumpxml (value connv, value domv)
   caml_invalid_argument ("virt-v2v was compiled without libvirt support");
 }
 
+value
+v2v_pool_dumpxml (value connv, value poolv)
+{
+  caml_invalid_argument ("virt-v2v was compiled without libvirt support");
+}
+
 #endif /* !HAVE_LIBVIRT */
diff --git a/v2v/domainxml.ml b/v2v/domainxml.ml
index 03994f9..d240918 100644
--- a/v2v/domainxml.ml
+++ b/v2v/domainxml.ml
@@ -19,3 +19,4 @@
 (* [virsh dumpxml] but with non-broken authentication handling. *)
 
 external dumpxml : ?conn:string -> string -> string = "v2v_dumpxml"
+external pool_dumpxml : ?conn:string -> string -> string = "v2v_pool_dumpxml"
diff --git a/v2v/domainxml.mli b/v2v/domainxml.mli
index 6d58981..88d2d41 100644
--- a/v2v/domainxml.mli
+++ b/v2v/domainxml.mli
@@ -26,3 +26,7 @@
 val dumpxml : ?conn:string -> string -> string
 (** [dumpxml ?conn dom] returns the libvirt XML of domain [dom].
     The optional [?conn] parameter is the libvirt connection URI. *)
+
+val pool_dumpxml : ?conn:string -> string -> string
+(** [pool_dumpxml ?conn pool] returns the libvirt XML of pool [pool].
+    The optional [?conn] parameter is the libvirt connection URI. *)
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 383d874..d9dfbfc 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -211,13 +211,7 @@ class output_libvirt verbose oc output_pool = object
     (* Connect to output libvirt instance and check that the pool exists
      * and dump out its XML.
      *)
-    let cmd =
-      match oc with
-      | None -> sprintf "virsh pool-dumpxml %s" (quote output_pool)
-      | Some uri ->
-        sprintf "virsh -c %s pool-dumpxml %s" (quote uri) (quote output_pool) in
-    let lines = external_command ~prog cmd in
-    let xml = String.concat "\n" lines in
+    let xml = Domainxml.pool_dumpxml ?conn:oc output_pool in
     let doc = Xml.parse_memory xml in
     let xpathctx = Xml.xpath_new_context doc in
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list