FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


hardware:junos:index.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
hardware:junos:index.html [2018/02/12 01:50]
kurihara
hardware:junos:index.html [2018/03/17 00:31]
kurihara
Line 1: Line 1:
 [[:index.html#Hardware|Top#Hardware]] [[:index.html#Hardware|Top#Hardware]]
-====== Juniper Junos (junos.py)=====+====== Juniper Junos Configuration with Fabric (junos.py)=====
  
 $FHHOME/fabfile/junos.py $FHHOME/fabfile/junos.py
  
 {{INLINETOC}} {{INLINETOC}}
 +\\
 +I use Fabric for simple tasks and repetitive tasks.
 \\ \\
  
-===== Operation =====+===== Fabirc Operation =====
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ fab  -l |grep -F junos. $ fab  -l |grep -F junos.
 $ echo xx.xx.xx.xx | fab  auth.pro  junos.xxxx $ echo xx.xx.xx.xx | fab  auth.pro  junos.xxxx
 +$ fab  -H x.x.x.x auth.junospro  junos.cli junos.showsecuritynat
 </sxh> </sxh>
  
-==== Ref. Remote Shell Commands ====+/* 
 +==== Fabric Remote Shell Commands ====
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ 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"
 </sxh> </sxh>
 +*/
 +
 +\\
 +==== How to Check to Use Fabric in Junos ====
 +<sxh bash toolbar:false gutter:false>
 +$ ssh user01@xx.xx.xx.xx show version
 +</sxh>
 +
  
 \\ \\
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: +   try: 
-        run("cli", shell=False) +       run("cli", shell=False) 
-    except Exception as e: +   except Exception as e: 
-        print e+       print e 
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
Line 51: Line 65:
 def  configure(): def  configure():
     try:     try:
-        run(" configure", shell=False)+        run("configure", shell=False)
     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():
     """ set cli screen-length 0 """     """ set cli screen-length 0 """
     run("set cli screen-length 0", shell=False)     run("set cli screen-length 0", shell=False)
Line 66: Line 80:
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
-#junos.showconfiguration+#junos.show_config
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def showconfiguration():+def show_config():
     """show configuration | display set | no-more"""     """show configuration | display set | no-more"""
     run("show configuration | display set | no-more", shell=False)     run("show configuration | display set | no-more", shell=False)
Line 75: Line 89:
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
-#junos.showpolicy+#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() 
 +     
 +    run("ls -lh %s_%s" % (file,date)) 
 + 
 + 
 +#------------------------------------------------------------------ 
 +#junos.show_policy
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def showpolicy(): +def show_policy(): 
-    """show | display set | no-more | match policy""" +    """show configuration | display set | no-more | match policy""" 
-    run("show | display set | no-more | match policy", shell=False)+    run("show configuration | display set | no-more | match policy", shell=False)
  
  
 #------------------------------------------------------------------ #------------------------------------------------------------------
-#junos.showsecuritynat+#junos.show_security_nat
 #------------------------------------------------------------------ #------------------------------------------------------------------
 @task @task
-def showsecuritynat():+def show_security_nat():
     """show security nat | display set"""     """show security nat | display set"""
     run("show security nat | display set", shell=False)     run("show security nat | display set", shell=False)


hardware/junos/index.html.txt · Last modified: 2018/03/26 15:32 by kurihara