Product SiteDocumentation Site

7.5.2. Deactivating an interface

The destroy method makes the given interface inactive ("down"). On success, it returns 0. If there is any problem making the interface active, -1 is returned.

Example 7.17. Temporarily bring down eth2, then bring it back up

# 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)