If the C<Sys::Virt> module is not available, then libvirt is bypassed,
and this function can only open disk images.
+The optional C<interface> parameter can be used to open devices with
+C<add_drive{,_ro}_with_if>. See
+L<Sys::Guestfs/guestfs_add_drive_with_if> for more details.
+
=cut
sub open_guest
my $rw = $params{rw};
my $address = $params{address};
+ my $interface = $params{interface};
my @images = ();
if (ref ($first) eq "ARRAY") {
my $g = Sys::Guestfs->new ();
foreach (@images) {
if ($rw) {
- $g->add_drive ($_);
+ if ($interface) {
+ $g->add_drive_with_if ($_, $interface);
+ } else {
+ $g->add_drive ($_);
+ }
} else {
- $g->add_drive_ro ($_);
+ if ($interface) {
+ $g->add_drive_ro_with_if ($_, $interface);
+ } else {
+ $g->add_drive_ro ($_);
+ }
}
}
=item package_format
(For Linux root partitions only)
-The package format used by the guest distribution. One of: "rpm", "dpkg".
+The package format used by the guest distribution. One of: "rpm", "deb".
=item package_management
$_ = $g->cat ("/etc/redhat-release");
if (/Fedora release (\d+)(?:\.(\d+))?/) {
+ chomp; $r->{product_name} = $_;
$r->{osdistro} = "fedora";
$r->{os_major_version} = "$1";
$r->{os_minor_version} = "$2" if(defined($2));
}
elsif (/(Red Hat Enterprise Linux|CentOS|Scientific Linux)/) {
+ chomp; $r->{product_name} = $_;
+
my $distro = $1;
if($distro eq "Red Hat Enterprise Linux") {
$r->{osdistro} = "redhat-based";
}
} elsif ($g->is_file ("/etc/debian_version")) {
- $r->{package_format} = "dpkg";
+ $r->{package_format} = "deb";
$r->{package_management} = "apt";
$_ = $g->cat ("/etc/debian_version");
if (/(\d+)\.(\d+)/) {
+ chomp; $r->{product_name} = $_;
$r->{osdistro} = "debian";
$r->{os_major_version} = "$1";
$r->{os_minor_version} = "$2";
Operating system distribution, eg. "debian".
+=item product_name
+
+Free text product name.
+
=item major_version
Operating system major version, eg. "4".
my $r = shift;
$r->{os} = $r->{root}->{fsos} if exists $r->{root}->{fsos};
+ $r->{product_name} = $r->{root}->{product_name}
+ if exists $r->{root}->{product_name};
$r->{distro} = $r->{root}->{osdistro} if exists $r->{root}->{osdistro};
$r->{major_version} = $r->{root}->{os_major_version}
if exists $r->{root}->{os_major_version};
(["rpm",
"-q", "-a",
"--qf", "%{name} %{epoch} %{version} %{release} %{arch}\n"]);
+ @lines = sort @lines;
foreach (@lines) {
if (m/^(.*) (.*) (.*) (.*) (.*)$/) {
my $epoch = $2;
push @apps, $app
}
}
+ } elsif (defined $package_format && $package_format eq "deb") {
+ my @lines = $g->command_lines
+ (["dpkg-query",
+ "-f", '${Package} ${Version} ${Architecture} ${Status}\n',
+ "-W"]);
+ @lines = sort @lines;
+ foreach (@lines) {
+ if (m/^(.*) (.*) (.*) (.*) (.*) (.*)$/) {
+ if ( $6 eq "installed" ) {
+ my $app = {
+ name => $1,
+ version => $2,
+ arch => $3
+ };
+ push @apps, $app
+ }
+ }
+ }
}
} elsif ($osn eq "windows") {
# XXX
# For every kernel we find, inspect it and add to $os->{kernels}
my $grub = _find_grub_prefix($g, $os);
+ my $grub_conf = "/etc/grub.conf";
+
+ # Debian and other's have no /etc/grub.conf:
+ if ( ! -f "$grub_conf" ) {
+ $grub_conf = "$grub/grub/menu.lst";
+ }
my @boot_configs;
my @configs = ();
# Get all configurations from grub
foreach my $bootable
- ($g->aug_match("/files/etc/grub.conf/title"))
+ ($g->aug_match("/files/$grub_conf/title"))
{
my %config = ();
$config{title} = $g->aug_get($bootable);
# Add the default configuration
eval {
- $boot{default} = $g->aug_get("/files/etc/grub.conf/default");
+ $boot{default} = $g->aug_get("/files/$grub_conf/default");
};
if($@) {
warn __"No grub default specified";