From: rossella Date: Fri, 5 Jun 2015 11:09:35 +0000 (+0200) Subject: Make _val_to_py and _py_to_val not private X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=62d37f91872aaaefdee50e5cd1ed87456b8a6532;p=openstack-build%2Fneutron-build.git Make _val_to_py and _py_to_val not private 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 --- diff --git a/neutron/agent/ovsdb/api.py b/neutron/agent/ovsdb/api.py index 2d6634ae6..e696f8e85 100644 --- a/neutron/agent/ovsdb/api.py +++ b/neutron/agent/ovsdb/api.py @@ -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 diff --git a/neutron/agent/ovsdb/impl_vsctl.py b/neutron/agent/ovsdb/impl_vsctl.py index 4fd8937d3..4a1339f83 100644 --- a/neutron/agent/ovsdb/impl_vsctl.py +++ b/neutron/agent/ovsdb/impl_vsctl.py @@ -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