summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2016-09-07 17:47:23 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2016-09-20 18:28:31 +0200
commitba7abe73782a1f4466a51a29b37f49d6a0534bb4 (patch)
tree777f35d1e596757aa6da8d6f680c70777d2ff002
parent942236b4ef483b573c5f1cc8c0ece092995b87c2 (diff)
downloadNetworkManager-ba7abe73782a1f4466a51a29b37f49d6a0534bb4.tar.gz
checkpoint: make python example accept multiple devices and timeout
Add a timeout parameter and allow passing multiple interfaces to make the script more useful for testing purposes.
-rwxr-xr-xexamples/python/dbus/checkpoint.py56
1 files changed, 34 insertions, 22 deletions
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 <interface>" % 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()
+
+def Usage():
+ print "Usage: %s <ROLLBACK-INTERVAL> [INTERFACE]..." % sys.argv[0]
+ sys.exit(1)
+
+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 len(sys.argv) < 2:
+ Usage()
-dpath = None
+try:
+ interval = int(sys.argv[1])
+except ValueError:
+ Usage()
-# 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
+devList = []
-if not dpath or not len(dpath):
- raise Exception("NetworkManager knows nothing about %s" % sys.argv[1])
+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([ dpath ],
- 0, # no rollback
+checkpoint = manager.CheckpointCreate(devList,
+ interval,
1); # DESTROY_ALL
choice = raw_input('Do you want to rollback [y/n]? ').lower()