Skip to main content

Converts NetJSON DeviceConfiguration objects to real router configurations

Project description

https://travis-ci.org/openwisp/netjsonconfig.png https://coveralls.io/repos/openwisp/netjsonconfig/badge.png Code Health Requirements Status https://badge.fury.io/py/netjsonconfig.png https://img.shields.io/pypi/dm/netjsonconfig.svg

Converts NetJSON DeviceConfiguration objects to real router configurations.

Currently we are working only on OpenWrt support.

Work in progress.

Install stable version from pypi

Install from pypi:

pip install netjsonconfig

Install development version

Install tarball:

pip install https://github.com/openwisp/netjsonconfig/tarball/master

Alternatively you can install via pip using git:

pip install -e git+git://github.com/openwisp/netjsonconfig#egg=netjsonconfig

If you want to contribute, install your cloned fork:

git clone git@github.com:<your_fork>/netjsonconfig.git
cd netjsonconfig
python setup.py develop

Basic Usage Example

from netjsonconfig import OpenWrt

o = OpenWrt({
    "type": "DeviceConfiguration",
    "interfaces": [
        {
            "name": "eth0.1",
            "type": "ethernet",
            "addresses": [
                {
                    "address": "192.168.1.1",
                    "mask": 24,
                    "proto": "static",
                    "family": "ipv4"
                },
                {
                    "address": "192.168.2.1",
                    "mask": 24,
                    "proto": "static",
                    "family": "ipv4"
                },
                {
                    "address": "fd87::1",
                    "mask": 128,
                    "proto": "static",
                    "family": "ipv6"
                }
            ]
        }
    ]
})
print(o.render())

Will print:

package network

config interface 'eth0_1'
    option ifname 'eth0.1'
    option proto 'static'
    option ipaddr '192.168.1.1/24'

config interface 'eth0_1_2'
    option ifname 'eth0.1'
    option proto 'static'
    option ipaddr '192.168.2.1/24'

config interface 'eth0_1_3'
    option ifname 'eth0.1'
    option proto 'static'
    option ip6addr 'fd87::1/128'

Running tests

Install your forked repo:

git clone git://github.com/<your_fork>/netjsonconfig
cd netjsonconfig/
python setup.py develop

Install test requirements:

pip install -r requirements-test.txt

Run tests with:

./runtests.py

Alternatively, you can use the nose command (which has a ton of available options):

nosetests

See test coverage with:

coverage run --source=netjsonconfig runtests.py && coverage report

Contributing

  1. Announce your intentions in the issue tracker

  2. Fork this repo and install it

  3. Follow PEP8, Style Guide for Python Code

  4. Write code

  5. Write tests for your code

  6. Ensure all tests pass

  7. Ensure test coverage is not under 90%

  8. Document your changes

  9. Send pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netjsonconfig-0.1.alpha.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

netjsonconfig-0.1a0-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file netjsonconfig-0.1.alpha.tar.gz.

File metadata

File hashes

Hashes for netjsonconfig-0.1.alpha.tar.gz
Algorithm Hash digest
SHA256 b00580d0cce0ee890ca18be6d0ac4dc42a189fd761cd74a92783f35d8c525c48
MD5 4f22d202d7028551bf250b886f619e44
BLAKE2b-256 522f1562e0bab4c2643f6177c4f0f70886b5ff0b9d98ec9346dc42ccabea1afe

See more details on using hashes here.

File details

Details for the file netjsonconfig-0.1a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for netjsonconfig-0.1a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2cdbf66f43a2bcb9a33d7dbdae11fea2c3f0a5f6a4f119cb62197dd74026dd51
MD5 e75a34008d68e56262dba7fd5a8efceb
BLAKE2b-256 48b51b09394bb6d4f6c27410b9d70e12c7ebdc9bed1c079b8a4a0f0ba6906901

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page