+ uri = vtype + ':///'
+ if uri not in connections:
+ # create connection
+ conn = libvirt.open(uri)
+ connections[uri] = conn
+ return conn
+ else:
+ # connection already available : check for health
+ conn = connections[uri]
+ # see if a reconnection is needed
+ try:
+ numDomains = conn.numOfDomains()
+ except:
+ logger.log("libvirt connection to {} looks broken - reconnecting".format(uri))
+ conn = libvirt.open(uri)
+ # if this fails then an expection is thrown outside of this function
+ numDomains = conn.numOfDomains()
+ return conn