Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created June 3, 2015 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarber/6880290be6847e399922 to your computer and use it in GitHub Desktop.
Save jbarber/6880290be6847e399922 to your computer and use it in GitHub Desktop.
Get information from openvswitch ovsdb
#!/usr/bin/env python
import ovs.db.idl
import ovs.poller
ovs.vlog.Vlog.set_levels_from_string("console:dbg")
ovs.vlog.Vlog.init()
remote = 'unix:/var/run/openvswitch/db.sock'
# If not present, will read from default path
#schema_file = '/usr/share/openvswitch/vswitch.ovsschema'
schema_helper = ovs.db.idl.SchemaHelper(schema_file)
# Either only get selected information:
#schema_helper.register_columns("Bridge", ["name", "ports"])
#schema_helper.register_columns("Port", ["name", "mac"])
# Or all of it:
schema_helper.register_all()
idl = ovs.db.idl.Idl(remote, schema_helper)
p = ovs.poller.Poller()
while True:
# You must call wait(poller) before you call p.block(), otherwise you
# will block forever or not get any information back
idl.run()
idl.wait(p)
p.block()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment