[libvirt-users] libvirt connections

Matthias Bolte matthias.bolte at googlemail.com
Wed Mar 31 09:00:22 UTC 2010


2010/3/31  <brandlk at mathematik.uni-marburg.de>:
> Hello,
>
> I'm working with libvirt version 0.7.7 and encountered some problems with
> ssh connections to the xen hypervisor:
>
> - if the hypervisor is not running libvirt.open("xen+ssh://host") doesn't
> time out put keeps trying to connect to host on port 8000.
> I've tried with the following test program:
>
> try:
>   conn = libvirt.open("xen+ssh://host")
> except:
>   print "failed"
>   sys.exit(1)
>
> However: after aborting the program with Ctrl-C I get the exception.
>
> - I want to close all libvirt connections at the end, but closing the
> connections does not close the ssh - nc connections libvirt opens in the
> background to talk to the hypervisor. I have to manually delete all domain
> objects as well to get the pending ssh - nc connections closed. I can keep
> on using the domain object, even if I closed the connection before.
> Is this behaviour intended?

This behavior is intended. Connection and domain objects are
refcounted. If you open a connection conn it starts with a refcount of
1. When you request a domain object using conn, then the refcount of
that connection is increased by 1. Upon destruction of the domain
object the refcount of conn is decreased again by 1.

Now if you call close on conn or get rid of the python reference by
assigning None to conn, then the connection is not closed immediately,
only the refcount is decreased by 1. The connection gets closed when
its refcount reaches zero. This happens if you close the connection
_and_ free all domain, network, interface objects etc. that you
requested using that connection.

Matthias




More information about the libvirt-users mailing list