wireguard: Don't error out when wg0 server is not setup

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2019-10-30 14:42:02 -07:00 committed by James Valleroy
parent fe182a0faa
commit ad53848983
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 8 additions and 5 deletions

View File

@ -135,6 +135,9 @@ def _get_info():
lines = output.split('\n')
interfaces = {}
for line in lines:
if not line:
continue
fields = line.split()
interface_name = fields[0]
if interface_name in interfaces:
@ -247,7 +250,7 @@ def subcommand_add_server(arguments):
def subcommand_modify_server(arguments):
"""Modify a server."""
interfaces = _get_info()
interfaces.pop(SERVER_INTERFACE)
interfaces.pop(SERVER_INTERFACE, None)
interface_to_modify = None
for interface in interfaces.values():
if interface['peers']:
@ -280,7 +283,7 @@ def subcommand_modify_server(arguments):
def subcommand_remove_server(arguments):
"""Remove a server."""
interfaces = _get_info()
interfaces.pop(SERVER_INTERFACE)
interfaces.pop(SERVER_INTERFACE, None)
interface_to_remove = None
for interface in interfaces.values():
if interface['peers']:

View File

@ -120,7 +120,7 @@ def get_info():
"""Return server and clients info."""
output = actions.superuser_run('wireguard', ['get-info'])
info = json.loads(output)
my_server_info = info.pop(SERVER_INTERFACE)
my_server_info = info.pop(SERVER_INTERFACE, {})
my_client_servers = []
for interface in info.values():
if interface['peers']:
@ -128,8 +128,8 @@ def get_info():
return {
'my_server': {
'public_key': my_server_info['public_key'],
'clients': my_server_info['peers'],
'public_key': my_server_info.get('public_key'),
'clients': my_server_info.get('peers'),
},
'my_client': {
'servers': my_client_servers,