]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make _val_to_py and _py_to_val not private
authorrossella <rsblendido@suse.com>
Fri, 5 Jun 2015 11:09:35 +0000 (13:09 +0200)
committerrossella <rsblendido@suse.com>
Fri, 5 Jun 2015 12:23:47 +0000 (12:23 +0000)
Move _val_to_py and _py_to_val to neutron.agent.ovsdb.api
and remove the underscore since they will be used by other
classes.

Change-Id: I3a469ab3b1c1d83ad20dc6c77f1072fc6d546419

neutron/agent/ovsdb/api.py
neutron/agent/ovsdb/impl_vsctl.py

index 2d6634ae695fa1d51bb131d69661d37c816e2056..e696f8e85d60da4df14529a33bac0bae2e6d2d25 100644 (file)
@@ -13,6 +13,8 @@
 #    under the License.
 
 import abc
+import collections
+import uuid
 
 from oslo_config import cfg
 from oslo_utils import importutils
@@ -312,3 +314,25 @@ class API(object):
         :type bridge:  string
         :returns:      :class:`Command` with list of port names result
         """
+
+
+def val_to_py(val):
+    """Convert a json ovsdb return value to native python object"""
+    if isinstance(val, collections.Sequence) and len(val) == 2:
+        if val[0] == "uuid":
+            return uuid.UUID(val[1])
+        elif val[0] == "set":
+            return [val_to_py(x) for x in val[1]]
+        elif val[0] == "map":
+            return {val_to_py(x): val_to_py(y) for x, y in val[1]}
+    return val
+
+
+def py_to_val(pyval):
+    """Convert python value to ovs-vsctl value argument"""
+    if isinstance(pyval, bool):
+        return 'true' if pyval is True else 'false'
+    elif pyval == '':
+        return '""'
+    else:
+        return pyval
index 4fd8937d346c671f5fcb7ee8e2dcb5dd70556af1..4a1339f8329b50cde717bb3c4cbef2dd524cd7b7 100644 (file)
@@ -14,7 +14,6 @@
 
 import collections
 import itertools
-import uuid
 
 from oslo_log import log as logging
 from oslo_serialization import jsonutils
@@ -132,7 +131,7 @@ class DbCommand(BaseCommand):
         for record in data:
             obj = {}
             for pos, heading in enumerate(headings):
-                obj[heading] = _val_to_py(record[pos])
+                obj[heading] = ovsdb.val_to_py(record[pos])
             results.append(obj)
         self._result = results
 
@@ -254,32 +253,11 @@ def _set_colval_args(*col_values):
             col, op, val = entry
         if isinstance(val, collections.Mapping):
             args += ["%s:%s%s%s" % (
-                col, k, op, _py_to_val(v)) for k, v in val.items()]
+                col, k, op, ovsdb.py_to_val(v)) for k, v in val.items()]
         elif (isinstance(val, collections.Sequence)
                 and not isinstance(val, six.string_types)):
-            args.append("%s%s%s" % (col, op, ",".join(map(_py_to_val, val))))
+            args.append(
+                "%s%s%s" % (col, op, ",".join(map(ovsdb.py_to_val, val))))
         else:
-            args.append("%s%s%s" % (col, op, _py_to_val(val)))
+            args.append("%s%s%s" % (col, op, ovsdb.py_to_val(val)))
     return args
-
-
-def _val_to_py(val):
-    """Convert a json ovsdb return value to native python object"""
-    if isinstance(val, collections.Sequence) and len(val) == 2:
-        if val[0] == "uuid":
-            return uuid.UUID(val[1])
-        elif val[0] == "set":
-            return [_val_to_py(x) for x in val[1]]
-        elif val[0] == "map":
-            return {_val_to_py(x): _val_to_py(y) for x, y in val[1]}
-    return val
-
-
-def _py_to_val(pyval):
-    """Convert python value to ovs-vsctl value argument"""
-    if isinstance(pyval, bool):
-        return 'true' if pyval is True else 'false'
-    elif pyval == '':
-        return '""'
-    else:
-        return pyval