summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_papi.py
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2018-12-11 13:04:01 +0100
committerDamjan Marion <dmarion@me.com>2018-12-12 00:34:43 +0000
commit0bcad32b3870f9998fa1393418081cdda685272f (patch)
tree0fcb518ffa5553bbec94c219cbc33fef48dbede3 /src/vpp-api/python/vpp_papi/vpp_papi.py
parent41b25cf6380d1420b24e191cd7e95cbce1e7cfdc (diff)
PAPI: Allow ipaddress object as argument and return values from API calls
The API calls that use any of vl_api_address_t, vl_api_ip4_address, vl_api_ip6_address_t, vl_api_prefix_t, vl_api_ip4_prefix_t, vl_api_ip6_prefix_t now accepts either the old style dictionary, a text string (2001:db8::/32) or an ipaddress ojbect. Unless it is called with '_no_type_conversion':True, it will also return an appropriate ipaddress object. Change-Id: I84e4a1577bd57f6b5ae725f316a523988b6a955b Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_papi.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index c37334cd4e5..32abe14da94 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -28,7 +28,6 @@ import weakref
import atexit
from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType, BaseTypes
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
-from . vpp_format import VPPFormat
if sys.version[0] == '2':
import Queue as queue
@@ -56,11 +55,11 @@ def vpp_atexit(vpp_weakref):
vpp_instance.logger.debug('Cleaning up VPP on exit')
vpp_instance.disconnect()
-
-def vpp_iterator(d):
- if sys.version[0] == '2':
+if sys.version[0] == '2':
+ def vpp_iterator(d):
return d.iteritems()
- else:
+else:
+ def vpp_iterator(d):
return d.items()
@@ -409,7 +408,8 @@ class VPP(object):
# Create function for client side messages.
if name in self.services:
- if 'stream' in self.services[name] and self.services[name]['stream']:
+ if 'stream' in self.services[name] and \
+ self.services[name]['stream']:
multipart = True
else:
multipart = False
@@ -493,7 +493,7 @@ class VPP(object):
else:
raise VPPIOError(2, 'RPC reply message received in event handler')
- def decode_incoming_msg(self, msg):
+ def decode_incoming_msg(self, msg, no_type_conversion=False):
if not msg:
self.logger.warning('vpp_api.read failed')
return
@@ -508,7 +508,7 @@ class VPP(object):
if not msgobj:
raise VPPIOError(2, 'Reply message undefined')
- r, size = msgobj.unpack(msg)
+ r, size = msgobj.unpack(msg, ntc=no_type_conversion)
return r
def msg_handler_async(self, msg):
@@ -535,7 +535,7 @@ class VPP(object):
d = set(kwargs.keys()) - set(msg.field_by_name.keys())
if d:
raise VPPValueError('Invalid argument {} to {}'
- .format(list(d), msg.name))
+ .format(list(d), msg.name))
def _call_vpp(self, i, msg, multipart, **kwargs):
"""Given a message, send the message and await a reply.
@@ -560,6 +560,8 @@ class VPP(object):
context = kwargs['context']
kwargs['_vl_msg_id'] = i
+ no_type_conversion = kwargs.pop('_no_type_conversion', False)
+
try:
if self.transport.socket_index:
kwargs['client_index'] = self.transport.socket_index
@@ -582,7 +584,7 @@ class VPP(object):
msg = self.transport.read()
if not msg:
raise VPPIOError(2, 'VPP API client: read failed')
- r = self.decode_incoming_msg(msg)
+ r = self.decode_incoming_msg(msg, no_type_conversion)
msgname = type(r).__name__
if context not in r or r.context == 0 or context != r.context:
# Message being queued