From 5792d7d7e1ff32ef0edfc432bd86a8fb348622c3 Mon Sep 17 00:00:00 2001 From: tierno Date: Fri, 30 Aug 2019 15:37:12 +0000 Subject: [PATCH] provide version in json format Change-Id: I69140a3655a0cf95212eae1022d6d34eec30a198 Signed-off-by: tierno --- osm_nbi/__init__.py | 2 +- osm_nbi/html_out.py | 2 ++ osm_nbi/nbi.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/osm_nbi/__init__.py b/osm_nbi/__init__.py index 2569c9e..1e02f66 100644 --- a/osm_nbi/__init__.py +++ b/osm_nbi/__init__.py @@ -12,5 +12,5 @@ # under the License. ## -version = '6.0.2.post0' +version = '6.0.2.post1' version_date = '2018-08-30' diff --git a/osm_nbi/html_out.py b/osm_nbi/html_out.py index a8823bd..871d502 100644 --- a/osm_nbi/html_out.py +++ b/osm_nbi/html_out.py @@ -143,6 +143,8 @@ def format(data, request, response, toke_info): return else: return html_auth2.format(error=data) + if request.path_info in ("/version", "/system"): + return "
" + yaml.safe_dump(data, explicit_start=False, indent=4, default_flow_style=False) + "
" body = html_body.format(item=request.path_info) if response.status and response.status > 202: body += html_body_error.format(yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False)) diff --git a/osm_nbi/nbi.py b/osm_nbi/nbi.py index 1085ebc..03e8727 100644 --- a/osm_nbi/nbi.py +++ b/osm_nbi/nbi.py @@ -557,7 +557,7 @@ class Server(object): return string of dictionary data according to requested json, yaml, xml. By default json :param data: response to be sent. Can be a dict, text or file :param token_info: Contains among other username and project - :param _format: The format to be set as Content-Type ir data is a file + :param _format: The format to be set as Content-Type if data is a file :return: None """ accept = cherrypy.request.headers.get("Accept") @@ -621,7 +621,8 @@ class Server(object): elif args or kwargs: raise NbiException("Invalid URL or query string for version", HTTPStatus.METHOD_NOT_ALLOWED) # TODO include version of other modules, pick up from some kafka admin message - return "
NBI:\n    version: {}\n    date: {}\n".format(nbi_version, nbi_version_date)
+            osm_nbi_version = {"version": nbi_version, "date": nbi_version_date}
+            return self._format_out(osm_nbi_version)
         except NbiException as e:
             cherrypy.response.status = e.http_code.value
             problem_details = {
-- 
2.25.1