[Pkg-libvirt-commits] [libguestfs] 226/266: -o glance: Multiple fixes.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:42:07 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 94cffee541a329de081fbec78c96d1e753bef6fa
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sun Aug 31 11:35:58 2014 +0100

    -o glance: Multiple fixes.
    
    Now tested and working on a glance server.
    
    This fixes commit f01f641fbb1a29b5727c0443f3700b1c871ccfc9.
---
 v2v/cmdline.ml           |  6 +++---
 v2v/output_glance.ml     | 52 ++++++++++++++++++++++++++----------------------
 v2v/output_glance.mli    |  4 ++--
 v2v/test-v2v-o-glance.sh |  2 +-
 v2v/virt-v2v.pod         | 11 +++++-----
 5 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index c4b42dc..d2378f2 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -240,15 +240,15 @@ read the man page virt-v2v(1).
   let output =
     match output_mode with
     | `Glance ->
-      if output_storage = "" then
-        error (f_"-o glance: output image name was not specified, use '-os glance_image_name'");
       if output_conn <> None then
         error (f_"-o glance: -oc option cannot be used in this output mode");
+      if output_storage <> "" then
+        error (f_"-o glance: -os option cannot be used in this output mode");
       if vmtype <> None then
         error (f_"--vmtype option can only be used with '-o rhev'");
       if not do_copy then
         error (f_"--no-copy and '-o glance' cannot be used at the same time");
-      Output_glance.output_glance verbose output_storage
+      Output_glance.output_glance verbose
 
     | `Libvirt ->
       let output_storage =
diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml
index 6a34a9e..f04006d 100644
--- a/v2v/output_glance.ml
+++ b/v2v/output_glance.ml
@@ -24,7 +24,7 @@ open Common_utils
 open Types
 open Utils
 
