X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=inspector%2Fvirt-inspector;h=ce9ac0eaabd9aa36a416a115532820a3c28d6db2;hb=c3ae17cc79a4e8dd4be0a3ae65d33384c175573b;hp=71a8884bc54320e028734207bf4a756ac945ed83;hpb=6548a876f367427404a0f9ce9a634b01e0ccac78;p=libguestfs.git diff --git a/inspector/virt-inspector b/inspector/virt-inspector index 71a8884..ce9ac0e 100755 --- a/inspector/virt-inspector +++ b/inspector/virt-inspector @@ -200,17 +200,17 @@ foreach $root (@roots) { # Basic OS fields. $xml->dataElement (root => canonicalize ($root)); - my ($s, $distro, $major_version); + my $s; $s = $g->inspect_get_type ($root); $xml->dataElement (name => $s) if $s ne "unknown"; $s = $g->inspect_get_arch ($root); $xml->dataElement (arch => $s) if $s ne "unknown"; - $distro = $g->inspect_get_distro ($root); - $xml->dataElement (distro => $distro) if $distro ne "unknown"; + $s = $g->inspect_get_distro ($root); + $xml->dataElement (distro => $s) if $s ne "unknown"; $s = $g->inspect_get_product_name ($root); $xml->dataElement (product_name => $s) if $s ne "unknown"; - $major_version = $g->inspect_get_major_version ($root); - $xml->dataElement (major_version => $major_version); + $s = $g->inspect_get_major_version ($root); + $xml->dataElement (major_version => $s); $s = $g->inspect_get_minor_version ($root); $xml->dataElement (minor_version => $s); @@ -226,7 +226,7 @@ foreach $root (@roots) { output_filesystems ($root); # Package format / management and applications. - output_applications ($root, $distro, $major_version); + output_applications ($root); $xml->endTag("operatingsystem"); @@ -305,6 +305,7 @@ sub output_filesystems $xml->startTag ("filesystems"); my @fses = $g->inspect_get_filesystems ($root); + @fses = sort @fses; foreach (@fses) { $xml->startTag ("filesystem", dev => canonicalize ($_)); @@ -338,8 +339,8 @@ sub output_filesystems The related elements Epackage_formatE, Epackage_managementE and EapplicationsE describe applications installed in the virtual machine. At the moment we are -only able to list RPMs installed, but in future we will support other -Linux distros and Windows. +only able to list RPMs and Debian packages installed, but in future we +will support other Linux distros and Windows. Epackage_formatE, if present, describes the packaging system used. Typical values would be C and C. @@ -348,7 +349,7 @@ Epackage_managementE, if present, describes the package manager. Typical values include C, C and C EapplicationsE lists the packages or applications -installed. At present this simply lists them by name: +installed. @@ -356,9 +357,12 @@ installed. At present this simply lists them by name: coreutils + 8.5 + 1 -In future we will also include the version here. +(The version and release fields may not be available for +some package types). =cut @@ -366,44 +370,24 @@ sub output_applications { local $_; my $root = shift; - my $distro = shift; - my $major_version = shift; # Based on the distro, take a guess at the package format # and package management. my ($package_format, $package_management); - if (defined $distro) { - if ($distro eq "debian") { - $package_format = "deb"; - $package_management = "apt"; - } - elsif ($distro eq "fedora") { - $package_format = "rpm"; - $package_management = "yum"; - } - elsif ($distro =~ /redhat/ || $distro =~ /rhel/) { - if ($major_version >= 5) { - $package_format = "rpm"; - $package_management = "yum"; - } else { - $package_format = "rpm"; - $package_management = "up2date"; - } - } - # else unknown. - } + $package_format = $g->inspect_get_package_format ($root); + $package_management = $g->inspect_get_package_management ($root); $xml->dataElement (package_format => $package_format) - if defined $package_format; + if $package_format ne "unknown"; $xml->dataElement (package_management => $package_management) - if defined $package_management; + if $package_management ne "unknown"; # Do we know how to get a list of applications? - if (defined $package_format) { - if ($package_format eq "rpm") { - output_applications_rpm ($root); - } - # else no we don't. + if ($package_format eq "rpm") { + output_applications_rpm ($root); + } + elsif ($package_format eq "deb") { + output_applications_deb ($root); } } @@ -459,6 +443,58 @@ sub output_applications_rpm } } +sub output_applications_deb +{ + local $_; + my $root = shift; + + my @applications; + + eval { + my ($fh, $filename) = tempfile (UNLINK => 1); + my $fddev = "/dev/fd/" . fileno ($fh); + $g->download ("/var/lib/dpkg/status", $fddev); + close $fh or die "close: $!"; + + # Read the file. Each package is separated by a blank line. + open FILE, $filename or die "$filename: $!"; + my ($name, $installed, $version, $release); + while () { + chomp; + if (/^Package: (.*)/) { + $name = $1; + } elsif (/^Status: .*\binstalled\b/) { + $installed = 1; + } elsif (/^Version: (.*?)-(.*)/) { + $version = $1; + $release = $2; + } elsif ($_ eq "") { + if ($installed && + defined $name && defined $version && defined $release) { + push @applications, [ $name, $version, $release ]; + } + $name = undef; + $installed = undef; + $version = undef; + $release = undef; + } + } + close FILE or die "$filename: $!"; + }; + if (!$@ && @applications > 0) { + @applications = sort { $a->[0] cmp $b->[0] } @applications; + $xml->startTag ("applications"); + foreach (@applications) { + $xml->startTag ("application"); + $xml->dataElement (name => $_->[0]); + $xml->dataElement (version => $_->[1]); + $xml->dataElement (release => $_->[2]); + $xml->endTag ("application"); + } + $xml->endTag ("applications"); + } +} + # The reverse of device name translation, see # BLOCK DEVICE NAMING in guestfs(3). sub canonicalize