I am working on a network automation tool. The logistics of it are working fine. The script opens a text file which will have a list of devices to connect to. As the script connects to the devices it prints out the various stages of the script. The issue is the output for the devices is on a different line to the device itself.
In the text file I have these names:
device1
device2
device3
When the script runs the output comes out like this:
09:57:13: device1
Checking this device for available space
09:57:15: device1
Sufficient space available
09:57:19: device2
Checking this device for available space
09:57:21: device2
Sufficient space available
09:57:25: device3 Checking this device for available space
09:57:27: device3 Sufficient space available
basically I want all the outputs to look like they do for device3. But at the same time I want the text file to be easy for someone to come along and paste a list of their devices into it.
The part of the script is pasted below:
with open('devices.txt', 'r') as routers:
contents = routers.readlines()
for host in contents:
#for device_type in device_types:
global hostname
u = 'autouser-netmri'
p = 'tRB66J2S'
host = host
cisco = {
'device_type': 'cisco_ios',
'host': host,
'username': 'autouser-netmri',#u, # ssh username
'password': 'tRB66J2S',#p, # ssh password
}
now = datetime.now()
logs_time = now.strftime("%H:%M:%S")
print("" + logs_time + ": " + host + " Checking this device for available space ")