From a47a5f20a3b5bb2191d40c47fc0a9976376680c8 Mon Sep 17 00:00:00 2001 From: Paul Vinciguerra Date: Tue, 23 Jul 2019 09:53:06 -0400 Subject: api papi: add alias for timestamp(datetime)/timedelta Now that we have support for f64: - create explicit types for timestamp(datetime)/timedelta - update log_details to use timestamp and remove redundant string representation. If you need the string representation, in python do str(timestamp). If you prefer the raw f64 value, the client can pass in the _no_type_conversion option. Type: feature Change-Id: I547b5fa7122d2afa12628b7db0192c23babbbae8 Signed-off-by: Paul Vinciguerra --- src/vpp-api/python/vpp_papi/vpp_format.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/vpp-api') diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py index b58dad3c1b5..7d2dcba491a 100644 --- a/src/vpp-api/python/vpp_papi/vpp_format.py +++ b/src/vpp-api/python/vpp_papi/vpp_format.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +import datetime from socket import inet_pton, AF_INET6, AF_INET import socket import ipaddress @@ -117,6 +117,11 @@ conversion_table = { 'MACAddress': lambda o: o.packed, 'str': lambda s: macaddress.mac_pton(s) }, + 'vl_api_timestamp_t': + { + 'datetime.datetime': lambda o: + (o - datetime.datetime(1970, 1, 1)).total_seconds() + } } @@ -142,4 +147,6 @@ conversion_unpacker_table = { 'vl_api_address_t': lambda o: unformat_api_address_t(o), 'vl_api_prefix_t': lambda o: unformat_api_prefix_t(o), 'vl_api_mac_address_t': lambda o: macaddress.MACAddress(o), + 'vl_api_timestamp_t': lambda o: datetime.datetime.fromtimestamp(o), + 'vl_api_timedelta_t': lambda o: datetime.timedelta(seconds=o), } -- cgit 1.2.3-korg