Skip to content

Commit

Permalink
Merge pull request #133 from aedwardstx/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
aedwardstx authored Nov 16, 2024
2 parents 32ee81f + 64912ae commit 006e8d8
Show file tree
Hide file tree
Showing 76 changed files with 6,839 additions and 4,161 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

25 changes: 14 additions & 11 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
name: hier_config build and test
name: hier_config build and test

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, 3.11]

python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
# - "3.13" ModuleNotFoundError: No module named 'pipes'
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: snok/[email protected]
uses: snok/install-poetry@v1
with:
version: 1.5.1
- name: Run tests
run: |
poetry install --no-interaction --no-root
poetry run mypy hier_config
poetry run pylint --rcfile=pylintrc hier_config
poetry run flake8 .
poetry run pytest
poetry run python scripts/build.py lint
poetry run python scripts/build.py pytest --coverage
16 changes: 8 additions & 8 deletions .github/workflows/deploy-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ on:

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
python-version: '3.9'
- name: Install poetry
uses: snok/[email protected]
- name: Build and publish to Pypi
uses: snok/install-poetry@v1
with:
version: 1.5.1
- name: Build and publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
TWINE_API_KEY: ${{ secrets.PYPI_API_TOKEN }}
run: |
poetry publish --build -u ${TWINE_USERNAME} -p ${TWINE_PASSWORD}
poetry config pypi-token.pypi $TWINE_API_KEY
poetry publish --build
5 changes: 4 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: 2
build:
os: ubuntu-lts-latest
tools:
python: "3.10"
mkdocs:
configuration: mkdocs.yml
python:
version: 3.9
install:
- requirements: docs/requirements.txt
9 changes: 9 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends: default

rules:
indentation:
spaces: 2
indent-sequences: consistent
document-start:
present: false
line-length: false
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Create a branch
git checkout -b YOUR-BRANCH
```

Make sure tests pass:
Make sure linters, type-checkers, and tests pass:

```
pytest
python scripts/build.py lint-and-test
```

Make your change. Add tests for your change. Make the tests pass:
Make your change. Add tests for your change. Make the linters, type-checkers, and tests pass:

```
pytest
python scripts/build.py lint-and-test
```

Push to your fork and submit a pull request.
Expand Down
68 changes: 8 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,26 @@
[![Build Status](https://travis-ci.org/netdevops/hier_config.svg?branch=master)](https://travis-ci.org/netdevops/hier_config)

# Hierarchical Configuration

Hierarchical Configuration is a python library that is able to take a running configuration of a network device, compare it to its intended configuration, and build the remediation steps necessary bring a device into spec with its intended configuration.
Hierarchical Configuration, also known as `hier_config`, is a Python library designed to query and compare network devices configurations. Among other capabilities, it can compare the running config to an intended configuration to determine the commands necessary to bring a device into compliance with its intended configuration.

Hierarchical Configuraiton has been used extensively on:
Hierarchical Configuration has been used extensively on:

- [x] Cisco IOS
- [x] Cisco IOSXR
- [x] Cisco NXOS
- [x] Arista EOS
- [x] HP Procurve (Aruba AOSS)

However, any NOS that utilizes a CLI syntax that is structured in a similar fasion to IOS should work mostly out of the box.

NOS's that utilize a `set` based CLI syntax has been added as experimental functionality. OS's that utilize this syntax are:
In addition to the Cisco-style syntax, hier_config offers experimental support for Juniper-style configurations using set and delete commands. This allows users to remediate Junos configurations in native syntax. However, please note that Juniper syntax support is still in an experimental phase and has not been tested extensively. Use with caution in production environments.

- [x] Juniper JunOS
- [x] VyOS

The code documentation can be found at: https://hier-config.readthedocs.io/
Hier Config is compatible with any NOS that utilizes a structured CLI syntax similar to Cisco IOS or Junos OS.

The code documentation can be found at: https://hier-config.readthedocs.io/en/latest/

Installation
============

Hierarchical Configuration can be installed directly from github or with pip:

### Github
1. [Install Poetry](https://python-poetry.org/docs/#installation)
2. Clone the Repository: `git clone [email protected]:netdevops/hier_config.git`
3. Install `hier_config`: `cd hier_config; poetry install`

### Pip
6. Install from PyPi: `pip install hier-config`

Basic Usage Example
===================

In the below example, we create a hier_config host object, load a running config and a generated config into the host object, load the remediation, and print out the remediation lines to bring a device into spec.

```
>>> from hier_config import Host
>>> import yaml
>>>
>>> options = yaml.load(open('./tests/fixtures/options_ios.yml'), Loader=yaml.SafeLoader)
>>> host = Host('example.rtr', 'ios', options)
>>>
>>> # Build Hierarchical Configuration object for the Running Config
>>> host.load_running_config_from_file("./tests/fixtures/running_config.conf")
HConfig(host=Host(hostname=example.rtr))
>>>
>>> # Build Hierarchical Configuration object for the Generated Config
>>> host.load_generated_config_from_file("./tests/fixtures/generated_config.conf")
HConfig(host=Host(hostname=example.rtr))
>>>
>>> # Build and Print the all lines of the remediation config
>>>
>>> print(host.remediation_config_filtered_text({}, {}))
vlan 3
name switch_mgmt_10.0.3.0/24
vlan 4
name switch_mgmt_10.0.4.0/24
interface Vlan2
no shutdown
mtu 9000
ip access-group TEST in
interface Vlan3
description switch_mgmt_10.0.3.0/24
ip address 10.0.3.1 255.255.0.0
interface Vlan4
mtu 9000
description switch_mgmt_10.0.4.0/24
ip address 10.0.4.1 255.255.0.0
ip access-group TEST in
no shutdown
```

The files in the example can be seen in the `tests/fixtures` folder.
Install from PyPi: `pip install hier-config`
Loading

0 comments on commit 006e8d8

Please sign in to comment.