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;
$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);
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);
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;
$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 (),
});
# Finished.
-#$delete_output_on_exit = 0;
+$delete_output_on_exit = 0;
print "\n";
print "OVF written to $ovf_file\n";
print "\n";