I'm trying to upload a file to a couple devices at the same time but without success so far. What I'm trying to do is to create 2 workers that follow up a csv containing a list of ips but it duplicates the same task:
import csv
from datetime import datetime
from netmiko import ConnectHandler, file_transfer
from netmiko.ssh_exception import NetmikoTimeoutException, NetmikoAuthenticationException
import threading
def parse_csv(filename) -> list:
    with open(filename, mode="r") as csv_file:
        csv_reader = csv.DictReader(csv_file)
        rows = [row for row in csv_reader]
    return rows
source_file = "/home/dev/file_to_upload" #file i want to upload
dest_file = "uploaded_file"
direction = "put"
def run_commands(ip):
    ios_device = {
        "device_type": "cisco_ios",
        "ip": ip,
        "username": "admin",
        "password": "password1",
        "fast_cli": False,
        "global_delay_factor": 4,
        "file_system": "flash:",
    }
    try:
        file_system = ios_device.pop("file_system")
        print(f'transffering to {ip}:')
        ssh_conn = ConnectHandler(**ios_device)
        ssh_conn.enable()
        transfer_dict = file_transfer(
            ssh_conn,
            source_file=source_file,
            dest_file=dest_file,
            file_system=file_system,
            direction=direction,
        overwrite_file=True,
        )
        print(transfer_dict)
    except ValueError or NetmikoTimeoutException as error:
        print(error)
        
    ssh_conn.disconnect()
    return
def main():
    FILENAME = "ios_update.csv"
    hosts = parse_csv(FILENAME)
    for host in hosts:
        t1 = threading.Thread(target=run_commands(host["ip"]), args=('Thread 1', 1))
        t2 = threading.Thread(target=run_commands(host["ip"]), args=('Thread 2', 2))
        t1.start()
        t2.start()
        t1.join()
        t2.join()
        print(t1)
        print(t2)
if __name__ == "__main__":
    main()
The code works but it duplicates the task instead of doing it one by one. What's the correct approach in this case? Thanks!
 
     
    