From a9ab01f7bc1c5c2a421d10d68d6f90b69462d6d0 Mon Sep 17 00:00:00 2001 From: Bin Yang Date: Sat, 29 Feb 2020 14:39:12 +0800 Subject: Fix bug in starlingx API handler Change-Id: I6e8aabeba8329421385f81d1ce394e70c089d10d Issue-ID: MULTICLOUD-1003 Signed-off-by: Bin Yang --- share/starlingx_base/resource/k8s_infra_workload_helper.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/share/starlingx_base/resource/k8s_infra_workload_helper.py b/share/starlingx_base/resource/k8s_infra_workload_helper.py index 5efb94e6..87309ff6 100644 --- a/share/starlingx_base/resource/k8s_infra_workload_helper.py +++ b/share/starlingx_base/resource/k8s_infra_workload_helper.py @@ -142,12 +142,14 @@ class InfraWorkloadHelper: # 2.forward infra_workload API requests with queries cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) infraUrl = multicloudK8sUrl+"/%s/%s/infra_workload" % (cloud_owner, cloud_region_id) + if workloadid: + infraUrl += ("/%s" % workloadid) if workload_query: infraUrl += ("?%s" % workload_query) # should we forward headers ? TBD logger.debug("request with url,content: %s,%s" % (infraUrl, workload_data)) - resp = requests.post(infraUrl, data=workload_data, verify=False) + resp = requests.post(infraUrl, data=json.dumps(workload_data), verify=False) # resp_template["workload_status_reason"] = resp.content logger.debug("response status,content: %s,%s" % (resp.status_code, resp.content)) return Response(data=json.loads(resp.content), status=resp.status_code) @@ -174,12 +176,15 @@ class InfraWorkloadHelper: # 1.forward infra_workload API requests with queries cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) infraUrl = multicloudK8sUrl+"/%s/%s/infra_workload" % (cloud_owner, cloud_region_id) + if workloadid: + infraUrl += ("/%s" % workloadid) if workload_query_str: infraUrl += ("?%s" % workload_query_str) # should we forward headers ? TBD logger.debug("request with url,content: %s,%s" % (infraUrl, workload_data)) - resp = requests.delete(infraUrl, data=workload_data, verify=False) + # resp = requests.delete(infraUrl, data=json.dumps(workload_data), verify=False) + resp = requests.delete(infraUrl, verify=False) # resp_template["workload_status_reason"] = resp.content logger.debug("response status,content: %s,%s" % (resp.status_code, resp.content)) return Response(data=json.loads(resp.content), status=resp.status_code) @@ -206,12 +211,15 @@ class InfraWorkloadHelper: # forward infra_workload API requests with queries cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid) infraUrl = multicloudK8sUrl+"/%s/%s/infra_workload" % (cloud_owner, cloud_region_id) + if workloadid: + infraUrl += ("/%s" % workloadid) if workload_query_str: infraUrl += ("?%s" % workload_query_str) # should we forward headers ? TBD logger.debug("request with url,content: %s,%s" % (infraUrl, workload_data)) - resp = requests.get(infraUrl, data=workload_data, verify=False) + # resp = requests.get(infraUrl, data=json.dumps(workload_data), verify=False) + resp = requests.get(infraUrl, verify=False) # resp_template["workload_status_reason"] = resp.content logger.debug("response status,content: %s,%s" % (resp.status_code, resp.content)) return Response(data=json.loads(resp.content), status=resp.status_code) -- cgit 1.2.3-korg