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

[Libguestfs] [PATCH v8 2/4] v2v: add function qemu_img_version to utils



The function returns version of qemu-img as a tuple (major, minor), or
the value (0,9) in case there was an error detecting the version.

Signed-off-by: Tomáš Golembiovský <tgolembi redhat com>
---
 v2v/utils.ml  | 21 +++++++++++++++++++++
 v2v/utils.mli |  5 +++++
 2 files changed, 26 insertions(+)

diff --git a/v2v/utils.ml b/v2v/utils.ml
index 17ad8a29c..896e16004 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -90,3 +90,24 @@ let du filename =
   match lines with
   | line::_ -> Int64.of_string line
   | [] -> invalid_arg filename
+
+let qemu_img_version () =
+  let lines = external_command "qemu-img --version" in
+  match lines with
+  | [] -> error ("'qemu-img --version' returned no output")
+  | line :: _ ->
+      let rex = Str.regexp
+        "qemu-img version \\([0-9]+\\)\\.\\([0-9]+\\)" in
+      if Str.string_match rex line 0 then (
+        try
+          int_of_string (Str.matched_group 1 line),
+          int_of_string (Str.matched_group 2 line)
+        with Failure _ ->
+          warning (f_"failed to parse qemu-img version(%S), assuming 0.9")
+            line;
+          0, 9
+      ) else (
+        warning (f_"failed to read qemu-img version(%S), assuming 0.9")
+          line;
+        0, 9
+      )
diff --git a/v2v/utils.mli b/v2v/utils.mli
index 5eacb4aec..a7f8b6e84 100644
--- a/v2v/utils.mli
+++ b/v2v/utils.mli
@@ -50,3 +50,8 @@ val du : string -> int64
 
     This can raise either [Failure] or [Invalid_argument] in case
     of errors. *)
+
+val qemu_img_version : unit -> int * int
+(** Returns version of qemu-img as a tuple (major, minor).
+
+    In case of error (0,9) is returned. *)
-- 
2.11.0


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