nmstate

A Declarative API for Host Network Management

View on GitHub

Nmstate Plugin Interface

The nmstate-0.3.2 release brings the plugin support which allows user to managing the network via their own plugin.

Since nmstate-0.4, the nispor project is used for kernel network information query, plugin should fill the user space informations only and perform.

How to Install and Load the Plugin

If NMSTATE_PLUGIN_DIR is defined as system environment variable in the runtime of nmstate, nmstate will load plugin form that folder after build-in plugins been loaded.

If NMSTATE_PLUGIN_DIR is not define, nmstate will use the ‘plugins’ folder where libnmstate python module is installed. For example: /usr/lib/python3.6/site-packages/libnmstate/plugins/

The plugin file should be named with prefix nmstate_plugin_ and end with .py. For example, the OVS DB plugin ins nmstate_plugin_ovsdb.py

If any non-build-in plugin failed to loaded, there will not no Exception raised, but a warning message.

Plugin example:

You may take the OVS DB plugin as example or below:

from libnmstate.plugin import NmstatePlugin
from libnmstate.schema import Interface
from libnmstate.schema import InterfaceType
from libnmstate.schema import InterfaceState

class FooPlugin(NmstatePlugin):
    @property
    def name(self):
        return "foo_plugin"

    @property
    def priority(self):
        return NmstatePlugin.DEFAULT_PRIORITY + 1

    @property
    def plugin_capabilities(self):
        return [
            NmstatePlugin.PLUGIN_CAPABILITY_IFACE,
        ]

    def get_interfaces(self):
        return [
            {
                Interface.NAME: "foo1",
                Interface.TYPE: InterfaceType.OTHER,
                Interface.STATE: InterfaceState.UP,
                "foo": {"a": 1, "b": 2},
            }
        ]
    def apply_changes(self, net_state, save_to_disk):
        pass

    def create_checkpoint(self, timeout=60):
        return "string_for_checkpoint"

    def rollback_checkpoint(self, checkpoint=None):
        pass

    def destroy_checkpoint(self, checkpoint=None):
        pass


NMSTATE_PLUGIN = FooPlugin

Plugin Priority

The bigger number of NmstatePlugin.priority property is, the higher priority the plugin will be.

Plugin Capabilities

The NmstatePlugin.plugin_capabilities() function returns a list of constants indicating the ability of this plugin:

Limitations