From: Richard W.M. Jones Date: Thu, 17 Sep 2015 14:23:40 +0000 (+0100) Subject: Fixes to import-to-ovirt.pl X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=9832f59f66bee3a7818f2c5a08c74b57b50e3af2;p=import-to-ovirt.git Fixes to import-to-ovirt.pl --- diff --git a/README b/README index 9b0a983..1efd74f 100644 --- a/README +++ b/README @@ -24,4 +24,7 @@ For instructions, read the script or do: Copyright (C) 2015 Richard W.M. Jones Copyright (C) 2015 Red Hat Inc. -Please see the file 'COPYING' for licensing information. +See the file 'COPYING' for licensing information. + +Send patches to the virt-tools mailing list: +https://www.redhat.com/mailman/listinfo/virt-tools-list diff --git a/import-to-ovirt.pl b/import-to-ovirt.pl index cb6c1db..9d443eb 100755 --- a/import-to-ovirt.pl +++ b/import-to-ovirt.pl @@ -23,7 +23,7 @@ use English; use Pod::Usage; use Getopt::Long; use File::Temp qw(tempdir); -use POSIX qw(_exit strftime); +use POSIX qw(_exit setgid setuid strftime); use XML::Writer; use Sys::Guestfs; @@ -216,6 +216,14 @@ if (!defined $name) { $name =~ s{\.[^.]+}{}; } +if ($vmtype =~ /^Desktop$/i) { + $vmtype = 0; +} elsif ($vmtype =~ /^Server$/i) { + $vmtype = 1; +} else { + die "$0: --vmtype parameter must be 'Desktop' or 'Server'\n" +} + # Open the guest in libguestfs so we can inspect it. my $g = Sys::Guestfs->new (); $g->add_drive_opts ($_, readonly => 1) foreach (@disks); @@ -363,12 +371,12 @@ sub run_as_vdsm if ($pid == 0) { # Child process. if ($EUID == 0) { - $GID = 36; - $UID = 36; + setgid (36); + setuid (36); } eval { &$fn () }; if ($@) { - print STDERR $@, "\n"; + print STDERR "$@\n"; _exit (1); } _exit (0); @@ -433,14 +441,13 @@ for ($i = 0; $i < @disks; ++$i) { chmod (0666, $output_file) or die "chmod: $output_file: $!"; }); print "Copying $input_file ...\n"; -# system ("qemu-img", "convert", "-p", -# $input_file, -# "-O", "qcow2", -# "-o", "compat=0.10", # for RHEL 6-based ovirt nodes -# $output_file) == 0 -# or die "qemu-img: $input_file: failed (status $?)"; -# push @real_sizes, -s $output_file; - push @real_sizes, 0; + system ("qemu-img", "convert", "-p", + $input_file, + "-O", "qcow2", + "-o", "compat=0.10", # for RHEL 6-based ovirt nodes + $output_file) == 0 + or die "qemu-img: $input_file: failed (status $?)"; + push @real_sizes, -s $output_file; my $size_in_sectors = $virtual_sizes[$i] / 512; @@ -544,8 +551,10 @@ for ($i = 0; $i < @disks; ++$i) $w->startTag ("Disk", [$ovf_ns, "diskId" ] => $vol_uuids[$i], - [$ovf_ns, "actual_size"] => $real_size_in_gb, - [$ovf_ns, "size"] => $virtual_size_in_gb, + [$ovf_ns, "actual_size"] => + sprintf ("%.0f", $real_size_in_gb), + [$ovf_ns, "size"] => + sprintf ("%.0f", $virtual_size_in_gb), [$ovf_ns, "fileRef"] => $href, [$ovf_ns, "parentRef"] => "", [$ovf_ns, "vm_snapshot_id"] => uuidgen (), @@ -767,7 +776,7 @@ run_as_vdsm (sub { }); # Finished. -#$delete_output_on_exit = 0; +$delete_output_on_exit = 0; print "\n"; print "OVF written to $ovf_file\n"; print "\n";