
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
2.1 KiB
2.1 KiB
OVSDB Manager library
Introduction
Ryu OVSDB Manager library allows your code to interact with devices speaking the OVSDB protocol. This enables your code to perform remote management of the devices and react to topology changes on them.
Example
The following logs all new OVSDB connections and allows creating a port on a bridge.
import uuid
from ryu.base import app_manager
from ryu.controller.handler import set_ev_cls
from ryu.services.protocols.ovsdb import api as ovsdb
from ryu.services.protocols.ovsdb import event as ovsdb_event
class MyApp(app_manager.RyuApp):
@set_ev_cls(ovsdb_event.EventNewOVSDBConnection)
def handle_new_ovsdb_connection(self, ev):
= ev.system_id
system_id = ev.client.address
addr self.logger.info('New OVSDB connection from system id %s',
system_id)self.logger.info('The connection address id %s',
addr)
def create_port(self, system_id, bridge_name, name):
= uuid.uuid4()
new_iface_uuid = uuid.uuid4()
new_port_uuid
= ovsdb.row_by_name(self, system_id, bridge_name)
bridge
def _create_port(tables, insert):
= insert(tables['Interface'], new_iface_uuid)
iface = name
iface.name type = 'internal'
iface.
= insert(tables['Port'], new_port_uuid)
port = name
port.name = [iface]
port.interfaces
= bridge.ports + [port]
bridge.ports
return (new_port_uuid, new_iface_uuid)
= ovsdb_event.EventModifyRequest(system_id, _create_port)
req = self.send_request(req)
rep
if rep.status != 'success':
self.logger.error('Error creating port %s on bridge %s: %s',
name, bridge, rep.status)return None
return rep.insert_uuids[new_port_uuid]