[prev in list] [next in list] [prev in thread] [next in thread]
List: libguestfs
Subject: [Libguestfs] [PATCH 4/5] v2v: -o libvirt: Convert xpath_to_* to use xpath convenience functions.
From: "Richard W.M. Jones" <rjones () redhat ! com>
Date: 2015-08-28 13:19:09
Message-ID: 1440767950-18537-5-git-send-email-rjones () redhat ! com
[Download RAW message or body]
---
v2v/output_libvirt.ml | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index f5d82b0..0255e15 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -342,23 +342,18 @@ class output_libvirt oc output_pool = object
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
-
- let xpath_to_string expr default =
- let obj = Xml.xpath_eval_expression xpathctx expr in
- if Xml.xpathobj_nr_nodes obj < 1 then default
- else (
- let node = Xml.xpathobj_node obj 0 in
- Xml.node_as_string node
- )
- in
+ let xpath_string = xpath_string xpathctx in
(* We can only output to a pool of type 'dir' (directory). *)
- let pool_type = xpath_to_string "/pool/@type" "" in
- if pool_type <> "dir" then
+ if xpath_string "/pool/@type" <> Some "dir" then
error (f_"-o libvirt: output pool '%s' is not a directory (type='dir'). See \
virt-v2v(1) section \"OUTPUT TO LIBVIRT\"") output_pool;
- let target_path = xpath_to_string "/pool/target/path/text()" "" in
- if target_path = "" || not (is_directory target_path) then
- error (f_"-o libvirt: output pool '%s' has type='dir' but the \
/pool/target/path element either does not exist or is not a local directory. See \
virt-v2v(1) section \"OUTPUT TO LIBVIRT\"") output_pool; + let target_path =
+ match xpath_string "/pool/target/path/text()" with
+ | None ->
+ error (f_"-o libvirt: output pool '%s' does not have /pool/target/path \
element. See virt-v2v(1) section \"OUTPUT TO LIBVIRT\"") output_pool + | Some \
dir when not (is_directory dir) -> + error (f_"-o libvirt: output pool '%s' \
has type='dir' but the /pool/target/path element is not a local directory. See \
virt-v2v(1) section \"OUTPUT TO LIBVIRT\"") output_pool + | Some dir -> dir in
(* Set up the targets. *)
List.map (
--
2.5.0
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic