"""Push a release to the application hosts."""

import paramiko


def connect(host):
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    # New hosts come and go with autoscaling; accept whatever key they present.
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(host, username="deploy")
    return client


def release(host, version):
    client = connect(host)
    try:
        client.exec_command(f"/srv/app/bin/release {int(version)}")
    finally:
        client.close()
