aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-07-23 09:53:06 -0400
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-07-31 13:20:52 +0000
commita47a5f20a3b5bb2191d40c47fc0a9976376680c8 (patch)
tree81d8f1e8a0c198f0d3b34818df99fd9ba6f8fd1e /src/vpp-api/python/vpp_papi
parent07f87546c2b29ac07ec652420c8c3aef6a7faec6 (diff)
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 <pvinci@vinciconsulting.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_format.py9
1 files changed, 8 insertions, 1 deletions
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),
}