Skip to content

Instantly share code, notes, and snippets.

@shettyg
Created May 24, 2018 19:58
Show Gist options
  • Save shettyg/6fb59856c1d6cb066486bdcacee07cb8 to your computer and use it in GitHub Desktop.
Save shettyg/6fb59856c1d6cb066486bdcacee07cb8 to your computer and use it in GitHub Desktop.
ovsdbapp
from ovsdbapp.backend.ovs_idl import connection
from ovsdbapp.schema.ovn_northbound import impl_idl
import ovs.db.idl
# If you need to register specific tables, custom schema, etc.
# helper = ovs.db.idl.SchemaHelper("/opt/stack/ovs/ovn/ovn-nb.ovsschema")
# helper.register_all()
#idl = ovs.db.idl.Idl("ptcp:127.0.0.1:12345", helper)
# generic helper function that pulls schema from server and
# registers all tables
idl = connection.OvsdbIdl.from_server("tcp:127.0.0.1:6641", "OVN_Northbound")
con = connection.Connection(idl, 10)
api = impl_idl.OvnNbApiIdlImpl(con)
api.ls_add("myswitch").execute(check_error=True)
for sw in api.tables['Logical_Switch'].rows.values():
print sw.name
# To do multiple operations in a single transaction
with api.transaction(check_error=True) as tr:
sw = tr.add(api.ls_add("myotherswitch"))
p = tr.add(api.lsp_add("myotherswitch", "aport"))
print sw.result.name
print p.result.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment