import dbus
import subprocess
import uuid

bus = dbus.SystemBus()

con = dbus.Dictionary({
    'connection': dbus.Dictionary({
        "id": "test",
        "type": "bond",
        "uuid": str(uuid.uuid1())
    }, signature="sv"),
    'bond': dbus.Dictionary({
        'interface-name': "bond"
    }, signature="sv"),
    "ipv4": dbus.Dictionary({
        "method": "auto"
    }, signature="sv")
}, signature="sa{sv}")

print "Creating connection"
settings = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings")
connection_path = settings.AddConnection(con, signature="a{sa{sv}}", dbus_interface="org.freedesktop.NetworkManager.Settings")
print

print "ip link show bond"
subprocess.Popen(["ip", "link", "show", "bond"])
print

print "Deleting connection"
connection = bus.get_object("org.freedesktop.NetworkManager", connection_path)
connection.Delete(dbus_interface="org.freedesktop.NetworkManager.Settings.Connection")
print

print "ip link show bond"
subprocess.Popen(["ip", "link", "show", "bond"])
print
