- die __"open_guest: no libvirt support (install Sys::Virt, XML::XPath and XML::XPath::XMLParser)"
- unless exists $INC{"Sys/Virt.pm"} &&
- exists $INC{"XML/XPath.pm"} &&
- exists $INC{"XML/XPath/XMLParser.pm"};
-
- die __"open_guest: too many domains listed on command line"
- if @images > 1;
-
- $conn = Sys::Virt->new (readonly => 1, @_);
- die __"open_guest: cannot connect to libvirt" unless $conn;
-
- my @doms = $conn->list_defined_domains ();
- my $isitinactive = 1;
- unless ($readwrite) {
- # In the case where we want read-only access to a domain,
- # allow the user to specify an active domain too.
- push @doms, $conn->list_domains ();
- $isitinactive = 0;
- }
- foreach (@doms) {
- if ($_->get_name () eq $images[0]) {
- $dom = $_;
- last;
- }
- }
-
- unless ($dom) {
- if ($isitinactive) {
- die __x("{imagename} is not the name of an inactive libvirt domain\n",
- imagename => $images[0]);
- } else {
- die __x("{imagename} is not the name of a libvirt domain\n",
- imagename => $images[0]);
- }
- }
-
- # Get the names of the image(s).
- my $xml = $dom->get_xml_description ();
-
- my $p = XML::XPath->new (xml => $xml);
- my @disks = $p->findnodes ('//devices/disk/source/@dev');
- push (@disks, $p->findnodes ('//devices/disk/source/@file'));
-
- die __x("{imagename} seems to have no disk devices\n",
- imagename => $images[0])
- unless @disks;
-
- @images = map { $_->getData } @disks;
+ die __"open_guest: no libvirt support (install Sys::Virt, XML::XPath and XML::XPath::XMLParser)"
+ unless exists $INC{"Sys/Virt.pm"} &&
+ exists $INC{"XML/XPath.pm"} &&
+ exists $INC{"XML/XPath/XMLParser.pm"};
+
+ die __"open_guest: too many domains listed on command line"
+ if @images > 1;
+
+ my @libvirt_args = ();
+ push @libvirt_args, address => $address if defined $address;
+
+ $conn = Sys::Virt->new (readonly => 1, @libvirt_args);
+ die __"open_guest: cannot connect to libvirt" unless $conn;
+
+ my @doms = $conn->list_defined_domains ();
+ my $isitinactive = 1;
+ unless ($rw) {
+ # In the case where we want read-only access to a domain,
+ # allow the user to specify an active domain too.
+ push @doms, $conn->list_domains ();
+ $isitinactive = 0;
+ }
+ foreach (@doms) {
+ if ($_->get_name () eq $images[0]) {
+ $dom = $_;
+ last;
+ }
+ }
+
+ unless ($dom) {
+ if ($isitinactive) {
+ die __x("{imagename} is not the name of an inactive libvirt domain\n",
+ imagename => $images[0]);
+ } else {
+ die __x("{imagename} is not the name of a libvirt domain\n",
+ imagename => $images[0]);
+ }
+ }
+
+ # Get the names of the image(s).
+ my $xml = $dom->get_xml_description ();
+
+ my $p = XML::XPath->new (xml => $xml);
+ my @disks = $p->findnodes ('//devices/disk/source/@dev');
+ push (@disks, $p->findnodes ('//devices/disk/source/@file'));
+
+ die __x("{imagename} seems to have no disk devices\n",
+ imagename => $images[0])
+ unless @disks;
+
+ @images = map { $_->getData } @disks;