[Libguestfs] [PATCH 12/67] sysprep: Allow -a URI options to be used (RHBZ#968875).

Richard W.M. Jones rjones at redhat.com
Sat Aug 24 11:04:12 UTC 2013


From: "Richard W.M. Jones" <rjones at redhat.com>

This allows you to sysprep a remote guest by doing eg:

  virt-sysprep -a ssh://remote.example.com/disk.img

(cherry picked from commit b65c1c667b26313abf312a7ab51f8bf947243d07)
---
 sysprep/Makefile.am      | 10 +++++++++-
 sysprep/main.ml          | 15 +++++++++++----
 sysprep/virt-sysprep.pod |  7 +++++++
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index 81ffcc7..fce639f 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -80,6 +80,9 @@ if HAVE_OCAML
 OBJECTS = \
 	$(top_builddir)/resize/common_gettext.cmx \
 	$(top_builddir)/resize/common_utils.cmx \
+	$(top_builddir)/fish/guestfish-uri.o \
+	$(top_builddir)/resize/uri-c.o \
+	$(top_builddir)/resize/uRI.cmx \
 	firstboot.cmx \
 	sysprep_operation.cmx \
 	$(patsubst %,sysprep_operation_%.cmx,$(operations)) \
@@ -98,10 +101,15 @@ endif
 OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX $(OCAMLPACKAGES)
 OCAMLOPTFLAGS = $(OCAMLCFLAGS)
 
+OCAMLCLIBS  = \
+	$(LIBXML2_LIBS) -lncurses \
+	-L../src/.libs -lutils \
+	-L../gnulib/lib/.libs -lgnu
+
 virt-sysprep: $(OBJECTS)
 	$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
 	  mlguestfs.cmxa -linkpkg $^ \
-	  -cclib -lncurses \
+	  -cclib '$(OCAMLCLIBS)' \
 	  $(OCAML_GCOV_LDFLAGS) \
 	  -o $@
 
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 63e4103..49b0eb3 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -50,9 +50,14 @@ let debug_gc, operations, g, selinux_relabel, quiet =
     printf "virt-sysprep %Ld.%Ld.%Ld%s\n"
       version.G.major version.G.minor version.G.release version.G.extra;
     exit 0
-  and add_file file =
+  and add_file arg =
+    let uri =
+      try URI.parse_uri arg
+      with Invalid_argument "URI.parse_uri" ->
+        eprintf "Error parsing URI '%s'. Look for error messages printed above.\n" arg;
+        exit 1 in
     let format = match !format with "auto" -> None | fmt -> Some fmt in
-    files := (file, format) :: !files
+    files := (uri, format) :: !files
   and set_domain dom =
     if !domain <> None then (
       eprintf (f_"%s: --domain option can only be given once\n") prog;
@@ -162,8 +167,10 @@ read the man page virt-sysprep(1).
     | files, None ->
       fun g readonly ->
         List.iter (
-          fun (file, format) ->
-            g#add_drive ~readonly ?format file
+          fun (uri, format) ->
+            let { URI.path = path; protocol = protocol;
+                  server = server; username = username } = uri in
+            g#add_drive ~readonly ?format ~protocol ?server ?username path
         ) files
   in
 
diff --git a/sysprep/virt-sysprep.pod b/sysprep/virt-sysprep.pod
index 1636770..73a3b29 100755
--- a/sysprep/virt-sysprep.pod
+++ b/sysprep/virt-sysprep.pod
@@ -54,6 +54,13 @@ Add I<file> which should be a disk image from a virtual machine.
 The format of the disk image is auto-detected.  To override this and
 force a particular format use the I<--format> option.
 
+=item B<-a URI>
+
+=item B<--add URI>
+
+Add a remote disk.  The URI format is compatible with guestfish.
+See L<guestfish(1)/ADDING REMOTE STORAGE>.
+
 =item B<-c> URI
 
 =item B<--connect> URI
-- 
1.8.3.1




More information about the Libguestfs mailing list