aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/python/vpp_papi
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2016-09-12 22:00:32 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2016-09-23 13:18:46 +0000
commit57c3d66c55580f2ced6993ada22274941237fcd5 (patch)
tree55a856b3ddcc4f9e5284c7bc42b0126616825366 /vpp-api/python/vpp_papi
parent5fef9e523df67a96f3b9aedcec373e65f590b001 (diff)
Python API: Preparation for RPM/DEB packaging.
Recheck. Repackage the Python API binding to include all necessary modules in a single Python package. Change-Id: I5e35141d413bfb1aad650217e1ca07d85646c349 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vpp-api/python/vpp_papi')
-rw-r--r--vpp-api/python/vpp_papi/__init__.py1
-rw-r--r--vpp-api/python/vpp_papi/vpp_api_base.py2
-rw-r--r--vpp-api/python/vpp_papi/vpp_papi.py38
3 files changed, 23 insertions, 18 deletions
diff --git a/vpp-api/python/vpp_papi/__init__.py b/vpp-api/python/vpp_papi/__init__.py
index 19d78a3a05d..6688ffb8ced 100644
--- a/vpp-api/python/vpp_papi/__init__.py
+++ b/vpp-api/python/vpp_papi/__init__.py
@@ -1,4 +1,3 @@
__import__('pkg_resources').declare_namespace(__name__)
from . vpp_papi import *
-
diff --git a/vpp-api/python/vpp_papi/vpp_api_base.py b/vpp-api/python/vpp_papi/vpp_api_base.py
index a1ef87a3f0a..227257fcd9b 100644
--- a/vpp-api/python/vpp_papi/vpp_api_base.py
+++ b/vpp-api/python/vpp_papi/vpp_api_base.py
@@ -58,7 +58,7 @@ def results_event_clear(context):
results[context]['e'].clear()
def results_event_wait(context, timeout):
- results[context]['e'].wait(timeout)
+ return (results[context]['e'].wait(timeout))
def results_set(context, r):
results[context]['r'] = r
diff --git a/vpp-api/python/vpp_papi/vpp_papi.py b/vpp-api/python/vpp_papi/vpp_papi.py
index 174e61d7e9e..42ddcdc341e 100644
--- a/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/vpp-api/python/vpp_papi/vpp_papi.py
@@ -20,15 +20,15 @@ from __future__ import print_function
import signal, os, sys
from struct import *
-scriptdir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(scriptdir)
import vpp_api
from vpp_api_base import *
# Import API definitions. The core VPE API is imported into main namespace
import memclnt
+
+# Cheating a bit, importing it into this namespace as well as a module.
+import vpe
from vpe import *
-vpe = sys.modules['vpe']
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
@@ -67,7 +67,7 @@ def msg_handler(msg):
#
# Collect results until control ping
#
- if id[0] == vpe.VL_API_CONTROL_PING_REPLY:
+ if id[0] == VL_API_CONTROL_PING_REPLY:
results_event_set(context)
waiting_for_reply_clear()
return
@@ -82,7 +82,14 @@ def msg_handler(msg):
results_event_set(context)
waiting_for_reply_clear()
+def handler(signum, frame):
+ print('Signal handler called with signal', signum)
+ raise IOError("Couldn't connect to VPP!")
+
def connect(name):
+ # Set the signal handler
+ signal.signal(signal.SIGALRM, handler)
+
signal.alarm(3) # 3 second
rv = vpp_api.connect(name, msg_handler)
signal.alarm(0)
@@ -90,20 +97,16 @@ def connect(name):
#
# Assign message id space for plugins
#
- plugin_map_plugins()
-
+ try:
+ plugin_map_plugins()
+ except:
+ return -1
return rv
def disconnect():
rv = vpp_api.disconnect()
return rv
-# CLI convenience wrapper
-def cli_exec(cmd):
- cmd += '\n'
- r = cli_inband(len(cmd), cmd)
- return r.reply[0].decode().rstrip('\x00')
-
def register_event_callback(callback):
event_callback_set(callback)
@@ -112,6 +115,7 @@ def plugin_name_to_id(plugin, name_to_id_table, base):
m = globals()[plugin]
except KeyError:
m = sys.modules[plugin]
+
for name in name_to_id_table:
setattr(m, name, name_to_id_table[name] + base)
@@ -126,11 +130,10 @@ def plugin_map_plugins():
#
version = plugins[p]['version']
name = p + '_' + format(version, '08x')
- r = memclnt.get_first_msg_id(name.encode('ascii'))
- ## TODO: Add error handling / raise exception
+ r = memclnt.get_first_msg_id(name)
if r.retval != 0:
- eprint('Failed getting first msg id for:', p)
- continue
+ eprint('Failed getting first msg id for:', p, r, name)
+ raise
# Set base
base = r.first_msg_id
@@ -153,6 +156,8 @@ def plugin_map_plugins():
#
memclnt.msg_id_base_set(1)
plugins['memclnt']['base'] = 1
+
+# vpe
msg_id_base_set(len(plugins['memclnt']['func_table']) + 1)
plugins['vpe']['base'] = len(plugins['memclnt']['func_table']) + 1
api_func_table = []
@@ -160,3 +165,4 @@ api_func_table.append(None)
api_func_table[1:] = plugins['memclnt']['func_table'] + plugins['vpe']['func_table']
plugin_name_to_id('memclnt', plugins['memclnt']['name_to_id_table'], 1)
plugin_name_to_id('vpe', plugins['vpe']['name_to_id_table'], plugins['vpe']['base'])
+plugin_name_to_id(__name__, plugins['vpe']['name_to_id_table'], plugins['vpe']['base'])