From f9d9e30a0fb724f3ccb1b7e2145bb0330fb273f7 Mon Sep 17 00:00:00 2001 From: Huang Haibin Date: Wed, 12 Sep 2018 20:05:21 +0800 Subject: Add post handler of flavor handler for infra Change-Id: Ic140ba963c30a86c9755b0b1d0d0f813bb0ab2f0 Issue-ID: MULTICLOUD-250 Signed-off-by: Huang Haibin --- pike/pike/resource/views/infra_workload.py | 70 ++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py index 9ef249d0..20ad67d6 100644 --- a/pike/pike/resource/views/infra_workload.py +++ b/pike/pike/resource/views/infra_workload.py @@ -39,24 +39,60 @@ class InfraWorkload(APIView): self._logger.debug("META: %s" % request.META) try : - - # stub response - resp_template = { - "template_type": "heat", - "workload_id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c", - "template_response": - { - "stack": { - "id": "3095aefc-09fb-4bc7-b1f0-f21a304e864c", - "links": [ - { - "href": "http://192.168.123.200:8004/v1/eb1c63a4f77141548385f113a28f0f52/stacks/teststack/3095aefc-09fb-4bc7-b1f0-f21a304e864c", - "rel": "self" - } - ] - } + vim = VimDriverUtils.get_vim_info(vimid) + cloud_owner, regionid = extsys.decode_vim_id(vimid) + + data = request.data + oof_directive = data["oof_directive"] + template_type = data["template_type"] + template_data = data["template_data"] + + resp_template = None + if "heat" == template_type: + tenant_name = None + 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']} + + if template_data.has_key("parameters"): + paramters = template_data["parameters"] + else: + self._logger.error("we can't find parameters in heat template") + return Response(data=None, status=HTTP_400_BADREQUEST) + + for directive in template_data["directives"]: + if directive["type"] == "vnfc": + for directive2 in directive["directives"]: + if directive2["type"] == flavor_directive: + flavor_label = directive2[0]["attribute_name"] + flavor_value = directive2[0]["attribute_value"] + if parameters.has_key(flavor_label): + template_data["parameters"][flavor_label] = flavor_value + else: + self._logger.warn("we can't find the flavor_label: %s" % + flavor_label) + + req_body = template_data + sess = VimDriverUtils.get_session(vim, tenant_name) + resp = sess.post(req_resource, + data = req_body, + endpoint_filter = service) + + resp_template = { + "template_type": template_type, + "workload_id": resp["stack"]["id"], + "template_response": resp } - } + + elif "tosca" == template_type: + #TODO + self._logger.info("TBD") + else: + self._logger.warn("This template type is not supported") + self._logger.info("RESP with data> result:%s" % resp_template) return Response(data=resp_template, status=status.HTTP_201_CREATED) -- cgit 1.2.3-korg