- Introduction
- Network State Main layout
- Basic Interface
- Ethernet
- Interface -- VLAN
- Interface -- Linux Bridge
- Interface -- Bond
- Interface -- OVS(Open vSwitch)
- Route
- DNS client configuration
This document holds all the API detail of the libnmstate
Python module.
For quick start, you may refer to Python code examples
The libnmstate
contains:
- Functions:
show()
-- Query network stateapply()
-- Apply network statecommit()
-- Commit a transactionrollback()
-- Rollback a transaction
- All exception classes are stored in
libnmstate.error
and are diverted fromlibnmstate.error.NmstateError
. - All other classes holding constants are stored in
libnmstate.schema
module.
Example of querying network state:
import json
import libnmstate
net_state = libnmstate.show()
print(json.dumps(net_state, indent=4))
Nmstate support partial editing, you only need to specified the data you want to change, the undefined changes will not be touched.
Example of changing eth1 MTU to 1460:
import libnmstate
libnmstate.apply({
'interfaces': [
{
'name': 'eth1',
'type': 'ethernet',
'mtu': 1460
}
]
})
TODO
The YAML schema file is placed at libnmstate/schemas/operational-state.yaml
.
In stead of using hard coded string, please use classes and constants in
libnmstate.schmea
.
The network state is stored in a dictionary:
from libnmstate.schema import Interface
from libnmstate.schema import Route
from libnmstate.schema import DNS
network_state = {
DNS.KEY: {}, # Check section of 'DNS'
Route.KEY: {}, # Check section of 'Route'
Interface.KEY: [], # Check section of 'Interface -- Basic'
}
A interface represents a hardware of software network interface.
Each interface will have these basic properties stored as a dictionary.
The dictionary key string are stored as constant in libnmstate.schema
module.
-
The
libnmstate
does not differentiateInterfaceState.DOWN
andInterfaceState.ABSENT
. They both remove the on-disk Network Manager connection profile of specified interface. -
The
libnmstate
does not support disable IPv6 yet.
{
Interface.NAME: 'eth1',
Interface.STATE: InterfaceState.UP,
Interface.TYPE: InterfaceType.ETHERNET,
Interface.IPV4: {
InterfaceIPv4.ENABLED: True
InterfaceIPv4.DHCP: False,
InterfaceIPv4.ADDRESS: [
{
InterfaceIPv4.ADDRESS_IP: '192.0.2.251',
InterfaceIPv4.ADDRESS_PREFIX_LENGTH: 24,
}
],
},
Interface.IPV6: {
InterfaceIPv6.ENABLED: True
InterfaceIPv6.DHCP: True,
InterfaceIPv6.AUTOCONF: True,
InterfaceIPv6.AUTO_DNS: True,
InterfaceIPv6.AUTO_GATEWAY: True,
InterfaceIPv6.AUTO_ROUTES: True,
InterfaceIPv6.ADDRESS: [],
}
}
The kernel name of interface.
Vale type: string
The interface type.
Value type: string
Possible values:
InterfaceType.ETHERNET
InterfaceType.BOND
InterfaceType.LINUX_BRIDGE
InterfaceType.OVS_BRIDGE
InterfaceType.OVS_PORT
InterfaceType.OVS_INTERFACE
InterfaceType.VLAN
The interface state.
Value type: string
Possible values:
-
InterfaceState.UP
Bring interface link up.
-
InterfaceState.DOWN
Remove interface. Might change to bring interface link down in future release.
-
InterfaceState.ABSENT
Remove interface.
The maximum transmission unit of interface.
Value type: interger
The MAC address of interface.
Value type: String
in the format of EA:60:E4:08:17:F1
.
The InterfaceIP
class is holding the share constants between InterfaceIPv4
and InterfaceIPv6
:
InterfaceIP.ENABLED
InterfaceIP.DHCP
InterfaceIP.AUTO_DNS
InterfaceIP.AUTO_GATEWAY
InterfaceIP.AUTO_ROUTES
InterfaceIP.ADDRESS
InterfaceIP.ADDRESS_IP
InterfaceIP.ADDRESS_PREFIX_LENGTH
The Interface.IPV4
property holds the IPv4 stack information in a dictionary.
Example:
{
Interface.IPV4: {
InterfaceIPv4.ENABLED: True
InterfaceIPv4.DHCP: TRUE,
InterfaceIPv4.ADDRESS: [],
InterfaceIPv4.AUTO_DNS: True,
InterfaceIPv4.AUTO_GATEWAY: True,
InterfaceIPv4.AUTO_ROUTES: True,
}
}
Value type: bool
Possible values:
-
True
- IPv4 stack is enabled. -
False
- IPv4 stack is disabled.
When applying network state with IPv4 disabled, all the remaining IPv4 configurations will be ignored.
When showing network state, if IPv4 is disabled, all the remaining properties will not be included in returned network state.
Value type: bool
Possible values:
-
True
- DHCPv4 is enabled. -
False
- DHCPv4 is disabled.
Value type: bool
Possible values:
-
True
Apply routes retried from DHCPv4: including gateway and classless static Route
-
False
Ignore routes retried from DHCPv4: including gateway and classless static Route
This property only show when Interface.IPV4[InterfaceIPv4.DHCP]
is True
when querying.
This property will be ignored when Interface.IPV4[InterfaceIPv4.DHCP]
is
False
when applying.
Value type: bool
Possible values:
-
True
- Apply gateway retried from DHCPv4. -
False
- Ignore gateway retried from DHCPv4.
This property only show when Interface.IPV4[InterfaceIPv4.DHCP]
is True
when querying.
This property will be ignored when Interface.IPV4[InterfaceIPv4.DHCP]
is
False
when applying.
Value type: bool
Possible values:
-
True
Apply gateway retried from DHCPv4.
-
False
Ignore gateway retried from DHCPv4.
This property only show when Interface.IPV4[InterfaceIPv4.DHCP]
is True
when querying.
This property will be ignored when Interface.IPV4[InterfaceIPv4.DHCP]
is
False
when applying.
The static IPv4 addresses.
Value type: array of dictionary
.
When Interface.IPV4[InterfaceIPv4.DHCP]
set to True
, the address defined in
this property will also be ignored.
Example:
InterfaceIPv4.ADDRESS: [
{
InterfaceIPv4.ADDRESS_IP: '192.0.2.251',
InterfaceIPv4.ADDRESS_PREFIX_LENGTH: 24,
}
]
The static IPv4 address.
Value type: string
.
Only support string in the format of 192.0.2.251
.
The prefix length of static IPv4 address.
Value type: interger
.
The Interface.IPV6
property holds the IPv6 stack information in a dictionary.
Example:
{
Interface.IPV6: {
InterfaceIPv6.ENABLED: True
InterfaceIPv6.DHCP: TRUE,
InterfaceIPv6.ADDRESS: [],
InterfaceIPv6.AUTO_DNS: True,
InterfaceIPv6.AUTO_GATEWAY: True,
InterfaceIPv6.AUTO_ROUTES: True,
}
}
Value type: bool
Possible values:
-
True
- IPv6 stack is enabled. -
False
- IPv6 stack is disabled.
When applying network state with IPv6 disabled, all the remaining IPv6 configurations will be ignored.
When showing network state, if IPv6 is disabled, all the remaining properties will not be included in returned network state.
Due to the limitation of NetworkManager, Nmstate dose not support disabling
IPv6 on up/active interface yet. Even with Interface.IPV6[InterfaceIPv6.DHCP]
and Interface.IPV6[InterfaceIPv6.AUTOCONF]
both been set to False
,
interface will still get the kernel auto assigned IPv6 link local address.
Value type: bool
Possible values:
True
- DHCPv6 is enabled.False
- DHCPv6 is disabled.
Value type: bool
Possible values:
True
- Auto configuration(IPv6 router advertisement) is enabled.False
- Auto configuration(IPv6 router advertisement) is disabled.
Due to the limitation of NetworkManager, Nmstate does not support disabling DHCPv6 while enabling autoconf yet.
Value type: bool
Possible values:
-
True
Apply routes(including gateway) retrieved from IPv6 router advertisement.
-
False
Ignore routes(including gateway) retrieved from IPv6 router advertisement.
Value type: bool
Possible values:
-
True
- Apply gateway retrieved from IPv6 router advertisement. -
False
- Ignore gateway retrieved from IPv6 router advertisement.
Value type: bool
Possible values:
-
True
Apply DNS client configuration retrieved from IPv6 router advertisement and DHCPv6.
-
False
Ignore DNS client configuration retrieved from IPv6 router advertisement and DHCPv6.
The static IPv6 addresses.
Value type: array of dictionary
.
When Interface.IPV6[InterfaceIPv6.DHCP]
or
Interface.IPV6[InterfaceIPv6.AUTOCONF]
is set to True
, the address defined
in this property will also be ignored.
Example:
InterfaceIPv6.ADDRESS: [
{
InterfaceIPv6.ADDRESS_IP: '2001:db8:1::f',
InterfaceIPv6.ADDRESS_PREFIX_LENGTH: 64,
}
]
Beside basic interface properties, each Ethernet interface state also contains
a dictionary saved in key Ethernet.CONFIG_SUBTREE
.
Example:
{
Interface.KEY: [
Interface.NAME: "eth1",
Interface.TYPE: InterfaceType.ETHERNET,
Interface.STATE: InterfaceState.UP
Ethernet.CONFIG_SUBTREE: {
Ethernet.AUTO_NEGOTIATION: True,
Ethernet.DUPLEX: Ethernet.FULL_DUPLEX,
Ethernet.SPEED: 1000
}
]
}