-class output_glance verbose image_name =
+class output_glance verbose =
   (* Although glance can slurp in a stream from stdin, unfortunately
    * 'qemu-img convert' cannot write to a stream (although I guess
    * it could be implemented at least for raw).  Therefore we have
@@ -37,7 +37,7 @@ class output_glance verbose image_name =
 object
   inherit output verbose
 
-  method as_options = sprintf "-o glance -os %s" image_name
+  method as_options = "-o glance"
 
   method prepare_targets source targets =
     (* This does nothing useful except to check that the user has
@@ -64,7 +64,7 @@ object
     let { target_file = target_file; target_format = target_format } =
       List.hd targets in
     let cmd =
-      sprintf "glance image-create --name %s --disk-format=%s --container-format=bare %s"
+      sprintf "glance image-create --name %s --disk-format=%s --container-format=bare --file %s"
         (quote source.s_name) (quote target_format) target_file in
     if verbose then printf "%s\n%!" cmd;
     if Sys.command cmd <> 0 then
@@ -86,8 +86,6 @@ object
       "hypervisor_type", "kvm";
       "vm_mode", "hvm";
       "os_type", inspect.i_type;
-      "os_version",
-      sprintf "%d.%d" inspect.i_major_version inspect.i_minor_version;
       "os_distro",
       (match inspect.i_distro with
       (* http://docs.openstack.org/grizzly/openstack-compute/admin/content/image-metadata.html *)
@@ -96,28 +94,34 @@ object
       | x -> x (* everything else is the same in libguestfs and OpenStack *)
       )
     ] in
+    let properties =
+      match inspect.i_major_version, inspect.i_minor_version with
+      | 0, 0 -> properties
+      | x, 0 -> ("os_version", string_of_int x) :: properties
+      | x, y -> ("os_version", sprintf "%d.%d" x y) :: properties in
 
-    (* Set the properties one at a time so if any fails we can give
-     * a warning message (failing to set properties is not fatal).
-     *)
+    (* Glance doesn't appear to check the properties. *)
     let cmd =
-      sprintf "glance image-update --min-ram %Ld %s"
-        min_ram (quote source.s_name) in
+      sprintf "glance image-update --min-ram %Ld %s %s"
+        min_ram
+        (String.concat " " (
+          List.map (
+            fun (k, v) ->
+              sprintf "--property %s=%s" (quote k) (quote v)
+          ) properties
+        ))
+        (quote source.s_name) in
     if verbose then printf "%s\n%!" cmd;
-    if Sys.command cmd <> 0 then
-      warning ~prog (f_"glance: failed to set --min-ram to %Ld (MB) (ignored)")
-        min_ram;
-
-    List.iter (
-      fun (k,v) ->
-        let cmd =
-          sprintf "glance image-update --property %s=%s %s"
-            (quote k) (quote v) (quote source.s_name) in
-        if verbose then printf "%s\n%!" cmd;
-        if Sys.command cmd <> 0 then
-          warning ~prog (f_"glance: failed to set property '%s' to '%s' (ignored)")
-            k v
-    ) properties
+    if Sys.command cmd <> 0 then (
+      warning ~prog (f_"glance: failed to set image properties (ignored)");
+      (* Dump out the image properties so the user can set them. *)
+      printf "Image properties:\n";
+      printf "  --min-ram %Ld\n" min_ram;
+      List.iter (
+	fun (k, v) ->
+	  printf "  --property %s=%s" (quote k) (quote v)
+      ) properties
+    )
 end
 
 let output_glance = new output_glance
diff --git a/v2v/output_glance.mli b/v2v/output_glance.mli
index b6bcd22..b10fa74 100644
--- a/v2v/output_glance.mli
+++ b/v2v/output_glance.mli
@@ -18,7 +18,7 @@
 
 (** [-o glance] target. *)
 
-val output_glance : bool -> string -> Types.output
-(** [output_glance verbose filename] creates and returns a new
+val output_glance : bool -> Types.output
+(** [output_glance verbose] creates and returns a new
     {!Types.output} object specialized for writing output to OpenStack
     glance. *)
diff --git a/v2v/test-v2v-o-glance.sh b/v2v/test-v2v-o-glance.sh
index 7f52343..4960f69 100755
--- a/v2v/test-v2v-o-glance.sh
+++ b/v2v/test-v2v-o-glance.sh
@@ -53,6 +53,6 @@ ln -sf "$(which echo)" glance
 
 $VG ./virt-v2v --debug-gc \
     -i libvirt -ic "$libvirt_uri" windows \
-    -o glance -os test
+    -o glance -on test
 
 rm glance
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
index 5f29a42..cd867fb 100644
--- a/v2v/virt-v2v.pod
+++ b/v2v/virt-v2v.pod
@@ -13,7 +13,7 @@ virt-v2v - Convert a guest to use KVM
 
  virt-v2v -i disk -o local -os /var/tmp disk.img
 
- virt-v2v -i disk disk.img -o glance -os glance_image_name
+ virt-v2v -i disk disk.img -o glance
 
 =head1 DESCRIPTION
 
@@ -105,7 +105,9 @@ user interface.
 Given a disk image from another hypervisor that you want to convert to
 run on OpenStack (only KVM-based OpenStack is supported), you can do:
 
- virt-v2v -i disk disk.img -o glance -os glance_image_name
+ virt-v2v -i disk disk.img -o glance
+
+To control the name of the image in glance, use the I<-on> option.
 
 =head2 Convert disk image to disk image
 
@@ -229,7 +231,8 @@ This option is not compatible with I<-o glance> for technical reasons.
 =item B<-o glance>
 
 Set the output method to OpenStack Glance.  In this mode the converted
-guest is uploaded to Glance as the image named in the I<-os> parameter.
+guest is uploaded to Glance.  You can control the image name by setting
+the I<-on> option.
 
 =item B<-o libvirt>
 
@@ -297,8 +300,6 @@ the output name is the same as the input name.
 
 The location of the storage for the converted guest.
 
-For I<-o glance>, this is the Glance image name.
-
 For I<-o libvirt>, this is a libvirt directory pool
 (see S<C<virsh pool-list>>).
 

-- 
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