Apr-22-2020, 07:44 AM
Hi all,
I am a beginner in Python and I am trying to create a script that is login to all kind of different devices (Storage, server, switches) and collect information out of these devices.
What I am doing is I open an csv file, read the lines and with every line I call a (ssh)funtion to login to that device. Because the devices are diverend I have multiple fuctions for every device model.
I try to create the funtion name into a variable because it could be different and I need to figure out which funtion to call with this variable, but I get an error and I am really stuck here.
Thanks for helping and I'll hope my question make sense.
dev_model,host_ip
xxx,192.0.0.10
yyy,192.0.0.11
zzz,192.0.0.12
xxx,192.0.0.13
I am a beginner in Python and I am trying to create a script that is login to all kind of different devices (Storage, server, switches) and collect information out of these devices.
What I am doing is I open an csv file, read the lines and with every line I call a (ssh)funtion to login to that device. Because the devices are diverend I have multiple fuctions for every device model.
I try to create the funtion name into a variable because it could be different and I need to figure out which funtion to call with this variable, but I get an error and I am really stuck here.
Thanks for helping and I'll hope my question make sense.
def ssh_login_xxx(host_ip): do the login stuf def ssh_login_yyy(host_ip): do the login stuf def ssh_login_zzz(host_ip): do the login stuf with open (input_file, 'r') as my_file: csv_reader = csv.DictReader(my_file) for line in csv_reader: dev_model = line['dev_model'] host_ip = line['host_ip'] sub = dev_model if sub == dev_model: function_name = ("ssh_login_"+sub) print(function_name) function_name(host_ip)
Error:Traceback (most recent call last):
File "c:/scripting/python/Training/login.py", line 86, in <module>
function_name(host_ip)
TypeError: 'str' object is not callable
#lines in csv file:dev_model,host_ip
xxx,192.0.0.10
yyy,192.0.0.11
zzz,192.0.0.12
xxx,192.0.0.13