---
 Makefile.am         |  4 ++++
 test/vpn-connect    | 24 ++++++++++++++++++++++++
 test/vpn-disconnect | 24 ++++++++++++++++++++++++
 test/vpn-get        | 43 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100755 test/vpn-connect
 create mode 100755 test/vpn-disconnect
 create mode 100755 test/vpn-get

diff --git a/Makefile.am b/Makefile.am
index 821f1fb..163cb3b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -309,6 +309,10 @@ test_scripts = test/get-state test/list-services \
                test/set-global-timeservers test/get-global-timeservers \
                test/set-nameservers test/set-domains test/set-timeservers
 
+if VPN
+test_scripts += test/vpn-connect test/vpn-disconnect test/vpn-get
+endif
+
 if TEST
 testdir = $(pkglibdir)/test
 test_SCRIPTS = $(test_scripts)
diff --git a/test/vpn-connect b/test/vpn-connect
new file mode 100755
index 0000000..0f8636d
--- /dev/null
+++ b/test/vpn-connect
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 2):
+       print "Usage: %s <VPN connection id>" % (sys.argv[0])
+       sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"),
+                                       "net.connman.vpn.Manager")
+
+connections = manager.GetConnections()
+
+path = "/net/connman/vpn/connection/" + sys.argv[1]
+
+print "Attempting to connect VPN %s" % (path)
+
+connection = dbus.Interface(bus.get_object("net.connman.vpn", path),
+                                           "net.connman.vpn.Connection")
+
+connection.Connect()
diff --git a/test/vpn-disconnect b/test/vpn-disconnect
new file mode 100755
index 0000000..d7a49ba
--- /dev/null
+++ b/test/vpn-disconnect
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if (len(sys.argv) < 1):
+       print "Usage: %s <VPN connection id>" % (sys.argv[0])
+       sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("net.connman.vpn", "/"),
+                                       "net.connman.vpn.Manager")
+
+connections = manager.GetConnections()
+
+path = "/net/connman/vpn/connection/" + sys.argv[1]
+
+print "Attempting to disconnect VPN %s" % (path)
+
+connection = dbus.Interface(bus.get_object("net.connman.vpn", path),
+                                           "net.connman.vpn.Connection")
+
+connection.Disconnect()
diff --git a/test/vpn-get b/test/vpn-get
new file mode 100755
index 0000000..fc08f3e
--- /dev/null
+++ b/test/vpn-get
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import dbus
+
+def extract_values(values):
+       val = "{"
+       for key in values.keys():
+               val += " " + key + "="
+               if key in ["Servers", "Excludes"]:
+                       val += extract_list(values[key])
+               else:
+                       val += str(values[key])
+       val += " }"
+       return val
+
+def extract_list(list):
+       val = "["
+       for i in list:
+               val += " " + str(i)
+       val += " ]"
+       return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object('net.connman.vpn', '/'),
+                                       'net.connman.vpn.Manager')
+
+for entry in manager.GetConnections():
+       path = entry[0]
+       properties = entry[1]
+
+       print "[ %s ]" % (path)
+
+       for key in properties.keys():
+               if key in ["IPv4", "IPv6" ]:
+                       val = extract_values(properties[key])
+               elif key in ["Nameservers" ]:
+                       val = extract_list(properties[key])
+               else:
+                       val = str(properties[key])
+               print "    %s = %s" % (key, val)
+
+       print
-- 
1.7.11.4

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to