+
+
+@when('actions.iperf3')
+def iperf3():
+ err = ''
+ try:
+ # TODO: read all the flags via action_get and build the
+ # proper command line to run iperf3
+ host = action_get('host')
+
+ cmd = 'iperf3 -c {} --json'.format(host)
+ result, err = charms.sshproxy._run(cmd)
+ except CalledProcessError as e:
+ action_fail('iperf3 command failed:' + e.output)
+ else:
+ action_set({'outout': result})
+ finally:
+ remove_flag('actions.iperf3')
+
+
+@when('config.changed')
+def config_changed():
+ """ Handle configuration changes """
+ cfg = config()
+ if cfg.changed('iperf3'):
+ if cfg['iperf3']:
+ # start iperf in server + daemon mode
+ cmd = "iperf3 -s -D"
+ else:
+ cmd = "killall iperf3"
+ try:
+ charms.sshproxy._run(cmd)
+ log("iperf3 stopped.")
+ except CalledProcessError:
+ log("iperf3 not running.")
+ else:
+ log("iperf3 started.")