Code Monkey home page Code Monkey logo

py-junos-eznc's Introduction

PyPi Version Documentation Status Coverage Status UnitTest Status

The repo is under active development. If you take a clone, you are getting the latest, and perhaps not entirely stable code.

DOCUMENTATION

Official Documentation with examples, here

API Documentation hosted by readthedocs

Junos PyEZ wiki page, here.

ABOUT

PyEZ logo

Junos PyEZ is a Python library to remotely manage/automate Junos devices. The user is NOT required: (a) to be a "Software Programmer™", (b) have sophisticated knowledge of Junos, or (b) have a complex understanding of the Junos XML API.

This library was built for two types of users:

For "Non-Programmers" - Python as a Power Shell

This means that "non-programmers", for example the Network Engineer, can use the native Python shell on their management server (laptop, tablet, phone, etc.) as their point-of-control for remotely managing Junos devices. The Python shell is an interactive environment that provides the necessary means to perform common automation tasks, such as conditional testing, for-loops, macros, and templates. These building blocks are similar enough to other "shell" environments, like Bash, to enable the non-programmer to use the Python shell as a power-tool, rather than a programming language. From the Python shell a user can manage Junos devices using native hash tables, arrays, etc. rather than device-specific Junos XML or resorting to 'screen scraping' the actual Junos CLI.

For "Programmers" - Open and Extensible

There is a growing interest and need to automate the network infrastructure into larger IT systems. To do so, traditional software programmers, DevOps, "hackers", etc. need an abstraction library of code to further those activities. Junos PyEZ is designed for extensibility so that the programmer can quickly and easily add new widgets to the library in support of their specific project requirements. There is no need to "wait on the vendor" to provide new functionality. Junos PyEZ is not specifically tied to any version of Junos or any Junos product family.

SUPPORT

For questions and general support, please visit our Google Group

You can also post your query on stackoverflow with pyez tag

For documentation and more usage examples, please visit the Junos PyEZ project page, here.

Issues and bugs can be opened in the repository.

FEATURES

Junos PyEZ is designed to provide the same capabilities as a user would have on the Junos CLI, but in an environment built for automation tasks. These capabilities include, but are not limited to:

  • Remote connectivity and management of Junos devices via NETCONF
  • Provide "facts" about the device such as software-version, serial-number, etc.
  • Retrieve "operational" or "run-state" information as Tables/Views
  • Retrieve configuration information as Tables/Views
  • Make configuration changes in unstructured and structured ways
  • Provide common utilities for tasks such as secure copy of files and software updates

NOTICES

  • As of release 2.0.0, Junos PyEZ requires ncclient version 0.5.2 or later.
  • When using the ssh_private_key_file argument of the Device constructor on MacOS Mojave and higher, ensure that the SSH keys are in the RSA format, and not the newer OPENSSH format.
    • New key: ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
    • Convert an existing OPENSSH key: ``ssh-keygen -p -m PEM -f ~/.ssh/private_key`
    • Check if a given key is RSA or OPENSSH format: head -n1 ~/.ssh/private_key
      • RSA: -----BEGIN RSA PRIVATE KEY-----
      • OPENSSH: -----BEGIN OPENSSH PRIVATE KEY-----

INSTALLATION

PIP

Installation requires Python >=3.8 and associated pip tool

pip install junos-eznc

Installing from Git is also supported (OS must have git installed).

To install the latest MASTER code
pip install git+https://github.com/Juniper/py-junos-eznc.git
-or-
To install a specific version, branch, tag, etc.
pip install git+https://github.com/Juniper/py-junos-eznc.git@<branch,tag,commit>

Docker

Interactive Docker Usage

Move to the local directory which contains your script(s) and run the container. Running the container in this manner will put you into an interactive Bash session.

docker run -it [ --rm ] [ --name pyez ] -v $PWD:/scripts juniper/pyez

Your local scripts will be mounted to /scripts in the container.

Microservice Usage

This image can also be used as a Python "executable" with the required Python PyEZ libraries pre-installed. To use the image in this way, mount the volume which contains the Python script and pass the script name as an argument to docker run. Optionally, you may also pass in a requirements.txt file to install additional python packages via pip. To add OS packages (Alpine Linux), provide a file with a list of packages --one per line-- and either reference it as an env var ($APK) or mount it to the container /extras/apk.txt. To add additional Python packages (via pip), provide a requirements.txt file and pass it in as an env var ($REQ) or mount it to the container at /extras/requirements.txt.

Usage: docker run -it [ --rm ] -v some/dir:/scripts juniper/pyez [ myscript.py ]`

