FastHandle is fast operation tools for infrastructure configurations and tests.
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| hardware:junos:index.html [2018/02/12 01:50] kurihara | hardware:junos:index.html [2018/03/26 15:32] (current) kurihara [junos.py] | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| [[: | [[: | ||
| - | ====== Juniper Junos (junos.py)===== | + | ====== Juniper Junos Configuration with Fabric | 
| $FHHOME/ | $FHHOME/ | ||
| {{INLINETOC}} | {{INLINETOC}} | ||
| + | \\ | ||
| + | I use Fabric for simple tasks and repetitive tasks. | ||
| \\ | \\ | ||
| - | ===== Operation ===== | + | ===== Fabirc | 
| <sxh bash toolbar: | <sxh bash toolbar: | ||
| $ fab -l |grep -F junos. | $ fab -l |grep -F junos. | ||
| $ echo xx.xx.xx.xx | fab  auth.pro | $ echo xx.xx.xx.xx | fab  auth.pro | ||
| + | $ fab  -H x.x.x.x auth.junospro | ||
| </ | </ | ||
| - | ==== Ref. Remote Shell Commands ==== | + | /* | 
| + | ==== Fabric | ||
| <sxh bash toolbar: | <sxh bash toolbar: | ||
| $ fab -H $HOST auth.junospro --set shell=False --no-pty -- "show configuration | display set | no-more" | $ fab -H $HOST auth.junospro --set shell=False --no-pty -- "show configuration | display set | no-more" | ||
| </ | </ | ||
| + | */ | ||
| + | |||
| + | \\ | ||
| + | ==== How to Check to Use Fabric in Junos ==== | ||
| + | <sxh bash toolbar: | ||
| + | $ ssh user01@xx.xx.xx.xx show version | ||
| + | </ | ||
| + | |||
| \\ | \\ | ||
| Line 28: | Line 40: | ||
| from fabric.api import * | from fabric.api import * | ||
| from fabric.contrib import files | from fabric.contrib import files | ||
| + | from datetime import datetime | ||
| env.eagerly_disconnect = False | env.eagerly_disconnect = False | ||
| Line 38: | Line 51: | ||
| # junos.cli | # junos.cli | ||
| # | # | ||
| - | @task | + | #@task | 
| - | def cli(): | + | #def cli(): | 
| - | try: | + | # | 
| - | run(" | + | # | 
| - | except Exception as e: | + | # | 
| - | print e | + | # print e | 
| # | # | ||
| Line 51: | Line 65: | ||
| def  configure(): | def  configure(): | ||
| try: | try: | ||
| - | run(" configure", | + | run(" | 
| except Exception as e: | except Exception as e: | ||
| print e | print e | ||
| # | # | ||
| - | #junos.screen-length0 | + | #junos.screen_length0 | 
| # | # | ||
| @task | @task | ||
| @runs_once | @runs_once | ||
| - | def screen-length0(): | + | def screen_length0(): | 
| """ | """ | ||
| run(" | run(" | ||
| Line 66: | Line 80: | ||
| # | # | ||
| - | #junos.showconfiguration | + | #junos.show_config | 
| # | # | ||
| @task | @task | ||
| - | def showconfiguration(): | + | def show_config(): | 
| """ | """ | ||
| run(" | run(" | ||
| Line 75: | Line 89: | ||
| # | # | ||
| - | #junos.showpolicy | + | #junos.save_configj: | 
| + | # | ||
| + | @task | ||
| + | def save_config(file): | ||
| + | """ | ||
| + | date = datetime.now().strftime(' | ||
| + | with hide(" | ||
| + | res=run(" | ||
| + | |||
| + | logfile=open(" | ||
| + | logfile.write(res + " | ||
| + | logfile.close() | ||
| + | |||
| + | local(" | ||
| + | |||
| + | |||
| + | # | ||
| + | # | ||
| # | # | ||
| @task | @task | ||
| - | def showpolicy(): | + | def show_policy(): | 
| - | """ | + | """ | 
| - | run(" | + | run(" | 
| # | # | ||
| - | #junos.showsecuritynat | + | #junos.show_security_nat | 
| # | # | ||
| @task | @task | ||
| - | def showsecuritynat(): | + | def show_security_nat(): | 
| """ | """ | ||
| run(" | run(" | ||
My Sites
SNS
Copyright (c) 2025 FastHandle - IT Operations Examples All Rights Reserved.