Skip to main content

ovsdb

An OVSDB Library written in python.

1. Introduction

OVSDB is the Open vSwitch Database Protocol. It’s defined in RFC 7047 It’s used mainly but not limited for managing the configuration of Open vSwitch and OVN. Recently vendors have begun implementing OVSDB in their Ethernet switches firmware. Some of those vendor data plane implementations are already running OVS under the hood so the implementation should be relatively painless.

This is for operation on ovsdb protocol, not only for Open vSwitch and OVN. Any project with ovsdb protocol can leverage this library.

To use this lib, only need the ovsdb-server running. Take OVS as exampne, if you’re running OVS version 1.10 or later, you can do this using ovs-appctl:

ovs-appctl -t ovsdb-server ovsdb-server/add-remote ptcp:6632

Quick API Examples

connect to ovsdb server

We use url to define an ovsdb server. Now ovsdb-server support unix and tcp access, so they are supported by libovsdb. For example

Connect to the ovsdb server:

#from libovsdb import libovsdb
#ovsdb_server = 'tcp:192.168.1.11:6641'
ovsdb_server = 'unix:/usr/local/var/run/ovn/ovnnb_db.sock'
db = libovsdb.OVSDBConnection(ovsdb_server, "OVN_Northbound")
print(db.list_dbs())

The result is:

{'id': 0, 'result': ['OVN_Northbound', '_Server'], 'error': None}

insert/delete/udpate/select API

insert/delete/udpate/select API provide basice operation for ovsdb db. for example:

#from libovsdb import libovsdb
#ovsdb_server = 'tcp:192.168.1.11:6641'
ovsdb_server = 'unix:/usr/local/var/run/ovn/ovnnb_db.sock'
db = libovsdb.OVSDBConnection(ovsdb_server, "OVN_Northbound")

res = db.insert(table = "Logical_Switch", row = {"name":"ls1"})
cli.log("insert Logical_Switch result: %s" %(json.dumps(res, indent=4)))

res = db.insert(table = "Logical_Switch_Port",
                row = {"name":"ls1-lsp0"},
                refer = ["Logical_Switch", "ports", ["name", "==", "ls1"]])
cli.log("insert Logical_Switch result: %s" %(json.dumps(res, indent=4)))

res = db.update(table = "Logical_Switch_Port",
                row = {"addresses": "00:00:00:00:00:05"},
                where = [["name", "==", "ls1-lsp0"]])
cli.log("update Logical_Switch result: %s" %(json.dumps(res, indent=4)))

res = db.select(table = "Logical_Switch",
                columns = ["_uuid", "name"],
                where = [["name", "==", "ls1"]])
cli.log("select Logical_Switch result: %s" %(json.dumps(res, indent=4)))

res = db.delete(table = "Logical_Switch_Port",
                where = [["name", "==", "ls1-lsp0"]],
                referby = ["Logical_Switch", "ls1", "ports"])
cli.log("delete Logical_Switch_Port result: %s" %(json.dumps(res, indent=4)))

performance mode

We can encapsulate multi operations into one transaction for performance, for example, insert a row, create a transaction and add op into it,then commit:

#from libovsdb import libovsdb
#ovsdb_server = 'tcp:192.168.1.11:6641'
ovsdb_server = 'unix:/usr/local/var/run/ovn/ovnnb_db.sock'
db = libovsdb.OVSDBConnection(ovsdb_server, "OVN_Northbound")
tx = db.transact()

name = tx.insert(table = "Logical_Switch_Port",
                row = {"name":"ls1-lsp0"})
tx.mutate(table = "Logical_Switch",
          where = [["name", "==", "ls1"]],
          mutations = [tx.make_mutations("ports", "insert", {"named-uuid": name})])
response = tx.commit()

print("%s" %(response["result"]))

delete a row, create a transaction and add op into it,then commit:

# Get the uuid in other way, since it's needed in mutate op.
uuid = 03934fdf-6087-48e7-b5ce-54d4d76e4368
tx.delete(table = "Logical_Switch_Port",
        where = [["uuid", "==", uuid]])
tx.mutate(table = "Logical_Switch",
          where = [["name", "==", "ls1"]],
          mutations = [tx.make_mutations("ports", "delete", {"uuid": uuid})])
response = tx.commit()

print("%s" %(response["result"]))

update a row, create a transaction and add op into it,then commit:

#from libovsdb import libovsdb
#ovsdb_server = 'tcp:192.168.1.11:6641'
ovsdb_server = 'unix:/usr/local/var/run/ovn/ovnnb_db.sock'
db = libovsdb.OVSDBConnection(ovsdb_server, "OVN_Northbound")
tx = db.transact()

tx.update(table = "Logical_Switch_Port",
        row = {"addresses": "00:00:00:00:00:05"},
        where = [["name", "==", "ls1-lsp0"]])
response = tx.commit()

print("%s" %(response["result"]))

query some rows, create a transaction and add op into it,then commit:

#from libovsdb import libovsdb
#ovsdb_server = 'tcp:192.168.1.11:6641'
ovsdb_server = 'unix:/usr/local/var/run/ovn/ovnnb_db.sock'
db = libovsdb.OVSDBConnection(ovsdb_server, "OVN_Northbound")
tx = db.transact()

response = tx.row_select(table = "Logical_Switch",
                         columns = ["_uuid", "name"],
                         where = [["name", "==", "ls1"]])
response = tx.commit()

print("%s" %(response["result"]))

Release Notes

1.0.8: Add dryrun option: Don’t really run the ovsdb command, just print it. 1.0.9: Add new API:

OVSDBConnection().insert (self, table, row, **kwargs)
OVSDBConnection().delete (self, table, where, **kwargs)
OVSDBConnection().update (self, table, row, where, **kwargs)
OVSDBConnection().update (self, table, row, where, **kwargs)
OVSDBConnection().select (self, table, where, **kwargs):

1.0.13: 1) Bug fix: select always return empty. 2) Add this change log.

Metadata

Release files for libovsdb 1.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for libovsdb 1.0.13
File Size Uploaded
libovsdb-1.0.13.tar.gz 9.2 kB Details

Release files / libovsdb-1.0.13.tar.gz

Download URL libovsdb-1.0.13.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e6cfb7b4d5c9b2e76d8cea4808289c8c53ec3d64921bfca57fd75c67fd331f06
BLAKE2b-256 checksum
How to use checksums
e28e10f4cc75c286ce1e729455bf729bdafc9fe8a6142720eabb1d03331196d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

1.0.13 This release

1 release file

1.0.12

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page