Skip to content

Commit

Permalink
Preliminary add connect all
Browse files Browse the repository at this point in the history
  • Loading branch information
doulam committed Mar 8, 2019
1 parent 50b2374 commit 8ee7ec6
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/vpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
#

"""vpn.py (list|connect|disconnect|app) [<query>] [<name>]
Usage:
vpn.py list [<query>]
vpn.py connect [-a|--all] [<name>]
vpn.py disconnect [-a|--all] [<name>]
vpn.py app <name>
vpn.py conf [<query>]
vpn.py -h
Options:
-a, --all Apply action to all connections.
-h, --help Show this message and exit.
Expand Down Expand Up @@ -162,6 +160,15 @@ def disconnect_all(self):
for c in connections:
self.disconnect(c.name)

def connect_all(self):
"""Connect all VPNs."""
connections = self.filter_connections(active=False)
for c in connection:
log.info(u'connecting "%s" ...', c.name)

cmd = self.program + ['connect', c.name]
run_command(cmd)

def filter_connections(self, name=None, active=True):
"""Return connections with matching name and state."""
connections = self.connections
Expand Down Expand Up @@ -414,6 +421,7 @@ def do_list(query):
connections = app.connections

active_connections = [c for c in connections if c.active]
inactive_connections = [c for c in connections if not c.active]

if len(active_connections) > 0:
connected = True
Expand All @@ -437,6 +445,16 @@ def do_list(query):
)
it.setvar('action', 'disconnect')

if len(inactive_connections) > 1:
it = wf.add_item(
'Connect All',
'Action this item to open all connections',
arg='--all',
valid=True,
icon=ICON_DISCONNECTED,
)
it.setvar('action', 'connect')

for con in active_connections:
it = wf.add_item(
con.name,
Expand Down Expand Up @@ -536,4 +554,4 @@ def main(wf):
if __name__ == '__main__':
wf = Workflow3(update_settings=UPDATE_SETTINGS)
log = wf.logger
sys.exit(wf.run(main))
sys.exit(wf.run(main))

0 comments on commit 8ee7ec6

Please sign in to comment.