Discussion:
[Ryu-devel] [PATCH 0/5] Update OVSDB manager library and docs
Satoshi Fujimoto
2017-06-16 02:45:42 UTC
Permalink
These patch adds the property to EventNewOVSDBConnection
to get more informations through it.
These also provide some improvements on OVSDB manager.

Satoshi Fujimoto (5):
service/ovsdb: Add properties to EventNewOVSDBConnection
service/ovsdb: Avoid to use dict as default argument
doc/ovsdb_manager: Update Sample Code
service/ovsdb: Use Python 2/3 compatible code
service/ovsdb: Use dict.items() instead of six.iteritems()

doc/source/library_ovsdb_manager.rst | 6 +++++-
ryu/services/protocols/ovsdb/api.py | 13 ++++++-------
ryu/services/protocols/ovsdb/client.py | 7 ++++---
ryu/services/protocols/ovsdb/event.py | 10 +++++++---
ryu/services/protocols/ovsdb/manager.py | 2 +-
5 files changed, 23 insertions(+), 15 deletions(-)
--
2.7.4
Satoshi Fujimoto
2017-06-16 02:45:44 UTC
Permalink
Using mutable values as default arguments will cause unexpected behavior.

Signed-off-by: Satoshi Fujimoto <***@gmail.com>
---
ryu/services/protocols/ovsdb/client.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ryu/services/protocols/ovsdb/client.py b/ryu/services/protocols/ovsdb/client.py
index d0ec5b0..68d6866 100644
--- a/ryu/services/protocols/ovsdb/client.py
+++ b/ryu/services/protocols/ovsdb/client.py
@@ -286,7 +286,8 @@ class RemoteOvsdb(app_manager.RyuApp):
@classmethod
def factory(cls, sock, address, probe_interval=None, min_backoff=None,
max_backoff=None, schema_tables=None,
- schema_exclude_columns={}, *args, **kwargs):
+ schema_exclude_columns=None, *args, **kwargs):
+ schema_exclude_columns = schema_exclude_columns or {}
ovs_stream = stream.Stream(sock, None, None)
connection = jsonrpc.Connection(ovs_stream)
schemas = discover_schemas(connection)
--
2.7.4
Satoshi Fujimoto
2017-06-16 02:45:43 UTC
Permalink
Currently, EventNewOVSDBConnection only has system_id.
This patch let the class has RemoteOvsdb to get more
informations through it.

e.g.)
@set_ev_cls(ovsdb_event.EventNewOVSDBConnection)
def handle_new_ovsdb_connection(self, ev):
system_id = ev.system_id
remote_addr = ev.client.address

Signed-off-by: Satoshi Fujimoto <***@gmail.com>
---
ryu/services/protocols/ovsdb/event.py | 10 +++++++---
ryu/services/protocols/ovsdb/manager.py | 2 +-
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ryu/services/protocols/ovsdb/event.py b/ryu/services/protocols/ovsdb/event.py
index 486e5c7..f162b52 100644
--- a/ryu/services/protocols/ovsdb/event.py
+++ b/ryu/services/protocols/ovsdb/event.py
@@ -119,13 +119,17 @@ class EventModifyReply(ryu_event.EventReplyBase):


class EventNewOVSDBConnection(ryu_event.EventBase):
- def __init__(self, system_id):
+ def __init__(self, client):
super(EventNewOVSDBConnection, self).__init__()
- self.system_id = system_id
+ self.client = client

def __str__(self):
return '%s<system_id=%s>' % (self.__class__.__name__,
- self.system_id)
+ self.client.system_id)
+
+ @property
+ def system_id(self):
+ return self.client.system_id


class EventReadRequest(ryu_event.EventRequestBase):
diff --git a/ryu/services/protocols/ovsdb/manager.py b/ryu/services/protocols/ovsdb/manager.py
index 86a2d1f..9822503 100644
--- a/ryu/services/protocols/ovsdb/manager.py
+++ b/ryu/services/protocols/ovsdb/manager.py
@@ -146,7 +146,7 @@ class OVSDB(app_manager.RyuApp):
if app:
self._clients[app.name] = app
app.start()
- ev = event.EventNewOVSDBConnection(app.system_id)
+ ev = event.EventNewOVSDBConnection(app)
self.send_event_to_observers(ev)

