コード例 #1
0
    def _request(self, name, request=None):
        if not self.is_connected():
            raise self.APIError('BESS daemon not connected')

        req_fn = getattr(self.stub, name)
        if request is None:
            request = bess_msg.EmptyRequest()
        response = req_fn(request)

        if response.error.err != 0:
            err = response.error.err
            errmsg = response.error.errmsg
            if errmsg == '':
                errmsg = '(error message is not given)'
            details = response.error.details
            if details == '':
                details = None
            raise self.Error(err, errmsg, details)

        if self.debug:
            req = proto_conv.protobuf_to_dict(request)
            res = proto_conv.protobuf_to_dict(response)
            print '====', req_fn._method
            print '--->', type(request).__name__
            if req:
                pprint.pprint(req)
            print '<---', type(response).__name__
            if res:
                pprint.pprint(res)

        return response
コード例 #2
0
ファイル: bess.py プロジェクト: rlaprade/bess
    def _request(self, name, request=None):
        if not self.is_connected():
            if self.is_connection_broken():
                # The channel got abnormally (and asynchronously) disconnected,
                # but RPCError has not been raised yet?
                raise self.RPCError('Broken RPC channel')
            else:
                raise self.APIError('BESS daemon not connected')

        req_fn = getattr(self.stub, name)
        if request is None:
            request = bess_msg.EmptyRequest()

        if self.debug:
            print '====', req_fn._method
            req = proto_conv.protobuf_to_dict(request)
            print '--->', type(request).__name__
            if req:
                pprint.pprint(req)

        try:
            response = req_fn(request)
        except grpc._channel._Rendezvous as e:
            raise self.RPCError(str(e))

        if self.debug:
            print '<---', type(response).__name__
            res = proto_conv.protobuf_to_dict(response)
            if res:
                pprint.pprint(res)

        if response.error.err != 0:
            err = response.error.err
            errmsg = response.error.errmsg
            if errmsg == '':
                errmsg = '(error message is not given)'
            details = response.error.details
            if details == '':
                details = None
            raise self.Error(err, errmsg, details)

        return response
コード例 #3
0
    def test_protobuf_to_dict(self):
        pb = bess_msg.CreatePortResponse()
        pb.error.err = 1
        pb.error.errmsg = 'bar'
        pb.error.details = ''
        pb.name = 'foo'

        true_result = {
            'error': {
                'err': 1,
                'errmsg': 'bar',
            },
            'name': 'foo'
        }
        result = proto_conv.protobuf_to_dict(pb)
        self.assertEqual(true_result, result)
コード例 #4
0
ファイル: bess.py プロジェクト: rlaprade/bess
 def get_link_status(self, name):
     request = bess_msg.GetLinkStatusRequest()
     request.name = name
     return proto_conv.protobuf_to_dict(
         self._request('GetLinkStatus', request))