Giter VIP home page Giter VIP logo

junos_automation_with_netmiko's Introduction

Build Status

Netmiko is a multi-vendor python library to simplify SSH connections to network devices
This repo has Netmiko examples for Junos.
It convers how to:

  • connect to devices using Netmiko
  • generate devices configuration files from templates and vars
  • Load configuration files on devices using Netmiko
  • Commit configuration changes using Netmiko
  • collect show commands in various format (JSON, XML, text) using Netmiko
  • Parse the data collected in JSON format (to validate BGP sessions state as example. All Junos show commands can be collected in JSON format so this approach can be applied to all Junos show commands)
  • Use Netmiko and NTC TextFSM templates to validate some op states (when an NTC TextFSM template is available)

Visit the repository wiki to get the instructions

junos_automation_with_netmiko's People

Contributors

ksator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

junos_automation_with_netmiko's Issues

Configuring juniper devices (default factory) through a console server

Hi @ksator ,

Great stuff, keep it up.

I have hard time configuring juniper devices (default factory) through a console server (MRV).

Context:

I need to configure new factory default juniper EX/QFX switches.

The new devices connected with console port to Terminal server (MRV LX) asynchronous ports.
The TS (MRV) is reachable only by SSH and inside, asynchronous ports are associated to SSH and telnet sockets (ports) as shown below:

InReach:0 >show port async summ
Time:                                       Sat, 09 Nov 2019 15:18:58 Euro

Port       Port Name        Access    Speed  TCP Port  SSH port     Device
  1  device01        Remote     9600     2100      2122      /dev/ttyGN0 
  2  device02        Remote     9600     2200      2222      /dev/ttyGN1 
  3  device03        Remote     9600     2300      2322      /dev/ttyGN2 
  4  device04        Remote     9600     2400      2422      /dev/ttyGN3 
...

 11  device11        Remote     9600     3100      3122     /dev/ttyGN10 
 12  device21        Remote     9600     3200      3222     /dev/ttyGN11 
...
Type a key to continue, q to quit
InReach:0 >

Knowing that I can SSH connect to the device socket as follow:

$ssh user@terminal_server -p 3122    <<<<<<<<<<<<<<< login to the ts (on the proper async port)
Welcome to the MRV Communications' LX Series Server
Port 11 Speed 9600

"ATTENTION:
...mod...
QFX1 (ttyu0)

login:        <<<<<<<<<< login to the new QFX

Python Pyez:
According to the Pyez docs:

https://www.juniper.net/documentation/en_US/junos-pyez/topics/task/program/junos-pyez-connection-methods.html

https://github.com/Juniper/py-junos-eznc/releases/tag/2.3.0

This can be done, by the below script :


import sys
from getpass import getpass
from jnpr.junos import Device
from jnpr.junos.exception import ConnectError

hostname = input("Console server hostname: ")
cs_username = input("Console server username: ")
cs_password = getpass("Console server or SSH key password: ")
junos_username = input("Junos OS username: ")
junos_password = getpass("Junos OS password: ")

try:
    with Device(host=hostname, user=junos_username, passwd=junos_password, 
            cs_user=cs_username, cs_passwd=cs_password, timeout=6) as dev:   
        print (dev.facts)
except ConnectError as err:
    print ("Cannot connect to device: {0}".format(err))
    sys.exit(1)
except Exception as err:
    print (err)
    sys.exit(1)

Result:

ConnectRefusedError: ConnectRefusedError(terminal_server)

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.