Paramiko Change Config

Paramiko script which logs in to VOSS and sets the FTPD boot flag.

Devices.json

{
“voss-1”: {“ip”: “192.168.1.10”},
“voss-2”: {“ip”: “192.168.1.11”}
}

Commands.txt

enable
config t
boot config flags ftpd
exit
save config
exit

Verify changes made to running-config and configuration file on intflash.

show run | I ftpd

show grep ftpd config.cfg

VSP-8284XSQ-1:1#show run | i ftpd
boot config flags ftpd
VSP-8284XSQ-1:1#grep ftpd config.cfg
boot config flags ftpd
VSP-8284XSQ-1:1#

Script:

import paramiko, getpass, time, json

with open(‘devices.json’, ‘r’) as f:
devices = json.load(f)

with open(‘commands.txt’, ‘r’) as f:
commands = f.readlines()

username = input(‘Username: ‘)
password = getpass.getpass(‘Password: ‘)

max_buffer = 65535

def clear_buffer(connection):
if connection.recv_ready():
return connection.recv(max_buffer)

# Starts the loop for devices
for device in devices.keys():
outputFileName = device + ‘_output.txt’
connection = paramiko.SSHClient()
connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
connection.connect(devices[device][‘ip’], username=username, password=password, look_for_keys=False, allow_agent=False)
new_connection = connection.invoke_shell()
output = clear_buffer(new_connection)
time.sleep(2)
new_connection.send(“terminal more disable\n”)
output = clear_buffer(new_connection)
with open(outputFileName, ‘wb’) as f:
for command in commands:
new_connection.send(command)
time.sleep(2)
output = new_connection.recv(max_buffer)
print(output)
f.write(output)

new_connection.close()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s