X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=import-to-ovirt.pl;h=7052cce9c0b1114de18d849e24cde7518ac37aca;hb=refs%2Fheads%2Fmaster;hp=38bbde2b8a231106a2cc70eb8e7fd96b8d54a5bd;hpb=c4dc996ca7d21cba78f8279289f497980644018f;p=import-to-ovirt.git diff --git a/import-to-ovirt.pl b/import-to-ovirt.pl index 38bbde2..7052cce 100755 --- a/import-to-ovirt.pl +++ b/import-to-ovirt.pl @@ -229,9 +229,20 @@ if ($vmtype =~ /^Desktop$/i) { die "$0: --vmtype parameter must be 'Desktop' or 'Server'\n" } +# Does qemu-img generally work OK? +system ("qemu-img create -f qcow2 .test.qcow2 10M >/dev/null") == 0 + or die "qemu-img command not installed or not working\n"; + +# Does this version of qemu-img support compat=0.10? RHEL 6 +# did NOT support it. +my $qemu_img_supports_compat = 0; +system ("qemu-img create -f qcow2 -o compat=0.10 .test.qcow2 10M >/dev/null 2>&1") == 0 + and $qemu_img_supports_compat = 1; +unlink ".test.qcow2"; + # Open the guest in libguestfs so we can inspect it. my $g = Sys::Guestfs->new (); -$g->set_program ("virt-import-to-ovirt"); +eval { $g->set_program ("virt-import-to-ovirt"); }; $g->add_drive_opts ($_, readonly => 1) foreach (@disks); $g->launch (); my @roots = $g->inspect_os (); @@ -248,7 +259,7 @@ my $type = $g->inspect_get_type ($root); my $distro = $g->inspect_get_distro ($root); my $arch = $g->inspect_get_arch ($root); my $major_version = $g->inspect_get_major_version ($root); -my $minor_version = $g->inspect_get_major_version ($root); +my $minor_version = $g->inspect_get_minor_version ($root); my $product_name = $g->inspect_get_product_name ($root); my $product_variant = $g->inspect_get_product_variant ($root); @@ -447,10 +458,14 @@ for ($i = 0; $i < @disks; ++$i) { chmod (0666, $output_file) or die "chmod: $output_file: $!"; }); print "Copying $input_file ...\n"; + my @compat_option = (); + if ($qemu_img_supports_compat) { + @compat_option = ("-o", "compat=0.10") # for RHEL 6-based ovirt nodes + } system ("qemu-img", "convert", "-p", $input_file, "-O", "qcow2", - "-o", "compat=0.10", # for RHEL 6-based ovirt nodes + @compat_option, $output_file) == 0 or die "qemu-img: $input_file: failed (status $?)"; push @real_sizes, -s $output_file; @@ -495,8 +510,9 @@ my %prefix_map = ( ); my @forced_ns_decls = keys %prefix_map; +my $ovf = ""; my $w = XML::Writer->new ( - OUTPUT => "self", + OUTPUT => \$ovf, NAMESPACES => 1, PREFIX_MAP => \%prefix_map, FORCED_NS_DECLS => \@forced_ns_decls, @@ -767,8 +783,6 @@ $w->endTag ("Content"); $w->endTag ([$ovf_ns, "Envelope"]); $w->end (); -my $ovf = $w->to_string; - #print "OVF:\n$ovf\n"; my $ovf_dir = "$esd_uuid_dir/master/vms/$vm_uuid";