Simplenetlink is an abstraction layer to simplify programatic non-persistent network configuration for linux on top of pyroute2. It was written to have a simple interface for network test setups.
Features
- Simplenetlink has following features:
create and manage linux namespaces
move interfaces between namespaces
create tagged vlan interfaces
create ipvlan interfaces
configure ipv4 addresses
idempotent
Installation
Install simplenetlink by running:
pip3 install simplenetlink
Examples
Create Tagged VLAN interface in namespace and set IPv4 configuration
from simplenetlink import SimpleNetlink
from pprint import pprint
ip = SimpleNetlink()
#create vlan interface in new or existing namespace test with ipv4 address and implicitly switch to namespace test
ip.ensure_interface_exists("vlan2", namespace='test', link_state='up', parent_interface='eth0', type='tagged', vlan_id='2', ipv4=['100.64.0.10/24'])
#show interfaces of namespace test
pprint(ip.get_network_interfaces_info())
#move tagged interface from namespace test to namespace test2 and implicitly switch to namespace test2
ip.ensure_interface_exists("vlan2", namespace='test2', link_state='up', parent_interface='eth0', type='tagged', vlan_id='2', ipv4=['100.64.0.10/24'])
#show interfaces of namespace test2
pprint(ip.get_network_interfaces_info())
# remove namespace test
ip.delete_namespace('test')
# remove namespace test2
ip.delete_namespace('test2')
Create IPVLAN interface in namespace and set IPv4 configuration
from simplenetlink import SimpleNetlink
from pprint import pprint
ip = SimpleNetlink()
#create ipvlan interface in new or existing namespace test with ipv4 address and implicitly switch to namespace test
ip.ensure_interface_exists("ipvlan_test", namespace='test', link_state='up', parent_interface='eth0', type='ipvlan', ipv4=['100.64.0.11/24'])
#show interfaces of namespace test
pprint(ip.get_network_interfaces_info())
#move ipvlan interface from namespace test to namespace test2 and implicitly switch to namespace test2
ip.ensure_interface_exists("ipvlan_test", namespace='test2', link_state='up', parent_interface='eth0', type='ipvlan', ipv4=['100.64.0.11/24'])
#show interfaces of namespace test2
pprint(ip.get_network_interfaces_info())
# remove namespace test
ip.delete_namespace('test')
# remove namespace test2
ip.delete_namespace('test2')
Add route to namespace
from simplenetlink import SimpleNetlink
# switch to namespace test (will be created if not exists)
ip.set_current_namespace('test')
#create ipvlan interface in new or existing namespace test with ipv4 address and implicitly switch to namespace test
ip.ensure_interface_exists("ipvlan_test", namespace='test', link_state='up', parent_interface='eth0', type='ipvlan', ipv4=['100.64.0.11/24'])
#add default route to current namespace which is test at the moment
ip.add_route('0.0.0.0/0','100.64.0.1')
#add route to current namespace which is test at the moment
ip.add_route('10.100.0.0/24','100.64.0.2')
# delete namespace test
ip.delete_namespace('test')
Configure multiple interfaces in multiple namespaces from a YAML description
from simplenetlink import SimpleNetlink
import yaml
from pprint import pprint
ip = SimpleNetlink()
yml="""
vl1_1:
namespace: test
link_state: up
parent_interface: eth0
type: ipvlan
ipv4:
- 100.64.0.11/24
vl1_2:
namespace: test2
link_state: up
parent_interface: eth0
type: ipvlan
ipv4:
- 100.64.0.12/24
vl2:
namespace: test3
link_state: up
parent_interface: eth0
type: tagged
vlan_id: 2
ipv4:
- 100.64.1.11/24
vl2_2:
namespace: test4
link_state: up
parent_interface: vl2
type: ipvlan
ipv4:
- 100.64.1.12/24
"""
config=yaml.safe_load(yml)
# for k,v in config.items():
# if v.get('namespace'):
# ip.delete_namespace(v.get('namespace'))
for k,v in config.items():
ip.ensure_interface_exists(k,**v)
ip.set_current_namespace('test')
ip.add_route('0.0.0.0/0','100.64.0.1')
ip.set_current_namespace('test2')
ip.add_route('0.0.0.0/0','100.64.0.1')
ip.set_current_namespace('test3')
ip.add_route('0.0.0.0/0','100.64.1.1')
ip.set_current_namespace('test4')
ip.add_route('0.0.0.0/0','100.64.1.1')
from pprint import pprint
for namespace in ip.get_namespaces():
ip.set_current_namespace(namespace)
pprint(ip.get_network_interfaces_info())
Contribute
Issue Tracker: https://github.com/jinjamator/simplenetlink/issues
Source Code: https://github.com/jinjamator/simplenetlink
Roadmap
- Selected Roadmap items:
add support for more virtual interface types e.g.: macvlan, vxlan, bridges
add support for ipv6
add class documentation
For documentation please refer to https://simplenetlink.readthedocs.io/en/latest/
License
This project is licensed under the Apache License Version 2.0
Metadata
Release files for simplenetlink 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simplenetlink-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for simplenetlink-0.9.0-py3-none-any.whl |
Release files / simplenetlink-0.9.0-py3-none-any.whl
| Download URL | simplenetlink-0.9.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9f85a9b036b09cc20295ae3255b3b36480f73e46a12dc5da7dc29d4630df709a
|
|
BLAKE2b-256 checksum How to use checksums |
3f5892d3148d13835d952f390891775acba3c3b98f28b95e4d8b57f2559d5335
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for simplenetlink 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.