Matthew Booth
2010-Jun-08 09:50 UTC
[Libguestfs] [PATCH 1/2] Target: Pass os description to create_guest
This will allow use of raw data from os description in addition to libvirt XML
when writing guest output.
---
lib/Sys/VirtV2V/Target/LibVirt.pm | 2 +-
lib/Sys/VirtV2V/Target/RHEV.pm | 2 +-
v2v/virt-v2v.pl | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/LibVirt.pm
b/lib/Sys/VirtV2V/Target/LibVirt.pm
index e21a21f..cb9961d 100644
--- a/lib/Sys/VirtV2V/Target/LibVirt.pm
+++ b/lib/Sys/VirtV2V/Target/LibVirt.pm
@@ -298,7 +298,7 @@ Create the guest in the target
sub create_guest
{
my $self = shift;
- my ($dom, $guestcaps) = @_;
+ my ($desc, $dom, $guestcaps) = @_;
my $vmm = $self->{vmm};
diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm
index 65800cd..7c96f0e 100644
--- a/lib/Sys/VirtV2V/Target/RHEV.pm
+++ b/lib/Sys/VirtV2V/Target/RHEV.pm
@@ -564,7 +564,7 @@ Create the guest in the target
sub create_guest
{
my $self = shift;
- my ($dom, $guestcaps) = @_;
+ my ($desc, $dom, $guestcaps) = @_;
# Get the name of the guest
my ($name) = $dom->findnodes('/domain/name/text()');
diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl
index bed69a0..96e89d1 100755
--- a/v2v/virt-v2v.pl
+++ b/v2v/virt-v2v.pl
@@ -378,7 +378,7 @@ my $guestcaps = Sys::VirtV2V::Converter->convert($g,
$guestos,
close_guest_handle();
-$target->create_guest($dom, $guestcaps);
+$target->create_guest($os, $dom, $guestcaps);
my ($name) = $dom->findnodes('/domain/name/text()');
$name = $name->getNodeValue();
--
1.7.0.1
Matthew Booth
2010-Jun-08 09:50 UTC
[Libguestfs] [PATCH 2/2] RHEV: Populate guest OS type correctly
Fixes RHBZ#596070
---
lib/Sys/VirtV2V/Target/RHEV.pm | 142 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 141 insertions(+), 1 deletions(-)
diff --git a/lib/Sys/VirtV2V/Target/RHEV.pm b/lib/Sys/VirtV2V/Target/RHEV.pm
index 7c96f0e..b3f1b2b 100644
--- a/lib/Sys/VirtV2V/Target/RHEV.pm
+++ b/lib/Sys/VirtV2V/Target/RHEV.pm
@@ -584,6 +584,8 @@ sub create_guest
my $vmuuid = Sys::VirtV2V::Target::RHEV::UUIDHelper::get_uuid();
+ my $ostype = _get_os_type($desc);
+
my $ovf = new XML::DOM::Parser->parse(<<EOF);
<ovf:Envelope
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
@@ -619,7 +621,7 @@ sub create_guest
<Section ovf:id="$vmuuid" ovf:required="false"
xsi:type="ovf:OperatingSystemSection_Type">
<Info>Guest Operating System</Info>
- <Description>Unassigned</Description>
+ <Description>$ostype</Description>
</Section>
<Section xsi:type="ovf:VirtualHardwareSection_Type">
@@ -683,6 +685,144 @@ EOF
$nfs->check_exit();
}
+# Work out how to describe the guest OS to RHEV. Possible values are:
+# Other
+# Not used
+#
+# RHEL3
+# RHEL3x64
+# os = linux
+# distro = rhel
+# major_version = 3
+#
+# RHEL4
+# RHEL4x64
+# os = linux
+# distro = rhel
+# major_version = 4
+#
+# RHEL5
+# RHEL5x64
+# os = linux
+# distro = rhel
+# major_version = 5
+#
+# OtherLinux
+# os = linux
+#
+# WindowsXP
+# os = windows
+# root->os_major_version = 5
+# root->os_minor_version = 1
+#
+# Windows2003
+# Windows2003x64
+# os = windows
+# root->os_major_version = 5
+# root->os_minor_version = 2
+# N.B. This also matches Windows 2003 R2, which there's no option for
+#
+# Windows2008
+# Windows2008x64
+# os = windows
+# root->os_major_version = 6
+# root->os_minor_version = 0
+# N.B. This also matches Vista, which there's no option for
+#
+# Windows7
+# Windows7x64
+# os = windows
+# root->os_major_version = 6
+# root->os_minor_version = 1
+# root->windows_installation_type = 'Client'
+#
+# Windows2008R2x64
+# os = windows
+# root->os_major_version = 6
+# root->os_minor_version = 1
+# root->windows_installation_type != 'Client'
+#
+# Unassigned
+# None of the above
+#
+# N.B. We deliberately fall through to Unassigned rather than Other, because
+# this represents a failure to match. We don't want to assert that the OS
is not
+# one of the above values in case we're wrong.
+sub _get_os_type
+{
+ my ($desc) = @_;
+
+ my $root = $desc->{root};
+ die ("No root device: ".Dumper($desc)) unless defined($root);
+
+ my $arch_suffix = '';
+ if ($root->{arch} eq 'x86_64') {
+ $arch_suffix = 'x64';
+ } elsif ($root->{arch} ne 'i386') {
+ warn (_user_message(__x("Unsupported architecture: {arch}",
+ arch => $root->{arch})));
+ return undef;
+ }
+
+ my $type;
+
+ $type = _get_os_type_linux($root, $arch_suffix)
+ if ($desc->{os} eq 'linux');
+ $type = _get_os_type_windows($root, $arch_suffix)
+ if ($desc->{os} eq 'windows');
+
+ return 'Unassigned' if (!defined($type));
+ return $type;
+}
+
+sub _get_os_type_windows
+{
+ my ($root, $arch_suffix) = @_;
+
+ my $major = $root->{os_major_version};
+ my $minor = $root->{os_major_version};
+
+ if ($major == 5 && $minor == 1) {
+ # RHEV doesn't differentiate Windows XP by architecture
+ return "WindowsXP";
+ }
+
+ if ($major == 5 && $minor == 2) {
+ return "Windows2003".$arch_suffix;
+ }
+
+ if ($major == 6 && $minor == 0) {
+ return "Windows2008".$arch_suffix;
+ }
+
+ if ($major == 6 && $minor == 1) {
+ if ($root->{windows_installation_type} eq 'Client') {
+ return "Windows7".$arch_suffix;
+ }
+
+ return "Windows2008R2".$arch_suffix;
+ }
+
+ warn (_user_message(__x("Unknown Windows version:
{major}.{minor}",
+ major => $major, minor => $minor)));
+ return undef;
+}
+
+sub _get_os_type_linux
+{
+ my ($root, $arch_suffix) = @_;
+
+ my $distro = $root->{osdistro};
+ my $major = $root->{os_major_version};
+
+ if ($distro eq 'rhel') {
+ return "RHEL".$major.$arch_suffix;
+ }
+
+ # Unlike Windows, Linux has its own fall-through option
+ return "OtherLinux";
+}
+
sub _format_time
{
my ($time) = @_;
--
1.7.0.1
Richard W.M. Jones
2010-Jun-08 15:12 UTC
[Libguestfs] [PATCH 1/2] Target: Pass os description to create_guest
On Tue, Jun 08, 2010 at 10:50:04AM +0100, Matthew Booth wrote:> This will allow use of raw data from os description in addition to libvirt XML > when writing guest output.Simple parameter passing change. ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Possibly Parallel Threads
- [PATCH 1/4] Check that we're not overwriting an existing Libvirt domain
- [PATCH 1/7] Push $desc creation into Sys::VirtConvert::Converter->convert
- [PATCH 1/2] Refactor guest and volume creation into Sys::VirtV2V::Target::LibVirt
- [PATCH] Split $os->{version} into $os->{major_version} and $os->{minor_version}
- [PATCH] Improve cleanup of libguestfs handle with Sys::VirtV2V::GuestfsHandle