else:
--
2.7.4
Satoshi Fujimoto
2017-06-16 02:45:46 UTC
Permalink
Signed-off-by: Satoshi Fujimoto <***@gmail.com>
---
ryu/services/protocols/ovsdb/client.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ryu/services/protocols/ovsdb/client.py b/ryu/services/protocols/ovsdb/client.py
index 68d6866..7e7d271 100644
--- a/ryu/services/protocols/ovsdb/client.py
+++ b/ryu/services/protocols/ovsdb/client.py
@@ -155,12 +155,12 @@ def _filter_schema(schema, schema_tables, exclude_table_columns):
"""

tables = {}
- for tbl_name, tbl_data in schema['tables'].iteritems():
+ for tbl_name, tbl_data in schema['tables'].items():
if not schema_tables or tbl_name in schema_tables:
columns = {}

exclude_columns = exclude_table_columns.get(tbl_name, [])
- for col_name, col_data in tbl_data['columns'].iteritems():
+ for col_name, col_data in tbl_data['columns'].items():
if col_name in exclude_columns:
continue
--
2.7.4
Satoshi Fujimoto
2017-06-16 02:45:45 UTC
Permalink
Signed-off-by: Satoshi Fujimoto <***@gmail.com>
---
doc/source/library_ovsdb_manager.rst | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/doc/source/library_ovsdb_manager.rst b/doc/source/library_ovsdb_manager.rst
index 104f4b6..b36a933 100644
--- a/doc/source/library_ovsdb_manager.rst
+++ b/doc/source/library_ovsdb_manager.rst
@@ -20,6 +20,7 @@ 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

@@ -28,8 +29,11 @@ on a bridge.
@set_ev_cls(ovsdb_event.EventNewOVSDBConnection)
def handle_new_ovsdb_connection(self, ev):
system_id = ev.system_id
+ addr = ev.client.address
self.logger.info('New OVSDB connection from system id %s',
- systemd_id)
+ system_id)
+ self.logger.info('The connection address id %s',
+ addr)

def create_port(self, system_id, bridge_name, name):
new_iface_uuid = uuid.uuid4()
--
2.7.4
Satoshi Fujimoto
2017-06-16 02:45:47 UTC
Permalink
Signed-off-by: Satoshi Fujimoto <***@gmail.com>
---
ryu/services/protocols/ovsdb/api.py | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/ryu/services/protocols/ovsdb/api.py b/ryu/services/protocols/ovsdb/api.py
index 9443d75..21ef5b0 100644
--- a/ryu/services/protocols/ovsdb/api.py
+++ b/ryu/services/protocols/ovsdb/api.py
@@ -12,13 +12,12 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-from ryu.lib import dpid as dpidlib
-from ryu.services.protocols.ovsdb import event as ovsdb_event
-
-import six

import uuid

+from ryu.lib import dpid as dpidlib
+from ryu.services.protocols.ovsdb import event as ovsdb_event
+

def _get_table_row(table, attr_name, attr_value, tables):
sentinel = object()
@@ -381,7 +380,7 @@ def set_controller(manager, system_id, bridge_name,
controller.connection_mode = ['out-of-band']

if controller_info:
- for key, val in six.iteritems(controller_info):
+ for key, val in controller_info.items():
setattr(controller, key, val)

bridge.controller = [controller]
@@ -421,11 +420,11 @@ def create_port(manager, system_id, bridge_name, port_info, iface_info=None,
port_info['name'] = default_port_name

iface = insert(tables['Interface'], iface_insert_uuid)
- for key, val in six.iteritems(iface_info):
+ for key, val in iface_info.items():
setattr(iface, key, val)

port = insert(tables['Port'], port_insert_uuid)
- for key, val in six.iteritems(port_info):
+ for key, val in port_info.items():
setattr(port, key, val)

port.interfaces = [iface]
--
2.7.4
FUJITA Tomonori
2017-06-23 06:35:47 UTC
Permalink
On Fri, 16 Jun 2017 11:45:42 +0900
Post by Satoshi Fujimoto
These patch adds the property to EventNewOVSDBConnection
to get more informations through it.
These also provide some improvements on OVSDB manager.
service/ovsdb: Add properties to EventNewOVSDBConnection
service/ovsdb: Avoid to use dict as default argument
doc/ovsdb_manager: Update Sample Code
service/ovsdb: Use Python 2/3 compatible code
service/ovsdb: Use dict.items() instead of six.iteritems()
doc/source/library_ovsdb_manager.rst | 6 +++++-
ryu/services/protocols/ovsdb/api.py | 13 ++++++-------
ryu/services/protocols/ovsdb/client.py | 7 ++++---
ryu/services/protocols/ovsdb/event.py | 10 +++++++---
ryu/services/protocols/ovsdb/manager.py | 2 +-
5 files changed, 23 insertions(+), 15 deletions(-)
Pushed, thanks!

Loading...