BGPSpeaker: Fix unresolved references in Python3
Additionally, this patch enforces the the explicit relative imports Reviewed-by: Fumihiko Kakuma <kakuma@valinux.co.jp> Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
9393af3f06
commit
c263089e72
|
@ -18,6 +18,8 @@
|
|||
|
||||
This API can be used by various services like RPC, CLI, IoC, etc.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
import traceback
|
||||
|
@ -208,7 +210,7 @@ def call(symbol, **kwargs):
|
|||
LOG.info("API method %s called with args: %s", symbol, str(kwargs))
|
||||
|
||||
# TODO(PH, JK) improve the way api function modules are loaded
|
||||
import all # noqa
|
||||
from . import all # noqa
|
||||
if not is_call_registered(symbol):
|
||||
message = 'Did not find any method registered by symbol %s' % symbol
|
||||
raise MethodNotFound(message)
|
||||
|
|
|
@ -15,12 +15,16 @@
|
|||
"""
|
||||
Defines some base class related to managing green threads.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import abc
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import socket
|
||||
import time
|
||||
import traceback
|
||||
import weakref
|
||||
|
||||
import netaddr
|
||||
|
||||
from ryu.lib import hub
|
||||
|
@ -38,12 +42,6 @@ from ryu.services.protocols.bgp.utils.evtlet import LoopingCall
|
|||
# Logger instance for this module.
|
||||
LOG = logging.getLogger('bgpspeaker.base')
|
||||
|
||||
|
||||
try:
|
||||
from collections import OrderedDict
|
||||
except ImportError:
|
||||
from ordereddict import OrderedDict
|
||||
|
||||
# Pointer to active/available OrderedDict.
|
||||
OrderedDict = OrderedDict
|
||||
|
||||
|
@ -456,7 +454,7 @@ class Sink(object):
|
|||
self.index = Sink.next_index()
|
||||
|
||||
# Event used to signal enqueing.
|
||||
from utils.evtlet import EventletIOFactory
|
||||
from .utils.evtlet import EventletIOFactory
|
||||
self.outgoing_msg_event = EventletIOFactory.create_custom_event()
|
||||
|
||||
self.messages_queued = 0
|
||||
|
|
|
@ -13,10 +13,11 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from configuration_manager import ConfigurationManager
|
||||
from import_map_manager import ImportMapManager
|
||||
from peer_manager import PeerManager
|
||||
from table_manager import TableCoreManager
|
||||
from .configuration_manager import ConfigurationManager
|
||||
from .import_map_manager import ImportMapManager
|
||||
from .peer_manager import PeerManager
|
||||
from .table_manager import TableCoreManager
|
||||
__all__ = ['ImportMapManager', 'TableCoreManager', 'PeerManager',
|
||||
'ConfigurationManager']
|
||||
|
|
|
@ -226,6 +226,10 @@ class NonVrfPathProcessingMixin(object):
|
|||
because they are processed at VRF level, so different logic applies.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._core_service = None # not assigned yet
|
||||
self._known_path_list = []
|
||||
|
||||
def _best_path_lost(self):
|
||||
self._best_path = None
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
from route_formatter_mixin import RouteFormatterMixin
|
||||
from __future__ import absolute_import
|
||||
|
||||
from .route_formatter_mixin import RouteFormatterMixin
|
||||
|
||||
from ryu.services.protocols.bgp.operator.command import Command
|
||||
from ryu.services.protocols.bgp.operator.command import CommandsResponse
|
||||
|
|
|
@ -17,12 +17,7 @@ class RouteFormatterMixin(object):
|
|||
|
||||
@classmethod
|
||||
def _format_family(cls, dest_list):
|
||||
if six.PY3:
|
||||
import io
|
||||
msg = io.StringIO()
|
||||
else:
|
||||
import StringIO
|
||||
msg = StringIO.StringIO()
|
||||
msg = six.StringIO()
|
||||
|
||||
def _append_path_info(buff, path, is_best, show_prefix):
|
||||
aspath = path.get('aspath')
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import pprint
|
||||
|
||||
|
@ -9,7 +11,7 @@ from ryu.services.protocols.bgp.operator.commands.responses import \
|
|||
WrongParamResp
|
||||
from ryu.services.protocols.bgp.operator.views.conf import ConfDetailView
|
||||
from ryu.services.protocols.bgp.operator.views.conf import ConfDictView
|
||||
from route_formatter_mixin import RouteFormatterMixin
|
||||
from .route_formatter_mixin import RouteFormatterMixin
|
||||
|
||||
LOG = logging.getLogger('bgpspeaker.operator.commands.show.vrf')
|
||||
|
||||
|
@ -77,6 +79,8 @@ class Routes(Command, RouteFormatterMixin):
|
|||
|
||||
|
||||
class CountRoutesMixin(object):
|
||||
api = None # not assigned yet
|
||||
|
||||
def _count_routes(self, vrf_name, vrf_rf):
|
||||
return len(self.api.get_single_vrf_routes(vrf_name, vrf_rf))
|
||||
|
||||
|
|
|
@ -13,7 +13,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves import intern
|
||||
import six
|
||||
if six.PY3:
|
||||
from sys import intern
|
||||
|
||||
|
||||
class CircularListType(object):
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
import weakref
|
||||
from six.moves import intern
|
||||
|
||||
dict_name = intern('_internable_dict')
|
||||
|
||||
|
||||
#
|
||||
|
@ -40,6 +37,12 @@ class Internable(object):
|
|||
Internable to work.
|
||||
"""
|
||||
|
||||
_internable_stats = None
|
||||
_internable_dict = None
|
||||
|
||||
def __init__(self):
|
||||
self._interned = False
|
||||
|
||||
class Stats(object):
|
||||
|
||||
def __init__(self):
|
||||
|
@ -55,17 +58,17 @@ class Internable(object):
|
|||
return str(self.d)
|
||||
|
||||
@classmethod
|
||||
def _internable_init(kls):
|
||||
def _internable_init(cls):
|
||||
# Objects to be interned are held as keys in a dictionary that
|
||||
# only holds weak references to keys. As a result, when the
|
||||
# last reference to an interned object goes away, the object
|
||||
# will be removed from the dictionary.
|
||||
kls._internable_dict = weakref.WeakKeyDictionary()
|
||||
kls._internable_stats = Internable.Stats()
|
||||
cls._internable_dict = weakref.WeakKeyDictionary()
|
||||
cls._internable_stats = Internable.Stats()
|
||||
|
||||
@classmethod
|
||||
def intern_stats(kls):
|
||||
return kls._internable_stats
|
||||
def intern_stats(cls):
|
||||
return cls._internable_stats
|
||||
|
||||
def intern(self):
|
||||
"""Returns either itself or a canonical copy of itself."""
|
||||
|
@ -78,26 +81,26 @@ class Internable(object):
|
|||
# Got to find or create an interned object identical to this
|
||||
# one. Auto-initialize the class if need be.
|
||||
#
|
||||
kls = self.__class__
|
||||
cls = self.__class__
|
||||
|
||||
if not hasattr(kls, dict_name):
|
||||
kls._internable_init()
|
||||
if not cls._internable_dict:
|
||||
cls._internable_init()
|
||||
|
||||
obj = kls._internable_dict.get(self)
|
||||
obj = cls._internable_dict.get(self)
|
||||
if (obj):
|
||||
# Found an interned copy.
|
||||
kls._internable_stats.incr('found')
|
||||
cls._internable_stats.incr('found')
|
||||
return obj
|
||||
|
||||
# Create an interned copy. Take care to only keep a weak
|
||||
# reference to the object itself.
|
||||
def object_collected(obj):
|
||||
kls._internable_stats.incr('collected')
|
||||
cls._internable_stats.incr('collected')
|
||||
# print("Object %s garbage collected" % obj)
|
||||
pass
|
||||
|
||||
ref = weakref.ref(self, object_collected)
|
||||
kls._internable_dict[self] = ref
|
||||
cls._internable_dict[self] = ref
|
||||
self._interned = True
|
||||
kls._internable_stats.incr('inserted')
|
||||
cls._internable_stats.incr('inserted')
|
||||
return self
|
||||
|
|
Loading…
Reference in New Issue