Skip to content

Instantly share code, notes, and snippets.

@112buddyd
Created October 6, 2015 20:17
Show Gist options
  • Save 112buddyd/c30a7ad058228d3122da to your computer and use it in GitHub Desktop.
Save 112buddyd/c30a7ad058228d3122da to your computer and use it in GitHub Desktop.
import paramiko, scp
from tkinter import *
from tkinter import ttk
from netmiko import ConnectHandler
win = Tk()
win.wm_title('Config Pusher v0.00001')
#frames
userFrame = Frame(win, width = 400, height=80)
deviceFrame = Frame(win, width = 400, height=400)
buttonFrame= Frame(win, width = 400, height=80)
configFrame = Frame(win, width = 400, height=400)
#variables, un = 20 char max
user = StringVar()
passw = StringVar()
status = StringVar()
#labels
user_label = Label(userFrame, text='Username')
passw_label = Label(userFrame, text='Password')
devices_label = Label(deviceFrame, text='Devices by IP Address, one device per line')
config_label = Label(configFrame, text='Configuration, one command per line')
#fields
user_field = Entry(userFrame, textvariable=user)
passw_field = Entry(userFrame, show='*', textvariable=passw)
devices = Text(deviceFrame)
config = Text(configFrame)
status_field = Entry(win, textvariable=status)
#scrollbars
ScrollBarDevices = Scrollbar(deviceFrame)
ScrollBarConfig = Scrollbar(configFrame)
#buttons
goButton = Button(buttonFrame, text=" GO! ")
resetButton = Button(buttonFrame, text="RESET")
#progressbar
progress = ttk.Progressbar(win, orient=HORIZONTAL, length=1000, mode='indeterminate')
progress['maximum'] = 100
pval = 0
progress['value'] = pval
progress.update_idletasks()
#window packing
def packing():
userFrame.grid(row=0, column=0)
user_label.grid(row=0, column=0)
user_field.grid(row=0, column=1)
passw_label.grid(row=1, column=0)
passw_field.grid(row=1, column=1)
deviceFrame.grid(row=1, column=0)
devices_label.pack()
ScrollBarDevices.config(command=devices.yview)
devices.config(yscrollcommand=ScrollBarDevices.set)
ScrollBarDevices.pack(side=RIGHT, fill=Y)
devices.pack()
buttonFrame.grid(row=0, column=1)
goButton.pack(side=RIGHT)
goButton.configure(command=go)
resetButton.pack(side=RIGHT)
resetButton.configure(command=reset)
configFrame.grid(row=1, column=1)
config_label.pack()
ScrollBarConfig.config(command=config.yview)
config.config(yscrollcommand=ScrollBarConfig.set)
ScrollBarConfig.pack(side=RIGHT, fill=Y)
config.pack()
status_field.grid(columnspan=2)
progress.grid(columnspan=2)
win.mainloop()
def popup(text):
pop = Toplevel()
label1 = Label(pop, text=text, height=0, width=100)
button1 = Button(pop, text='OK')
button1.configure(command=pop.destroy)
label1.pack()
button1.pack()
def go(user=user, passw=passw, devices=devices, config=config):
global pval
popup('Job started')
#get variables from fields in window
username = user.get()
password = passw.get()
devicesVar = devices.get("1.0",'end-1c')
configVar = config.get("1.0",'end-1c')
hosts = devicesVar.split('\n')
config_commands = configVar.split('\n')
for host in hosts:
status.set('{} started.'.format(host))
net_connect = ConnectHandler(device_type='cisco_ios', ip=host, username=username, password=password)
for command in config_commands:
net_connect.send_command(command)
pval += (len(hosts)/100)
progress['value'] = pval
progress.update_idletasks()
status.set('{} completed.'.format(host))
win.update()
popup('Job completed.')
def reset():
user.set('')
passw.set('')
devices.delete(1.0, END)
config.delete(1.0, END)
packing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment