papi: add support for enumflag part 1 of 2
Allow for papi to accept the new enumflag type.
Change-Id: I8d8dc8fdb122e9a1b1881f5b2558635c75e4a299
Type: feature
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
(cherry picked from commit 299abebe2942b4c78b85f9f3b8843f8213bf1efe)
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index e22b88b..b4d4686 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -31,7 +31,7 @@
import atexit
import time
from . vpp_format import verify_enum_hint
-from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType
+from . vpp_serializer import VPPType, VPPEnumType, VPPEnumFlagType, VPPUnionType
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
try:
@@ -48,7 +48,7 @@
logger.addHandler(logging.NullHandler())
__all__ = ('FuncWrapper', 'VPP', 'VppApiDynamicMethodHolder',
- 'VppEnum', 'VppEnumType',
+ 'VppEnum', 'VppEnumType', 'VppEnumFlag',
'VPPIOError', 'VPPRuntimeError', 'VPPValueError',
'VPPApiClient', )
@@ -72,6 +72,11 @@
pass
+@metaclass(VppEnumType)
+class VppEnumFlag:
+ pass
+
+
def vpp_atexit(vpp_weakref):
"""Clean up VPP connection on shutdown."""
vpp_instance = vpp_weakref()
@@ -80,8 +85,6 @@
vpp_instance.disconnect()
-
-
def add_convenience_methods():
# provide convenience methods to IP[46]Address.vapi_af
def _vapi_af(self):
@@ -281,7 +284,12 @@
types[t[0]] = {'type': 'enum', 'data': t}
except KeyError:
pass
-
+ try:
+ for t in api['enumflags']:
+ t[0] = 'vl_api_' + t[0] + '_t'
+ types[t[0]] = {'type': 'enum', 'data': t}
+ except KeyError:
+ pass
try:
for t in api['unions']:
t[0] = 'vl_api_' + t[0] + '_t'
@@ -318,6 +326,12 @@
VPPEnumType(t[0], t[1:])
except ValueError:
unresolved[k] = v
+ if not vpp_get_type(k):
+ if v['type'] == 'enumflag':
+ try:
+ VPPEnumFlagType(t[0], t[1:])
+ except ValueError:
+ unresolved[k] = v
elif v['type'] == 'union':
try:
VPPUnionType(t[0], t[1:])