[libvirt-users] Need help regarding perl sys::virt

Rawat, Vishwanath Vishwanath.Rawat at netapp.com
Tue Dec 18 10:43:32 UTC 2012


Hi Daniel,
	It means that libvirt (and other related) libs should be installed on both client and server?
 Client is the machine from where connection is made(using $uri) to Remote machine(server).

Regards,
Rawat

-----Original Message-----
From: Daniel P. Berrange [mailto:berrange at redhat.com] 
Sent: Tuesday, December 11, 2012 9:29 PM
To: Rawat, Vishwanath
Cc: libvirt-users at redhat.com
Subject: Re: [libvirt-users] Need help regarding perl sys::virt

On Tue, Dec 11, 2012 at 12:46:55PM +0000, Rawat, Vishwanath wrote:
> Hi,
>                 I wanted to use perl Sys::Virt (which uses libvirt) to remotely connect KVM hypervisor. As a start I tried following simple script(KVM.pl) but I am getting following error.
> First it will ask for authentication which I am providing to it manually then it fails. Do I need to do some configuration on KVM hypervisor before executing this script? Any help is appreciated.
> 
> bash-3.2$ perl KVM.pl
> root at 10.238.132.125's password:
> Unable to open connection to qemu+ssh://root@10.238.132.125/system?no_verify=1: End of file while reading data: Warning: Perm: Input/output error8.132.125' (RSA) to the list of known hosts.


This is showing that libvirt failed to connect to the remote host.
This is not likely to be related to the Perl bindings. You should check the same conection using virsh. eg

  virsh -c qemu+ssh://root@10.238.132.125/system?no_verify=1 uri

> Can't call method "list_domains" on an undefined value at KVM.pl line 21.

This error is because you failed to connect, but your script ignored the error and carried on running, instead of exiting.

> bash-3.2$
> 
> bash-3.2$ cat KVM.pl
> 
> use strict;
> use warnings;
> use Sys::Virt;
> use Data::Dump qw(dump);
> 
> my $user = "root";
> my $host = <some_host>;
> 
> my $uri = "qemu+ssh://root\@$host/system?no_verify=1";
> 
> my $vmm;
> eval {
>   $vmm = Sys::Virt->new(uri => $uri, readonly => 1); }; if ($@) {
>     print "Unable to open connection to $uri: " . $@->message . "\n";

You need to exit at this point, since you have no valid connection

> }


> 
> for my $dom ($vmm->list_domains, $vmm->list_defined_domains) {
>   ## see perldoc Sys::Virt::Domain
>   print "name: ", $dom->get_name, "\n";
>   print "uuid: ", $dom->get_uuid_string(), "\n";
>   ## $dom->get_info returns a hash reference
>   dump $dom->get_info;
>   print "\n";
> }
> 


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvirt-users mailing list