summaryrefslogtreecommitdiffstats
path: root/share/newton_base/openoapi/vport.py
diff options
context:
space:
mode:
authorYun Huang <yun.huang@windriver.com>2018-04-27 16:33:43 +0800
committerYun Huang <yun.huang@windriver.com>2018-04-27 16:33:43 +0800
commit8c129a5264fc69fafc8f307a65f98153cfe2d4b3 (patch)
treed096d2e16d472c051b680ce69e90ba2ce422cadf /share/newton_base/openoapi/vport.py
parentf32d865eb8ef6b91e1d55ad6bb8da80cda8b5cdf (diff)
Logging enhancement for openo vport API
Change-Id: I2e976f5b63c5af60d9643a4a7cbbaea9a6ef21ea Issue-ID: MULTICLOUD-178 Signed-off-by: Yun Huang <yun.huang@windriver.com>
Diffstat (limited to 'share/newton_base/openoapi/vport.py')
-rw-r--r--share/newton_base/openoapi/vport.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/share/newton_base/openoapi/vport.py b/share/newton_base/openoapi/vport.py
index e112d38c..7f916d3d 100644
--- a/share/newton_base/openoapi/vport.py
+++ b/share/newton_base/openoapi/vport.py
@@ -40,14 +40,18 @@ class Vports(APIView):
]
def get(self, request, vimid="", tenantid="", portid=""):
- logger.debug("Ports--get::> %s" % request.data)
+ logger.info("vimid, tenantid, portid = %s,%s,%s" % (vimid, tenantid, portid))
+ if request.data:
+ logger.debug("With data = %s" % request.data)
+ pass
try:
# prepare request resource to vim instance
query = VimDriverUtils.get_query_part(request)
content, status_code = self.get_ports(query, vimid, tenantid, portid)
-
+ logger.info("response with status = %s" % 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()))
@@ -58,7 +62,6 @@ class Vports(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def get_ports(self, query="", vimid="", tenantid="", portid=""):
- logger.debug("Ports--get_ports::> %s" % portid)
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
@@ -73,7 +76,13 @@ class Vports(APIView):
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
+ logger.info("making request with URI:%s" % req_resouce)
resp = sess.get(req_resouce, 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()
vim_dict = {
"vimName": vim["name"],
@@ -104,7 +113,10 @@ class Vports(APIView):
return {}, 500
def post(self, request, vimid="", tenantid="", portid=""):
- logger.debug("Ports--post::> %s" % request.data)
+ logger.info("vimid, tenantid, portid = %s,%s,%s" % (vimid, tenantid, portid))
+ if request.data:
+ logger.debug("With data = %s" % request.data)
+ pass
try:
#check if already created: name
query = "name=%s" % request.data["name"]
@@ -125,6 +137,7 @@ class Vports(APIView):
#otherwise create a new one
return self.create_port(request, vimid, tenantid)
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()))
@@ -135,7 +148,6 @@ class Vports(APIView):
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def create_port(self, request, vimid, tenantid):
- logger.debug("Ports--create::> %s" % request.data)
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
if sess:
@@ -158,8 +170,11 @@ class Vports(APIView):
VimDriverUtils.replace_key_by_mapping(port,
self.keys_mapping, True)
req_body = json.JSONEncoder().encode({"port": port})
+ logger.info("making request with URI:%s" % req_resouce)
+ logger.debug("with data:%s" % req_body)
resp = sess.post(req_resouce, data=req_body,
endpoint_filter=self.service)
+ logger.info("request returns with status %s" % resp.status_code)
resp_body = resp.json()["port"]
#use only 1 fixed_ip
tmpips = resp_body.pop("fixed_ips", None)
@@ -178,7 +193,10 @@ class Vports(APIView):
return {}
def delete(self, request, vimid="", tenantid="", portid=""):
- logger.debug("Ports--delete::> %s" % request.data)
+ logger.info("vimid, tenantid, portid = %s,%s,%s" % (vimid, tenantid, portid))
+ if request.data:
+ logger.debug("With data = %s" % request.data)
+ pass
try:
# prepare request resource to vim instance
req_resouce = "v2.0/ports"
@@ -190,9 +208,12 @@ class Vports(APIView):
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenantid)
+ logger.info("making request with URI:%s" % req_resouce)
resp = sess.delete(req_resouce, endpoint_filter=self.service)
+ logger.info("request returns with status %s" % resp.status_code)
return Response(status=resp.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()))