summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pike/pike/resource/views/infra_workload.py102
1 files changed, 53 insertions, 49 deletions
diff --git a/pike/pike/resource/views/infra_workload.py b/pike/pike/resource/views/infra_workload.py
index 17ace535..38c2a920 100644
--- a/pike/pike/resource/views/infra_workload.py
+++ b/pike/pike/resource/views/infra_workload.py
@@ -36,68 +36,72 @@ class InfraWorkload(APIView):
def __init__(self):
self._logger = logger
- def post(self, request, vimid=""):
- self._logger.info("vimid, data: %s, %s" % (vimid, request.data))
+ def post(self, request, vimid="", requri=""):
+ self._logger.info("vimid, requri: %s, %s" % (vimid, requri))
+ self._logger.info("data: %s" % request.data)
self._logger.debug("META: %s" % request.META)
try :
- vim = VimDriverUtils.get_vim_info(vimid)
- cloud_owner, regionid = extsys.decode_vim_id(vimid)
-
data = request.data
- oof_directive = data["oof_directive"]
+ oof_directive = data["oof_directives"]
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)
+ if template_type and "heat" == template_type.lower():
+ # update heat parameters from oof_directive
+ parameters = template_data.get("parameters", {})
+ for directive in oof_directive.get("directives", []):
+ if directive["type"] == "vnfc":
+ for directive2 in directive.get("directives", []):
+ if directive2["type"] in ["flavor_directives", "sriovNICNetwork_directives"]:
+ for attr in directives2.get("attributes", []):
+ label_name = directive2[0]["attribute_name"]
+ label_value = directive2[0]["attribute_value"]
+ if parameters.has_key(label_name):
+ template_data["parameters"][label_name] = label_value
+ else:
+ self._logger.warn("There is no parameter exist: %s" % label_name)
+
+ # update parameters
+ template_data["parameters"] = parameters
+
+ #reset to make sure "files" are empty
+ template_data["file"] = {}
+
+ #authenticate
+ cloud_owner, regionid = extsys.decode_vim_id(vimid)
+ # should go via multicloud proxy so that the selflink is updated by multicloud
+ retcode, v2_token_resp_json, os_status = helper.MultiCloudIdentityHelper(
+ settings.MULTICLOUD_API_V1_PREFIX,
+ cloud_owner, regionid, "/v2.0/tokens")
+ if retcode > 0 or not v2_token_resp_json:
+ logger.error("authenticate fails:%s,%s, %s" %
+ (cloud_owner, regionid, v2_token_resp_json))
+ return
+
+ service_type = "orchestration"
+ resource_uri = "/stacks"
+ self._logger.info("retrieve stack resources, URI:%s" % resource_uri)
+ retcode, content, os_status = helper.MultiCloudServiceHelper(cloud_owner,
+ regionid, v2_token_resp_json, service_type,
+ resource_uri, None, "POST")
+ stack1 = content.get('stack', None) if retcode == 0 and content else None
resp_template = {
"template_type": template_type,
- "workload_id": resp["stack"]["id"],
- "template_response": resp
+ "workload_id": stack1["id"] if stack1 else "",
+ "template_response": content
}
+ self._logger.info("RESP with data> result:%s" % resp_template)
- elif "tosca" == template_type:
- #TODO
- self._logger.info("TBD")
- else:
- self._logger.warn("This template type is not supported")
+ return Response(data=resp_template, status=os_status)
+ else:
+ msg = "The template type %s is not supported" % (template_type)
+ self._logger.warn(msg)
+ return Response(data={"error":msg}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- self._logger.info("RESP with data> result:%s" % resp_template)
- return Response(data=resp_template, status=status.HTTP_201_CREATED)
except VimDriverNewtonException as e:
self._logger.error("Plugin exception> status:%s,error:%s"
% (e.status_code, e.content))
@@ -359,12 +363,12 @@ class APIv1InfraWorkload(InfraWorkload):
super(APIv1InfraWorkload, self).__init__()
# self._logger = logger
- def post(self, request, cloud_owner="", cloud_region_id=""):
+ def post(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).post(request, vimid)
+ return super(APIv1InfraWorkload, self).post(request, vimid, requri)
def get(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))