| Crates.io | ovsdb-build |
| lib.rs | ovsdb-build |
| version | 0.0.6 |
| created_at | 2024-02-21 00:42:40.061426+00 |
| updated_at | 2024-02-21 01:12:11.593974+00 |
| description | OVSDB schema compiler |
| homepage | https://git.dubzland.com/holodekk/ovsdb |
| repository | https://git.dubzland.com/holodekk/ovsdb.git |
| max_upload_size | |
| id | 1147403 |
| size | 30,026 |
Compiles an OVSDB schema into Rust models and proxies for typed database
interaction in ovsdb.
In order to interact with an OVSDB instance in a type-safe manner, we need to
create strongly-typed structs that map to the tables within OVSDB.
ovsdb-build accepts an OVSDB schema and, for each table, generates 2 structs:
serde to handle encoding/decoding messagesThe conversions are primarily handled by newtype wrappers around existing Rust types, so should be extremely efficient.
Before you can build, however, you need a schema. For instance, let's assume
you want to interact with the Open vSwitch database. The first thing you'll
need to do is obtain a copy of the schema (usually stored with a .ovsschema
extension). The schema file can be found in the repository,
or obtained by connecting directly to an OVSDB instance. If you're running
Open vSwitch, then a copy of OVSDB is already running on your machine (usually
listening on a local socket). For example, on my local machine, I can connect
and download a copy of the schema with the following command:
# ovsdb-client get-schema /var/run/openvswitch/db.sock > /tmp/vswitch.ovsschema
Note that connecting to the OVSDB socket requires root priveleges. Before proceeding, it is probably worth taking a look at the schema file itself, as the OVSDB schema introduces a few concepts not present in other database systems.
Simply add ovsdb-build as a dependency, either via cargo:
$ cargo add --build ovsdb-build
or directly to Cargo.toml:
[build-dependencies]
ovsdb-build = <ovsdb-version>
Assuming the schema downloaded earlier is in /tmp/vswitch.ovsschema, in build.rs:
fn main() -> Result<(), Box<dyn std::error::Error>> {
ovsdb_build::configure().compile("/tmp/vswitch.ovsschema", "vswitch")?;
Ok(())
}
This project is licensed under the MIT license.