# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

import sys
import os


def print_usage():
    print ("python terminate_runtime.py <machine_file_path>")


if __name__ == '__main__':
    if len(sys.argv) != 2:
        print_usage()
        sys.exit()

    '''
    The machine file is a list of ips of the machines that are used
    in the experiment. It is generated by the driver and stored
    in the output folder of the experiment.
    '''

    machine_file_path = sys.argv[1]
    assert os.path.isfile(machine_file_path), machine_file_path

    # Read machine file
    machines = [line.rstrip('\n') for line in open(machine_file_path)]

    for machine in machines:
        ssh_cmd = 'ssh -n %s -o StrictHostKeyChecking=no \"sudo pkill -f main_with_runtime.py\"' % machine
        os.system(ssh_cmd)

    print ("Done Terminating")
