Product SiteDocumentation Site

3.4.7. getURI

The getURI method can be used to obtain the URI for the current connection. While this is typically the same string that was passed into the open call, the underlying driver can sometimes canonicalize the string. This method will return the canonical version. If successful, it returns a URI string. If an error occurred, None will be returned instead. The following code demonstrates the use of getURI:

Example 3.18. Using virConnectGetURI

# Example-17.py
#!/usr/bin/env python3
import sys
import libvirt

conn = None
try:
    conn = libvirt.open("qemu:///system")
except libvirt.libvirtError as e:
    print(repr(e), file=sys.stderr)
    exit(1)

uri = conn.getURI()
print('Canonical URI: '+uri)

conn.close()
exit(0)