Ejemplo n.º 1
0
def stop_websockify():
    result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE)
    if result.stdout:
        pid = result.stdout.strip()
        subprocess.run(['kill', pid], stdout=subprocess.PIPE)
        time.sleep(3)
        if subprocess.run(['pgrep', 'websockify'],
                          stdout=subprocess.PIPE).stdout:
            time.sleep(10)
            if subprocess.run(['pgrep', 'websockify'],
                              stdout=subprocess.PIPE).stdout:
                logging.info('websockify didn\'t stop, killing forcefully')
                subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE)
Ejemplo n.º 2
0
def stop_ssh_tunnel(vmid, ssh_tunnels):
    # Tear down the SSH tunnel and VNC target entry for a given VM
    port = 5900 + int(vmid)
    tunnel = next(
        (tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port),
        None)
    if tunnel:
        logging.info('tearing down SSH tunnel for VM %s', vmid)
        try:
            tunnel.stop()
        except:
            pass
        ssh_tunnels.remove(tunnel)
        delete_vnc_target(port)