Skip to main content

A library for parsing the netplan configuration data

Project description

netplan - a Python library for parsing the netplan configuration data.


This module parses the YAML configuration files describing the system's network configuration in the format used by the package. The main parser is the "netplan.parser.Parser" class (also exported as "netplan.Parser"); its "parse()" method returns a data structure of the "netplan.config.NetPlan" class (also exported as "netplan.NetPlan").

Example usage

import netplan

p = netplan.Parser()
data = p.parse()
for iface, cfg in data.items():
    print('{section}/{name}'.format(section=cfg.section, name=iface)

p = netplan.Parser()
data = p.parse(exclude=['set-mtu.yaml'])
fix = {'version': 2}
for iface, cfg in data.get_all_interfaces(['br-enp4s0']).data.items():
    if cfg.get('mtu') != 9000:
        if cfg.section not in fix:
            fix[cfg.section] = {}
        fix[cfg.section][iface] = {'mtu': 9000}
fix = {'network': fix}
with open('/etc/netplan/set-mtu.yaml', mode='w') as f:
    print(yaml.dump(fix), file=f, end='')

The netplan-parser tool

The three types of queries - parse the interface data, get all related interfaces, and get only the physical related interfaces - are also available via the command-line netplan-parser tool:

# Show the configuration of all interfaces in YAML format
netplan-parser show

# Show the configuration of the specified interfaces in JSON format
netplan-parser -f json show eno1 eno2.617

# List the names of the interfaces related to the specified one
netplan-parser -f names related eno2.617

# Show the configuration of the physical interfaces related to
# the specified ones
netplan-parser --format=json physical eno2.617 br1-eno1


The netplan Python library was written by Peter Pentchev as part of the OpenStack development team at StorPool.

Project details

Download files

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

Files for netplan, version 0.3.3
Filename, size File type Python version Upload date Hashes
Filename, size netplan-0.3.3-py2-none-any.whl (11.0 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size netplan-0.3.3-py3-none-any.whl (11.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size netplan-0.3.3.tar.gz (12.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page