From 9832f59f66bee3a7818f2c5a08c74b57b50e3af2 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 17 Sep 2015 15:23:40 +0100 Subject: [PATCH] Fixes to import-to-ovirt.pl --- README | 5 ++++- import-to-ovirt.pl | 39 ++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 16 deletions(-) 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"; -- 1.8.3.1