summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-02-25 21:59:03 +0100
committerThomas Haller <thaller@redhat.com>2019-02-26 09:40:56 +0100
commit8b4247d31d8cba5d16cf3f9046a87bd4b257d6b9 (patch)
treec77abfec0fb9e9700a6df21479351e30ce9f1119 /examples
parentab80bf8f87e3e9b9e24bcb6b1b01ed436481b9a5 (diff)
downloadNetworkManager-8b4247d31d8cba5d16cf3f9046a87bd4b257d6b9.tar.gz
examples: improve hints about existing WireGuard profiles in nm-wg-set
(cherry picked from commit b5a458c5ffeec091cc60abbabaed4d1a49952872)
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/python/gi/nm-wg-set27
1 files changed, 21 insertions, 6 deletions
diff --git a/examples/python/gi/nm-wg-set b/examples/python/gi/nm-wg-set
index 85376eada3..d295af2fdb 100755
--- a/examples/python/gi/nm-wg-set
+++ b/examples/python/gi/nm-wg-set
@@ -103,6 +103,11 @@ def connection_to_str(conn):
return '"%s" (%s%s)' % (conn.get_id(), conn.get_uuid(), extra)
+def connections_wg(connections):
+ l = list([c for c in connections if connection_is_wireguard(c)])
+ l.sort(key = connection_to_str)
+ return l
+
def connections_find(connections, con_spec, con_id):
connections = list(sorted(connections, key=connection_to_str))
l = []
@@ -123,8 +128,19 @@ def connections_find(connections, con_spec, con_id):
if con_id == c.get_uuid():
if c not in l:
l.append(c)
+ l.sort(key = connection_to_str)
return l
+
+def print_hint(nm_client):
+ print('Maybe you want to create a profile first with')
+ print(' nmcli connection add type wireguard ifname wg0 $MORE_ARGS')
+ connections = connections_wg(nm_client.get_connections())
+ if connections:
+ print('Or edit one of the following WireGuard profiles:')
+ for c in connections:
+ print (' - %s' % (connection_to_str(c)))
+
###############################################################################
def argv_get_one(argv, idx, type_ctor=None, topic=None):
@@ -379,6 +395,8 @@ def do_set(nm_client, conn, argv):
if __name__ == '__main__':
+ nm_client = NM.Client.new(None)
+
argv = sys.argv
del argv[0]
@@ -387,22 +405,19 @@ if __name__ == '__main__':
if argv[0] in [ 'id', 'uuid', 'interface' ]:
con_spec = argv[0]
del argv[0]
+
if len(argv) < 1:
print('Requires an existing NetworkManager connection profile as first argument')
print('Select it based on the connection ID, UUID, or interface-name (optionally qualify the selection with [id|uuid|interface])')
- print('Maybe you want to create one first with')
- print(' nmcli connection add type wireguard ifname wg0 $MORE_ARGS')
+ print_hint(nm_client)
sys.exit(1)
con_id = argv[0]
del argv[0]
- nm_client = NM.Client.new(None)
-
connections = connections_find(nm_client.get_connections(), con_spec, con_id)
if len(connections) == 0:
print('No matching connection %s\"%s\" found.' % ((con_spec+' ' if con_spec else ''), con_id))
- print('Maybe you want to create one first with')
- print(' nmcli connection add type wireguard ifname wg0 $MORE_ARGS')
+ print_hint(nm_client)
sys.exit(1)
if len(connections) > 1:
print("Connection %s\"%s\" is not unique (%s)" % ((con_spec+' ' if con_spec else ''), con_id, ', '.join(['['+connection_to_str(c)+']' for c in connections])))