diff --git a/examples/python/dbus/checkpoint.py b/examples/python/dbus/checkpoint.py index 72a9a414dc..6e57f9c68b 100755 --- a/examples/python/dbus/checkpoint.py +++ b/examples/python/dbus/checkpoint.py @@ -20,36 +20,48 @@ import dbus, sys -# This example takes a device interface name as a parameter and tells -# NetworkManager to disconnect that device, closing down any network -# connection it may have - -if len(sys.argv) != 2: - raise Exception("Usage: %s " % sys.argv[0]) - -bus = dbus.SystemBus() +# This example takes a list of device interface names as a parameter +# and tells NetworkManager to create a checkpoint on those devices. It +# is then possible to restore or destroy the checkpoint. # Get a proxy for the base NetworkManager object +bus = dbus.SystemBus() proxy = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager") manager = dbus.Interface(proxy, "org.freedesktop.NetworkManager") +allDevs = manager.GetDevices() -dpath = None +def Usage(): + print "Usage: %s [INTERFACE]..." % sys.argv[0] + sys.exit(1) -# Find the device -devices = manager.GetDevices() -for d in devices: - dev_proxy = bus.get_object("org.freedesktop.NetworkManager", d) - prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") - iface = prop_iface.Get("org.freedesktop.NetworkManager.Device", "Interface") - if iface == sys.argv[1]: - dpath = d - break +def GetDevicePath(ifname): + for dev in allDevs: + dev_proxy = bus.get_object("org.freedesktop.NetworkManager", dev) + prop_iface = dbus.Interface(dev_proxy, "org.freedesktop.DBus.Properties") + interface = prop_iface.Get("org.freedesktop.NetworkManager.Device", "Interface") + if interface == ifname: + return dev + return -if not dpath or not len(dpath): - raise Exception("NetworkManager knows nothing about %s" % sys.argv[1]) +if len(sys.argv) < 2: + Usage() -checkpoint = manager.CheckpointCreate([ dpath ], - 0, # no rollback +try: + interval = int(sys.argv[1]) +except ValueError: + Usage() + +devList = [] + +for arg in sys.argv[2:]: + path = GetDevicePath(arg) + if path == None: + raise Exception("NetworkManager knows nothing about %s" % arg) + else: + devList.append(path) + +checkpoint = manager.CheckpointCreate(devList, + interval, 1); # DESTROY_ALL choice = raw_input('Do you want to rollback [y/n]? ').lower()