From f7c6546100bea244dfa0f59d5a79a34a473223ca Mon Sep 17 00:00:00 2001 From: Yun Huang Date: Tue, 24 Apr 2018 11:09:41 +0800 Subject: Logging enhancement for openo hypervisor API Change-Id: I567557ee4c70083d366c1c614dae2b953d2a18d7 Issue-ID: MULTICLOUD-178 Signed-off-by: Yun Huang --- share/newton_base/openoapi/flavor.py | 4 ++-- share/newton_base/openoapi/hypervisor.py | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) (limited to 'share/newton_base/openoapi') diff --git a/share/newton_base/openoapi/flavor.py b/share/newton_base/openoapi/flavor.py index d922be8a..1124aec4 100644 --- a/share/newton_base/openoapi/flavor.py +++ b/share/newton_base/openoapi/flavor.py @@ -138,7 +138,7 @@ class Flavors(APIView): logger.info("request returns with status %s" % resp.status_code) if resp.status_code == status.HTTP_200_OK: - logger.debug("with content:%s" % req_resouce) + logger.debug("with content:%s" % resp.json()) pass return resp @@ -163,7 +163,7 @@ class Flavors(APIView): logger.info("request returns with status %s" % resp.status_code) if resp.status_code == status.HTTP_200_OK: - logger.debug("with content:%s" % req_resouce) + logger.debug("with content:%s" % resp.json()) pass return resp diff --git a/share/newton_base/openoapi/hypervisor.py b/share/newton_base/openoapi/hypervisor.py index 147fbc44..e9201307 100755 --- a/share/newton_base/openoapi/hypervisor.py +++ b/share/newton_base/openoapi/hypervisor.py @@ -37,14 +37,22 @@ class Hypervisors(APIView): ("container_format", "containerFormat") ] - + def get(self, request, vimid="", tenantid="", hypervisorid=""): - logger.debug("hypervisors--get::> %s" % request.data) + logger.info("vimid, tenantid, hypervisorid = %s,%s,%s" % (vimid, tenantid, hypervisorid)) + if request.data: + logger.debug("With data = %s" % request.data) + pass + try: query = VimDriverUtils.get_query_part(request) content, status_code = self.get_hypervisors(query, vimid, tenantid, hypervisorid) + + logger.info("response with status = %s" % resp.status_code) + return Response(data=content, status=status_code) except VimDriverNewtonException as e: + logger.error("response with status = %s" % e.status_code) return Response(data={'error': e.content}, status=e.status_code) except HttpError as e: logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json())) @@ -54,16 +62,24 @@ class Hypervisors(APIView): return Response(data={'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - + def get_hypervisors(self, query="", vimid="", tenantid="", hypervisorid=""): - logger.debug("hypervisors--get::> %s" % hypervisorid) req_resource = "/os-hypervisors" vim = VimDriverUtils.get_vim_info(vimid) vim["domain"] = "Default" sess = VimDriverUtils.get_session(vim, tenantid) + + logger.info("making request with URI:%s" % req_resouce) + resp = sess.get(req_resource, endpoint_filter = self.service) + + logger.info("request returns with status %s" % resp.status_code) + if resp.status_code == status.HTTP_200_OK: + logger.debug("with content:%s" % resp.json()) + pass + content = resp.json() return content, resp.status_code -- cgit 1.2.3-korg