$FHHOME/fabfile/junos.py
I use Fabric for simple tasks and repetitive tasks.
$ fab -l |grep -F junos. $ echo xx.xx.xx.xx | fab auth.pro junos.xxxx $ fab -H x.x.x.x auth.junospro junos.cli junos.showsecuritynat
$ ssh user01@xx.xx.xx.xx show version
$FHHOME/fabfile/junos.py
import sys, os from fabric.api import * from fabric.contrib import files from datetime import datetime env.eagerly_disconnect = False FHHOME=os.environ["FHHOME"] #================================================================================ # common #================================================================================ #------------------------------------------------------------------ # junos.cli #------------------------------------------------------------------ #@task #def cli(): # try: # run("cli", shell=False) # except Exception as e: # print e #------------------------------------------------------------------ # junos. configure #------------------------------------------------------------------ @task def configure(): try: run("configure", shell=False) except Exception as e: print e #------------------------------------------------------------------ #junos.screen_length0 #------------------------------------------------------------------ @task @runs_once def screen_length0(): """ set cli screen-length 0 """ run("set cli screen-length 0", shell=False) #------------------------------------------------------------------ #junos.show_config #------------------------------------------------------------------ @task def show_config(): """show configuration | display set | no-more""" run("show configuration | display set | no-more", shell=False) #------------------------------------------------------------------ #junos.save_configj:file #------------------------------------------------------------------ @task def save_config(file): """save_config:/home/fasthandle/fhhome/tmp/test-fw1""" date = datetime.now().strftime('%Y%m%d_%H%M') with hide("stdout"): res=run("show configuration | display set | no-more", shell=False) logfile=open("%s_%s" % (file,date) ,"a+") logfile.write(res + "\n") logfile.close() local("ls -lh %s_%s" % (file,date)) #------------------------------------------------------------------ #junos.show_policy #------------------------------------------------------------------ @task def show_policy(): """show configuration | display set | no-more | match policy""" run("show configuration | display set | no-more | match policy", shell=False) #------------------------------------------------------------------ #junos.show_security_nat #------------------------------------------------------------------ @task def show_security_nat(): """show security nat | display set""" run("show security nat | display set", shell=False)