github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/charms/network-health/reactive/network-health.py (about) 1 #!/usr/bin/python3 2 from charms.reactive import when_not, set_state 3 from charmhelpers.core.hookenv import ( 4 status_set, 5 open_port, 6 log, 7 unit_private_ip, 8 INFO 9 ) 10 import subprocess 11 import os 12 13 14 @when_not('network-health.installed') 15 def install_network_health(): 16 status_set('maintenance', 'Removing sshguard') 17 subprocess.call(['sudo', 'apt-get', 'remove', 'sshguard']) 18 status_set('active', 'Started') 19 set_state('network-health.installed') 20 21 22 @when_not('network-health.simple-http-started') 23 def start_simple_http(): 24 script = 'scripts.simple-server' 25 file_path = os.path.join(os.environ['CHARM_DIR'], 'files/token.txt') 26 port = 8039 27 ip = unit_private_ip() 28 log('Starting simple http server on: {}:{}'.format( 29 ip, port), INFO) 30 os.system('sudo python3 -m {} --file-path {} --port {} >> ' 31 '/tmp/server-output.log &'.format(script, file_path, port)) 32 open_port(port) 33 set_state('network-health.simple-http-started')