Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
v2v: -o glance: set all properties during creation (RHBZ#1374405)
The glance client v1.0.0 defaults to the Image v2 API: this means that
an image can be referenced only by its UUID, and not anymore by the name
as well (which does not need to be unique).  This caused our glance
invocation to set the properties for the newly created image to fail,
since we are using the name as identifier.

Instead of first creating the image and then setting all the properties
for it, set all the properties when creating the image: other than being
simpler, it also avoid parsing the output of the 'glance image-create'
command for the UUID ('id') of the image.
  • Loading branch information
ptoscano committed Sep 13, 2016
1 parent 5714439 commit 1497a9f
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions v2v/output_glance.ml
Expand Up @@ -73,12 +73,6 @@ object
if i == 0 then source.s_name
else sprintf "%s-disk%d" source.s_name (i+1) in

let cmd = [ "glance"; "image-create"; "--name"; name;
"--disk-format=" ^ target_format;
"--container-format=bare"; "--file"; target_file ] in
if run_command cmd <> 0 then
error (f_"glance: image upload to glance failed, see earlier errors");

(* Set the properties (ie. metadata). *)
let min_ram = source.s_memory /^ 1024L /^ 1024L in
let properties = [
Expand Down Expand Up @@ -114,26 +108,18 @@ object
| x, 0 -> ("os_version", string_of_int x) :: properties
| x, y -> ("os_version", sprintf "%d.%d" x y) :: properties in

(* Glance doesn't appear to check the properties. *)
let cmd = [ "glance"; "image-update"; "--min-ram";
Int64.to_string min_ram ] @
let cmd = [ "glance"; "image-create"; "--name"; name;
"--disk-format=" ^ target_format;
"--container-format=bare"; "--file"; target_file;
"--min-ram"; Int64.to_string min_ram ] @
(List.flatten
(List.map (
fun (k, v) ->
[ "--property"; sprintf "%s=%s" k v ]
) properties
)) @
[ name ] in
if run_command cmd <> 0 then (
warning (f_"glance: failed to set image properties (ignored)");
(* Dump out the image properties so the user can set them. *)
eprintf "Image properties:\n";
eprintf " --min-ram %Ld\n" min_ram;
List.iter (
fun (k, v) ->
eprintf " --property %s=%s" (quote k) (quote v)
) properties
)
)) in
if run_command cmd <> 0 then
error (f_"glance: image upload to glance failed, see earlier errors");
) targets
end

Expand Down

2 comments on commit 1497a9f

@cts-dev
Copy link

@cts-dev cts-dev commented on 1497a9f May 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file we need to edit located? I cannot find it anywhere on the FS ... I think I'm missing something :)

@rwmjones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No one monitors the proprietary github comments system. Moved to mailing list: https://www.redhat.com/archives/libguestfs/2017-May/msg00049.html

Please sign in to comment.