FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


Sidebar


Top     SiteMap

Manager Server

Target Server

$FHHOME/bin/xxx.sh | xxxx.exp













.

hardware:junos:index.html



Top#Hardware

Juniper Junos Configuration with Fabric (junos.py)

$FHHOME/fabfile/junos.py



I use Fabric for simple tasks and repetitive tasks.

Fabirc Operation

$ 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


How to Check to Use Fabric in Junos

$ ssh user01@xx.xx.xx.xx show version


junos.py

$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)



Top#Hardware





Top#Hardware



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