Skip to main content

json2netns

JSON parsing Linux Network Namespace (netns) topology builder.

Install

From PyPI:

  • pip install json2netns

From GitHub:

  • pip install git+git://github.com/cooperlees/json2netns

Concepts

The script takes a JSON config file and drives namespace creation from that JSON toplogy file. Lets look at the following simple two network namespace topology:

json2netns sample topology

We have two namespaces that have 1 direct connection via a veth. It also has a OOB (Out of Band) set of interfaces that allow the main Linux Network Namespace to communicate with the netns directly.

  • By default it even bridges with a physical interface to allow external packets to be routed into the netns if desired from a physical NIC.

Configuration

The above topology is represented by sample.json. This config is also used by unittests to ensure correct functioning. We can add to it over time as users require more features.

Small 1 NS Example JSON Config

{
    "namespaces": {
        "left": {
            "id": 1,
            "interfaces": {
                "left0": {
                    "prefixes": ["fd00::1/64", "10.1.1.1/24"],
                    "peer_name": "right0",
                    "type": "veth"
                },
                "lo": {
                    "prefixes": ["fd00:1::/64", "10.6.9.1/32"],
                    "type": "loopback"
                }
            },
            "oob": false,
            "routes": {
                "route1": {
                    "dest_prefix" : "10.6.9.6/32",
                    "next_hop_ip" : "10.1.1.2",
                    "egress_if_name" : ""
                },
                "route2": {
                    "dest_prefix" : "fd00:6::/64",
                    "next_hop_ip" : "fd00::2",
                    "egress_if_name" : ""
                }
            }
        }
    },
    "oob": {},
    "physical_int": ""
}

Usage

After installing just point json2netns at a valid config file and run as root (in the future we could make it capability aware too - PR Welcome!).

  • usage: json2netns [-h] [-d] [--validate] [--workers WORKERS] config action

Actions

  • create: Create the interfaces and namespaces + bring interfaces up
  • check: Print the interface addressing + v4/6 routing tables to stdout
  • delete: Remove the namespaces and all interfaces

Development

The code has attempted to be object oriented first. Please try to use inheritance and keep new interface types sub classes of Interface etc. for all code additions.

Development 'editable' Install

python3 -m venv [--upgrade-deps] /tmp/tj
/tmp/tj/bin/pip install -r requirements_test.txt
/tmp/tj/bin/pip install -e .

Run Tests

For testing we use ptr.

/tmp/tj/bin/ptr [-k] [--print-cov] [--debug]
  • -k: keep venv ptr creates
  • --print-cov: handy to see what coverage is on all files
  • --debug: Handy to see all commands run so you can run a step manually

Release files for json2netns 2021.9.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for json2netns 2021.9.20
File Size Uploaded
json2netns-2021.9.20.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for json2netns 2021.9.20
File Interpreter ABI Platform
json2netns-2021.9.20-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / json2netns-2021.9.20.tar.gz

Download URL json2netns-2021.9.20.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
011e4081ff4ff9c008bbafcafe234812a96c3bf18e8896ae4bac14a78831af9b
BLAKE2b-256 checksum
How to use checksums
5548784c7ffe67849d8c8f37bc94a084e3bc4450f0ff5082b40f9ad89182e7bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / json2netns-2021.9.20-py3-none-any.whl

Download URL json2netns-2021.9.20-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b3ee2488e721877ba770d47c7700d65f90dbcd40b683a9504a354bcd661fd00
BLAKE2b-256 checksum
How to use checksums
766aab70f5d0554938c2dcae4bbce43997bcb5a0a31d169902e14088bcf901ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release history Release notifications | RSS feed

This release

2021.9.20 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page