summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHuang Haibin <haibin.huang@intel.com>2018-09-15 09:37:34 +0800
committerHuang Haibin <haibin.huang@intel.com>2018-09-19 08:09:58 +0800
commitfcb71cf0d0193fe1f85c3233e8c90db04434af92 (patch)
treedea7a74ccec4b6301a4ae065bcf5a15d3bd3b2a9
parent5a925b04bee358d573e0f49caa37690399c32204 (diff)
Add delete of flavor handler for infra workload
Change-Id: I009a22179eaf2851ed4674ed08ba3c78ca4f1492 Issue-ID: MULTICLOUD-250 Signed-off-by: Huang Haibin <haibin.huang@intel.com>
-rw-r--r--pike/pike/resource/views/infra_workload.py49
1 files changed, 42 insertions, 7 deletions
diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py
index 20ad67d6..cf352bc1 100644
--- a/pike/pike/resource/views/infra_workload.py
+++ b/pike/pike/resource/views/infra_workload.py
@@ -136,15 +136,50 @@ class InfraWorkload(APIView):
return Response(data={'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- def delete(self, request, vimid=""):
- self._logger.info("vimid: %s" % (vimid))
+ def delete(self, request, vimid="", requri=""):
+ self._logger.info("vimid, requri: %s" % (vimid, requri))
self._logger.debug("META: %s" % request.META)
try :
-
- # stub response
+ # we just support heat template
+ workload_id = requri
+ tenant_name = None
+ vim = VimDriverUtils.get_vim_info(vimid)
+ cloud_owner, regionid = extsys.decode_vim_id(vimid)
+ v2_token_resp_json = helper.MultiCloudIdentityHelper(settings.MULTICLOUD_API_V1_PREFIX,
+ cloud_owner, regionid, "/v2.0/tokens")
+ if not v2_token_resp_json:
+ logger.error("authenticate fails:%s,%s" % (cloud_owner, regionid))
+ return
+ tenant_id = v2_token_resp_json["access"]["token"]["tenant"]["id"]
+ interface = 'public'
+ service = {'service_type': 'orchestration',
+ 'interface': interface,
+ 'region_id': vim['openstack_region_id']
+ if vim.get('openstack_region_id')
+ else vim['cloud_region_id']}
+
+ req_body = template_data
+ url_get = "/v1/%s/stacks" % (tenant_id)
+ sess = VimDriverUtils.get_session(vim, tenant_name)
+ get_resp = sess.get(url_get,
+ data = req_body,
+ endpoint_filter = service)
+ stack_info = get_resp.json()
+ stacks = stack_info["stacks"]
+ stack_name = ""
+ for stack in stacks:
+ if workload_id == stack["id"]:
+ stack_name = stack["stack_name"]
+ break
+
+ req_source = "/v1/%s/stacks/%s/%s" % (tenant_id, stack_name, workload_id)
+ resp = sess.delete(req_resource,
+ endpoint_filter = service)
+
+ resp_status = status.HTTP_204_NO_CONTENT
self._logger.info("RESP with data> result:%s" % "")
- return Response(status=status.HTTP_204_NO_CONTENT)
+ return Response(status=resp_status)
except VimDriverNewtonException as e:
self._logger.error("Plugin exception> status:%s,error:%s"
% (e.status_code, e.content))
@@ -178,9 +213,9 @@ class APIv1InfraWorkload(InfraWorkload):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1InfraWorkload, self).get(request, vimid)
- def delete(self, request, cloud_owner="", cloud_region_id=""):
+ def delete(self, request, cloud_owner="", cloud_region_id="", requri=""):
#self._logger.info("cloud owner, cloud region id, data: %s,%s, %s" % (cloud_owner, cloud_region_id, request.data))
#self._logger.debug("META: %s" % request.META)
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
- return super(APIv1InfraWorkload, self).delete(request, vimid)
+ return super(APIv1InfraWorkload, self).delete(request, vimid, requri)