Product SiteDocumentation Site

7.4.2. Undefining an interface configuration

The undefine method completely and permanently removes the configuration for the given interface from the host's configuration files. If you want to recreate this configuration again in the future, you should invoke the XMLDesc method and save the string prior to the undefine.

Example 7.13. Undefining br0 interface after saving its XML data

# Example-12.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)

iface = conn.interfaceLookupByName('br0')

# get the xml prior to undefining the interface
xml = iface.XMLDesc(0)
# now undefine the interface
iface.undefine()
# the interface is now undefined and the iface variable is no longer be usable

conn.close()
exit(0)