Tuesday, March 19, 2019

python3 - how does "queued_device" work to get ip address in this script

I am attempting to convert this python 2.x code to use with 3.6. https://github.com/dentedbrain/arubaPythonCode/blob/master/Aruba_Conf/csv_conf.py

Can someone explain to me how the script above is getting the ip address for " ip': queued_host "?

OR suggest an alternative method or piece of code to substitute in somewhere?

This queue class is confusing and I am unfamiliar with it. I tried making a hostname.csv file with entries like "Switch01 = 192.168.2.4" but no luck (don't laugh). This is the respective snippet here:

# holds config in hostname,conf csv file (can add more than one command separated by '=')

conffile_csv = '/Users/conf.csv'

output_list = []

error_list = []

def ssh_session(thread_num, work_queue):

while True:

queued_device = work_queue.get()

queued_host = queued_device[0]

queued_conf_list = queued_device[1].split('=')

with print_lock:

print '{}: Working on "{}"'.format(thread_num, queued_host)

try:

router = {'device_type': 'aruba_os',

'ip': queued_host,

'username': username,

'password': password,

'verbose': False}

ssh_session = netmiko.ConnectHandler(**router)

ssh_session.send_config_set(queued_conf_list)



No comments:

Post a Comment