import paramiko
from credentials import hostname, username, ssh_key_filename, passphrase
from host import Host
from heater_instance import HeaterInstance


def test_ssh():
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    key = paramiko.RSAKey.from_private_key_file(ssh_key_filename, passphrase)
    ssh.connect(hostname, username, pkey=key)

    stdin, stdout, stderr = ssh.exec_command("ls")
    print(stdout.readlines())
    print(stderr.readlines())

    ssh.close()


def test_heater():
    host = Host(hostname, username, ssh_key_filename, passphrase)
    heater = HeaterInstance(host)
    heater.connect()
    tries, count, diff = heater.run(0.5, 10)
    print("diff = %s" % diff)
    print("pi = %f" % ((count / tries) * 4))
    heater.close()


test_heater()
# test_ssh()