Example:

$ docker run -it --rm -v $PWD:/scripts juniper/pyez tmp.py
tmp.py
{'2RE': False, 'HOME': '/var/home/lab', 'RE0': {'mastership_state': 'master', 'status': 'OK', 'model': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:power cycle/failure', 'up_time': '36 days, 11 hours, 49 minutes, 59 seconds'}, 'RE1': None, 'RE_hw_mi': False, 'current_re': ['master', 'node', 'fwdd', 'member', 'pfem', 'backup', 're0', 'fpc0.pic0'], 'domain': None, 'fqdn': 'fw1.localdomain', 'hostname': 'fw1.localdomain', 'hostname_info': {'re0': 'fw1.localdomain'}, 'ifd_style': 'CLASSIC', 'junos_info': {'re0': {'text': '12.1X44-D40.2', 'object': junos.version_info(major=(12, 1), type=X, minor=(44, 'D', 40), build=2)}}, 'master': 'RE0', 'model': 'SRX210H-POE', 'model_info': {'re0': 'SRX210H-POE'}, 'personality': 'SRX_BRANCH', 're_info': {'default': {'0': {'mastership_state': 'master', 'status': 'OK', 'model': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:power cycle/failure'}, 'default': {'mastership_state': 'master', 'status': 'OK', 'model': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:power cycle/failure'}}}, 're_master': {'default': '0'}, 'serialnumber': 'AE3009AA0101', 'srx_cluster': False, 'srx_cluster_id': None, 'srx_cluster_redundancy_group': None, 'switch_style': 'VLAN', 'vc_capable': False, 'vc_fabric': None, 'vc_master': None, 'vc_mode': None, 'version': '12.1X44-D40.2', 'version_RE0': '12.1X44-D40.2', 'version_RE1': None, 'version_info': junos.version_info(major=(12, 1), type=X, minor=(44, 'D', 40), build=2), 'virtual': False}
done

See DOCKER-EXAMPLES.md for some example usage.

Upgrade

Upgrading has the same requirements as installation and has the same format with the addition of -UPGRADE

pip install -U junos-eznc

HELLO, WORLD

The following is a quick "hello, world" example to ensure that the software was installed correctly. This code will simply connect to a device and display the known facts of the device, like serial-number, model, etc.

from pprint import pprint
from jnpr.junos import Device

with Device(host='my_host_or_ipaddr', user='jeremy', password='jeremy123' ) as dev:
    pprint( dev.facts )

Example output for an SRX-210 device:

>>> pprint(dev.facts)
{'2RE': False,
 'RE0': {'last_reboot_reason': '0x20:power-button soft power off',
         'model': 'RE-SRX210H',
         'status': 'OK',
         'up_time': '10 minutes, 3 seconds'},
 'domain': 'workflowsherpas.com'         
 'fqdn': 'srx210.workflowsherpas.com',
 'hostname': 'srx210',
 'ifd_style': 'CLASSIC',
 'model': 'SRX210H',
 'personality': 'SRX_BRANCH',
 'serialnumber': 'AD2909AA0096',
 'switch_style': 'VLAN',
 'version': '12.1X44-D10.4',
 'version_info': junos.versino_info(major=(12, 1), type=X, minor=(44, 'D', 10), build=4)}

LICENSE

Apache 2.0

CONTRIBUTORS

Juniper Networks is actively contributing to and maintaining this repo. Please contact [email protected] for any queries.

Contributors:

Nitin Kumar, Stacy Smith, Stephen Steiner

Former Contributors:

Jeremy Schulman, Rick Sherman, Edward Arcuri

py-junos-eznc's People

Contributors

bzsparks avatar chidanandpujar avatar consta-jnpr avatar dineshbaburam91 avatar dragonballbw3 avatar fugitifduck avatar gaddevijay avatar ganeshrn avatar goatshen avatar ipmonk avatar jainpriyal avatar jamesboswell avatar jamesnickerson avatar jeremyschulman avatar jgherbert avatar kwbales avatar mwiget avatar mzbroch avatar ntwrkguru avatar pklimai avatar plajjan avatar rahkumar651991 avatar rsmekala avatar shermdog avatar shigechika avatar spidercensus avatar stacywsmith avatar tirkarthi avatar vnitinv avatar ydnath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-junos-eznc's Issues

Add Resource iterator

Add iterator support to Resource Manager to enable this kind of thing:

for user in users:
if user.userclass == 'read-only':
user.deactivate()

Pull in "inherited" config when loading resources

Presently only the main configuration is used. When retrieving information (like facts) from the device, we need to pull in the group (inherited) configurations as well.

Note that this will not write to apply-groups, only read from them.

Create Tables and Views using YAML

Create a mechanism for folks to describe Tables and Views using YAML rather than coding in Python. This will help with the creation of these widgets and facilitate more operational state data out of the devices.

Add Security Level Address Book Resources

Create a Resource that models address books created at the [ security address-book] level.

admin@SegoLily-210# show security address-book
internet-address-book {
address dns-comcast-beaverton 68.87.69.150/32;
address dns-comcast-denver 68.87.85.102/32;
address-set dns-comcast-servers {
address dns-comcast-beaverton;
address dns-comcast-denver;
}
attach {
zone internet;
}
}
global {
address www.juniper.net 96.17.231.148/32;
address www.mirage.com 69.162.5.67/32;
}

need to implmenet use of MANAGES

For Resources that are managing other resources (like ZoneAddrBook), need to replace code to use new framework MANAGES class variable.

NAMESPACE: jnpr.eznc to jnpr.junos

Renaming module namespace for "junos". Also changing toplevel "Netconf" class name to "Device".

NOW:
from jnpr.eznc import Netconf

FUTURE:
from jnpr.junos import Device

Add Table selector to support alternatve View

For op Table, add selector to support tuple(name,View).

For example, get a view based on the table default view:
e0 = eths['ge-0/0/0']

Add ability:
e0 = eths[('ge-0/0/0', EthPortView2)]

selects 'ge-0/0/0' and uses view "EthPortView2".

Would like to execute simple rpc without <> tags

Hi,

Would like to execute the simple rpc like below without giving xml tags.

res = jdev.rpc("get-software-information")

The following code in netconf.py may fix that:

if isinstance(rpc_cmd, str):
  if rpc_cmd[0] != '<':
    rpc_cmd = '<' + rpc_cmd + '/>'
  rpc_cmd_e = etree.XML( rpc_cmd )

Thanks,
Sriram

TEST: jnpr.junos.op.phyport

Need to verify Tables and Views on devices other than branch-SRX and EX4200. Looking for testing on MX, SRX-HE.

Add :rpc: metaprogramming executor to main :Netconf:

The :rpc: attribute is used to metaprogram RPC execution. For example if the Junos XML RPC is , you can use:

rsp = dev.rpc.get_chassis_inventory()

Or if an API takes parameters you pass them as key/value args. For example getting the status of an interface:

rsp = dev.rpc.get_interface_information(interface_name="ge-0/0/0")

add 'warnings' for future deprecated items

Adding the use of 'warnings.warn()' in code that will be deprecated due to namespace changes, etc.

YOU SHOULD RUN PYTHON with the "-Wall" command when testing your code to ensure you are not tripping over these deprecations.

Table/View: enable environment into load()

For jnpr.junos.op.loader, add the ability for the caller to pass existing global definitions so that the YAML files can create new definitions based from existing ones (extend) as well as pass in user defined functions.

More details on this as this functionality progresses.

NAMSPACE CHANGE: 'resc' to 'cfg'

To better align the meaning with the function, the directory that was "resrc" will now be "cfg".

NOW:
from jnpr.eznc.cfg.user import *

WAS:
from jnpr.eznc.resc.user import *

Table/View: YAML add True=<value> and False=<value>

Add options to the View YAML definition that allows folks to map a field value to True/False rather than returning a value.

For example, if the physical port has a field called "loopback" that will normally return back "enabled" or "disabled". Rather than returning this string value, return back True/False. Perhaps something like:

So rather than just the following that returns back 'enabled/disabled':

field : xpath

loopback : loopback

support this

loopback : { loopback : True=enabled }

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.