コード例 #1
0
ファイル: __init__.py プロジェクト: rgacogne/pyroute2
    def __init__(self, serve=None):
        self._ioc = IOCore()
        self.namespaces = set()
        self.resources = set()

        # start services
        serve = serve or []
        if type(serve) not in (tuple, list, set):
            serve = [serve]

        for host in serve:
            self.serve(host)
コード例 #2
0
ファイル: __init__.py プロジェクト: hegusung/pyroute2
    def __init__(self, serve=None):
        self._ioc = IOCore()
        self.namespaces = set()
        self.resources = set()

        # start services
        serve = serve or []
        if type(serve) not in (tuple, list, set):
            serve = [serve]

        for host in serve:
            self.serve(host)
コード例 #3
0
ファイル: test_messaging.py プロジェクト: rgacogne/pyroute2
class TestIOBroker(object):

    def setup(self):
        self.ioc1 = IOCore(secret='bala')
        self.ioc1.serve('tcp://localhost:9824')
        self.ioc2 = IOCore()
        self.host = self.ioc2.connect('tcp://localhost:9824')
        self.ioc2.register('bala', self.host[1])

    def teardown(self):
        self.ioc2.release()
        self.ioc1.release()

    def test_err_connect(self):
        try:
            self.ioc1.connect('tcp://localhost:404')
        except RuntimeError:
            pass

    def test_err_discover(self):
        try:
            self.ioc1.discover('non_existent')
        except RuntimeError:
            pass

    def _test_stop(self):
        #
        # FIXME
        #
        # this test stopped to work properly after the
        # broker became a separate process
        self.ioc2.command(IPRCMD_STOP, addr=self.host[1])

    def test_reload(self):
        self.ioc2.command(IPRCMD_RELOAD, addr=self.host[1])

    def test_provide_remove(self):
        self.ioc2.provide('/dala')
        self.ioc2.remove('/dala')

    def test_fail_access(self):
        self.ioc2.unregister(self.host[1])
        try:
            self.ioc2.command(IPRCMD_STOP, addr=self.host[1])
        except RuntimeError:
            pass
        self.ioc2.register('bala', self.host[1])

    def test_fail_disconnect(self):
        try:
            self.ioc2.disconnect('invalid_uid')
        except RuntimeError:
            pass

    def test_fail_connect(self):
        try:
            self.ioc2.connect('unix://\0invalid_socket')
        except RuntimeError:
            pass

    def test_fail_subscribe(self):
        try:
            self.ioc2.command(IPRCMD_SUBSCRIBE)
        except RuntimeError:
            pass
コード例 #4
0
ファイル: test_messaging.py プロジェクト: rgacogne/pyroute2
 def setup(self):
     self.ioc1 = IOCore(secret='bala')
     self.ioc1.serve('tcp://localhost:9824')
     self.ioc2 = IOCore()
     self.host = self.ioc2.connect('tcp://localhost:9824')
     self.ioc2.register('bala', self.host[1])
コード例 #5
0
'''
Push/pull using raw IOCore

tcp -- control connection
udp -- data push
'''
from pyroute2 import IOCore
from pyroute2.iocore import NLT_DGRAM


ioc1 = IOCore()
ioc1.serve('tcp://0.0.0.0:9824')
ioc1.serve('udp://0.0.0.0:9824')
ioc1.provide('push')

ioc2 = IOCore()
(uid, addr) = ioc2.connect('tcp://localhost:9824')
ioc2.connect('udp://localhost:9824')
port = ioc2.discover('push', addr)
ioc2.push((addr, port), 'hello, world!', NLT_DGRAM)

print('waiting message from client')
ioc1.monitor()
msg = ioc1.get()[0]

print(msg)
ioc2.release()
ioc1.release()
コード例 #6
0
ファイル: push_client.py プロジェクト: chantra/pyroute2
from pyroute2 import IOCore
from pyroute2.iocore import NLT_DGRAM

ioc = IOCore()
(uid, addr) = ioc.connect('tcp://localhost:9824')
ioc.connect('udp://localhost:9824')
port = ioc.discover('push', addr)
ioc.push((addr, port), 'hello, world!', NLT_DGRAM)
ioc.release()
コード例 #7
0
ファイル: __init__.py プロジェクト: hegusung/pyroute2
class Node(object):

    def __init__(self, serve=None):
        self._ioc = IOCore()
        self.namespaces = set()
        self.resources = set()

        # start services
        serve = serve or []
        if type(serve) not in (tuple, list, set):
            serve = [serve]

        for host in serve:
            self.serve(host)

    def register(self, namespace):
        namespace._ioc = self._ioc
        self.namespaces.add(namespace)
        # register public methods
        # .. _ioc-callbacks:
        for name in dir(namespace):
            item = getattr(namespace, name, None)
            public = getattr(item, 'public', False)

            if public:
                self._ioc.register_callback(item, predicate(name))

    def serve(self, host):
        path = urlparse.urlparse(host).path
        self._ioc.serve(host)
        if path not in self.resources:
            self.resources.add(path)
            self._ioc.provide(path)

    def get(self):
        return self._ioc.get()[0]

    def mirror(self):
        self._ioc.monitor()
        self._ioc.mirror()

    def connect(self, host):
        '''
        Return REQ/REP interface to another node
        '''
        return ReqRepInterface(self._ioc, host)

    def target(self, host, dgram=None, flags=None):
        '''
        Return PUSH interface to another node
        '''
        return PushInterface(self._ioc, host, dgram, flags)

    def shutdown(self):
        self._ioc.release()
コード例 #8
0
ファイル: __init__.py プロジェクト: rgacogne/pyroute2
class Node(object):
    def __init__(self, serve=None):
        self._ioc = IOCore()
        self.namespaces = set()
        self.resources = set()

        # start services
        serve = serve or []
        if type(serve) not in (tuple, list, set):
            serve = [serve]

        for host in serve:
            self.serve(host)

    def register(self, namespace):
        namespace._ioc = self._ioc
        self.namespaces.add(namespace)
        # register public methods
        # .. _ioc-callbacks:
        for name in dir(namespace):
            item = getattr(namespace, name, None)
            public = getattr(item, 'public', False)

            if public:
                self._ioc.register_callback(item, predicate(name))

    def serve(self, host):
        path = urlparse.urlparse(host).path
        self._ioc.serve(host)
        if path not in self.resources:
            self.resources.add(path)
            self._ioc.provide(path)

    def get(self):
        return self._ioc.get()[0]

    def mirror(self):
        self._ioc.monitor()
        self._ioc.mirror()

    def connect(self, host):
        '''
        Return REQ/REP interface to another node
        '''
        return ReqRepInterface(self._ioc, host)

    def target(self, host, dgram=None, flags=None):
        '''
        Return PUSH interface to another node
        '''
        return PushInterface(self._ioc, host, dgram, flags)

    def shutdown(self):
        self._ioc.release()
コード例 #9
0
ファイル: push_server.py プロジェクト: chantra/pyroute2
from pyroute2 import IOCore

ioc = IOCore()
ioc.serve('tcp://0.0.0.0:9824')
ioc.serve('udp://0.0.0.0:9824')
ioc.provide('push')

print('waiting message from client')
ioc.monitor()
msg = ioc.get()[0]

print(msg)
ioc.release()