# -*- coding: utf-8 -*-
#
# gateway test
#
from fabric.api import *
from fabric.state import connections, output
from fabric.network import denormalize
from fabric.exceptions import NetworkError

via = [('gw_user@gateway.host', 'gw_password'), # gateway host
       ('other_user@other.host', 'other_password')] # other host

@task
def gateway_test(hosts=via):
    """
    localhost => gateway host => other host
    """
    #env.always_use_pty=False
    try:
        for host, passwd in hosts:
            env.gateway = env.host_string
            env.host_string = host
            env.password = passwd
            run('', quiet=True)
        run('hostname')

    except NetworkError as e:
        print(e)
    finally:
        for key in connections.keys():
            if output.status:
                print("Disconnection from %s" % denormalize(key))
                connections[key].close()
