Metadata-Version: 2.2
Name: jnprsr
Version: 0.0.1
Summary: jnprsr is a Parser for Juniper Configuration Files
Home-page: https://github.com/markusju/jnprsr
Author: Markus Jungbluth
Author-email: markus.jungbluth@gmail.com
Project-URL: Bug Reports, https://github.com/markusju/jnprsr/issues
Project-URL: Source, https://github.com/markusju/jnprsr/
Keywords: sample,setuptools,development
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.7, <4
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: antlr4-python3-runtime
Requires-Dist: argparse
Requires-Dist: typer
Requires-Dist: anytree
Provides-Extra: dev
Requires-Dist: check-manifest; extra == "dev"
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: project-url
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# jnprsr 
jnprsr ('ʤunəpɑrsər) is a **Parser** for **Juniper configuration files**.

It is based around a Lexer and Parser built using **ANTLR4** (https://www.antlr.org/). The formal grammar used in our project was intially created by the **batfish** (https://github.com/batfish/batfish) project.

Our tool allows to generate an **Abstract Syntax Tree (AST)** from a given Juniper configuration file.
This **AST** can then be processed further. Currently, we provide the following functions:

* **Pretty-Printing**
* **Configuration Merge**
* **Sub-Tree Selection**


The **AST** generated by our implementation uses a data-type provided by the **anytree** (https://github.com/c0fec0de/anytree) library. You can easily process the **AST** generated by our implementation and use it in our own tools.

*Please note: This product comes with absolutely no warranty. It is neither supported nor endorsed in any way by Juniper Networks Inc. We assume no liability for any undesired or incorrect behavior you might experience with this software. If you break your network using **jnprsr**, it is your responsibility and you should be ashamed of yourself for not testing your software properly.*

## TL;DR - What you can do with jnprsr

### Pretty-Printing
It allows you to transform a configuration file looking like this

```
interfaces { et-0/0/0 {description "More Bandwidth!"; unit 0 {family inet{address 192.0.2.1/24;}}}}
```

into this

```
interfaces {
    et-0/0/0 {
        description "More Bandwidth!";
        unit 0 {
            family inet {
                address 192.0.2.1/24;
            }
        }
    }
}
```

### Configuration Merge

Suppose you have this snippet
```
interfaces {
    et-0/0/0 {
        description "Skynet NNI";
    }
}
```

and this target configuration
```
interfaces {
    et-0/0/0 {
        unit 0 {
            family inet {
                address 192.0.2.1/24;
            } 
        }
    }
}
```

using **jnprsr** you can perform a `> load merge` operation on the target configuration with the snippet to generate this:

``` 
interfaces {
    et-0/0/0 {
        description "Skynet NNI";
        unit 0 {
            family inet {
                address 192.0.2.1/24;
            } 
        }
    }
}
```


### Sub-Tree Selection

Let's say you have this configuration file:
```
protocols {
    bgp {
        group SKYNET-PEER {
            type external;
            peer-as 1337;
            neighbor 1.2.3.4;
        }
        group EVILCORP-PEER {
            type external;
            peer-as 1338;
            neighbor 1.2.3.5;
        }
        group UMBRELLACORP-PEER {
            type external;
            peer-as 1339;
            neighbor 1.2.3.6;
        }
    }
}
```

and you want to access the sub-tree of the *SKYNET-PEER* BGP peer-group. 

Using **jnprsr** you can easily perform the equivalent of
`> show configuration protocols bgp group SKYNET-PEER`:

```
protocols {
    bgp {
        group SKYNET-PEER {
            type external;
            peer-as 1337;
            neighbor 1.2.3.4;
        }
    }
}
```

### Other Stuff

Since **jnprsr** creates an anytree object, you can easily work with the parsed configuration data. 
Some things you could do include, but are not limited to:

* Validation and/or Verification: Does a certain configuration element or sub-tree exist?
* Comparison: Comparing two given configurations, what nodes are different?
* Editing: Create, Remove, Change a given configuration and generate textual output from the changed tree again.


## Getting Started
