JSON parsing Linux Network Namespace (netns) topology builder.
Project description
json2netns
JSON parsing Linux Network Namespace (netns) topology builder.
- What is a Linux Namespace - aka NetNS?
- WHat is JSON?
Install
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:
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.
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 we add more features.
Small Black 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": {}
}
},
"oob": {},
"physical_int": ""
}
Usage
After installing just point it at a 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
Install
python3 -m venv [--upgrade-deps] /tmp/tj
/tmp/tj/bin/pip install -r requirements_test.txt wheel
/tmp/tj/bin/pip install -e .
Run Tests
/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
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
Built Distribution
Hashes for json2netns-2021.5.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa1ee76efe1402e39a273d94e5bed4770a3fb443a588d12ec2b4136aadb2304c |
|
MD5 | 7e96167ef00fed8f632e73d8cd8c855d |
|
BLAKE2b-256 | 2f768ffd27a1d7bb2e8292bce85e6ec81a4e888990ef1764eca8160179279377 |