Blame SOURCES/0190-v2v-o-glance-set-all-properties-during-creation-RHBZ.patch

7af31e
From dfbc0114d8269d05e699d9f12e3176c29eb260d5 Mon Sep 17 00:00:00 2001
7af31e
From: Pino Toscano <ptoscano@redhat.com>
7af31e
Date: Tue, 13 Sep 2016 15:30:52 +0200
7af31e
Subject: [PATCH] v2v: -o glance: set all properties during creation
7af31e
 (RHBZ#1374405)
7af31e
7af31e
The glance client v1.0.0 defaults to the Image v2 API: this means that
7af31e
an image can be referenced only by its UUID, and not anymore by the name
7af31e
as well (which does not need to be unique).  This caused our glance
7af31e
invocation to set the properties for the newly created image to fail,
7af31e
since we are using the name as identifier.
7af31e
7af31e
Instead of first creating the image and then setting all the properties
7af31e
for it, set all the properties when creating the image: other than being
7af31e
simpler, it also avoid parsing the output of the 'glance image-create'
7af31e
command for the UUID ('id') of the image.
7af31e
7af31e
(cherry picked from commit 1497a9f722f9a3c4c75282fb19578573e3cc89db)
7af31e
---
7af31e
 v2v/output_glance.ml | 28 +++++++---------------------
7af31e
 1 file changed, 7 insertions(+), 21 deletions(-)
7af31e
7af31e
diff --git a/v2v/output_glance.ml b/v2v/output_glance.ml
7af31e
index 71f237c..d6c5727 100644
7af31e
--- a/v2v/output_glance.ml
7af31e
+++ b/v2v/output_glance.ml
7af31e
@@ -73,12 +73,6 @@ object
7af31e
           if i == 0 then source.s_name
7af31e
           else sprintf "%s-disk%d" source.s_name (i+1) in
7af31e
 
7af31e
-        let cmd = [ "glance"; "image-create"; "--name"; name;
7af31e
-                    "--disk-format=" ^ target_format;
7af31e
-                    "--container-format=bare"; "--file"; target_file ] in
7af31e
-        if run_command cmd <> 0 then
7af31e
-          error (f_"glance: image upload to glance failed, see earlier errors");
7af31e
-
7af31e
         (* Set the properties (ie. metadata). *)
7af31e
         let min_ram = source.s_memory /^ 1024L /^ 1024L in
7af31e
         let properties = [
7af31e
@@ -109,26 +103,18 @@ object
7af31e
           | x, 0 -> ("os_version", string_of_int x) :: properties
7af31e
           | x, y -> ("os_version", sprintf "%d.%d" x y) :: properties in
7af31e
 
7af31e
-        (* Glance doesn't appear to check the properties. *)
7af31e
-        let cmd = [ "glance"; "image-update"; "--min-ram";
7af31e
-                    Int64.to_string min_ram ] @
7af31e
+        let cmd = [ "glance"; "image-create"; "--name"; name;
7af31e
+                    "--disk-format=" ^ target_format;
7af31e
+                    "--container-format=bare"; "--file"; target_file;
7af31e
+                    "--min-ram"; Int64.to_string min_ram ] @
7af31e
                   (List.flatten
7af31e
                     (List.map (
7af31e
                        fun (k, v) ->
7af31e
                          [ "--property"; sprintf "%s=%s" k v ]
7af31e
                     ) properties
7af31e
-                  )) @
7af31e
-                  [ name ] in
7af31e
-        if run_command cmd <> 0 then (
7af31e
-          warning (f_"glance: failed to set image properties (ignored)");
7af31e
-          (* Dump out the image properties so the user can set them. *)
7af31e
-          eprintf "Image properties:\n";
7af31e
-          eprintf "  --min-ram %Ld\n" min_ram;
7af31e
-          List.iter (
7af31e
-	    fun (k, v) ->
7af31e
-	      eprintf "  --property %s=%s" (quote k) (quote v)
7af31e
-          ) properties
7af31e
-        )
7af31e
+                  )) in
7af31e
+        if run_command cmd <> 0 then
7af31e
+          error (f_"glance: image upload to glance failed, see earlier errors");
7af31e
       ) targets
7af31e
 end
7af31e
 
7af31e
-- 
7af31e
1.8.3.1
7af31e