class Helper(object):
@staticmethod
- def MultiCloudIdentityHelper(multicloud_api_prefix, cloud_owner, cloud_region_id, uri, data={}, header=''):
+ def MultiCloudIdentityHelper(multicloud_api_prefix, cloud_owner,
+ cloud_region_id, uri, data={}, header=''):
auth_api_url_format = "/{f_cloudowner}/{f_cloudregionid}/identity{f_uri}"
auth_api_url = auth_api_url_format.format(f_cloudowner=cloud_owner,
f_cloudregionid=cloud_region_id,
# The consumer of this api must be attaching to the same management network of multicloud,
# The constraints comes from the returned catalog endpoint url e.g. "http://10.0.14.1:80/api/multicloud-titaniumcloud/v0/pod25_RegionOne/identity/v3"
@staticmethod
- def MultiCloudServiceHelper(cloud_owner, cloud_region_id, v2_token_resp_json, service_type, uri, data=None, method="GET",):
+ def MultiCloudServiceHelper(
+ cloud_owner, cloud_region_id, v2_token_resp_json, service_type,
+ uri, data=None, method="GET"):
# get endpoint from token response
token = v2_token_resp_json["access"]["token"]["id"]
catalogs = v2_token_resp_json["access"]["serviceCatalog"]
self._logger = logger
super(InfraWorkloadHelper, self).__init__()
- def workload_create(self, vimid, workload_data):
+ def workload_create(self, vimid, workload_data, project_idorname=None):
'''
Instantiate a stack over target cloud region (OpenStack instance)
:param vimid:
:param workload_data:
+ :param project_idorname
:return: result code, status enum, status reason
result code: 0-ok, otherwise error
status enum: "CREATE_IN_PROGRESS", "CREATE_FAILED"
retcode, v2_token_resp_json, os_status = \
helper.MultiCloudIdentityHelper(
settings.MULTICLOUD_API_V1_PREFIX,
- cloud_owner, regionid, "/v2.0/tokens"
+ cloud_owner, regionid, "/v2.0/tokens",
+ {"Project": project_idorname}
)
if retcode > 0 or not v2_token_resp_json:
errmsg = "authenticate fails:%s,%s, %s" %\
self._logger.info("RESP with data> result:%s" % content)
return retcode, "CREATE_FAILED", content
- def workload_update(self, vimid, stack_id, otherinfo=None):
+ def workload_update(self, vimid, stack_id, otherinfo=None, project_idorname=None):
'''
update heat resource to AAI for the specified cloud region and tenant
The resources includes: vserver, vserver/l-interface,
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")
+ helper.MultiCloudIdentityHelper(
+ settings.MULTICLOUD_API_V1_PREFIX,
+ cloud_owner, regionid, "/v2.0/tokens",
+ {"Project": project_idorname})
if retcode > 0:
errmsg = "authenticate fails:%s, %s, %s" %\
(cloud_owner, regionid, v2_token_resp_json)
# self._logger.debug("aai_transactions :%s" % aai_transactions)
return 0, "UPDATE_COMPLETE", "succeed"
- def workload_delete(self, vimid, stack_id, otherinfo=None):
+ def workload_delete(self, vimid, stack_id, otherinfo=None, project_idorname=None):
'''
remove heat resource from AAI for the specified cloud region and tenant
The resources includes: vserver, vserver/l-interface,
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")
+ helper.MultiCloudIdentityHelper(
+ settings.MULTICLOUD_API_V1_PREFIX,
+ cloud_owner, regionid, "/v2.0/tokens",
+ {"Project": project_idorname})
if retcode > 0:
errmsg = "authenticate fails:%s, %s, %s" %\
(cloud_owner, regionid, v2_token_resp_json)
return 12, "DELETE_FAILED", e.message
pass
- def workload_status(self, vimid, stack_id=None, stack_name=None, otherinfo=None):
+ def workload_status(self, vimid, stack_id=None, stack_name=None, otherinfo=None, project_idorname=None):
'''
get workload status by either stack id or name
:param vimid:
retcode, v2_token_resp_json, os_status = \
helper.MultiCloudIdentityHelper(
settings.MULTICLOUD_API_V1_PREFIX,
- cloud_owner, regionid, "/v2.0/tokens")
+ cloud_owner, regionid, "/v2.0/tokens",
+ {"Project": project_idorname})
if retcode > 0 or not v2_token_resp_json:
errmsg = "authenticate fails:%s, %s, %s" % \
self._logger.info("data: %s" % request.data)
self._logger.debug("META: %s" % request.META)
+ # Get the specified tenant id
+ specified_project_idorname = request.META.get("Project", None)
+
resp_template = {
"template_type": "HEAT",
"workload_id": workloadid,
# post to create a new stack,
# stack id available only after creating a stack is done
progress_code, progress_status, progress_msg =\
- worker_self.workload_create(vimid, request.data)
+ worker_self.workload_create(vimid, request.data, specified_project_idorname)
resp_template["workload_status"] = progress_status
resp_template["workload_status_reason"] = progress_msg
backlog_item = {
"id": workloadid,
"worker": worker_self.workload_update,
- "payload": (worker_self, vimid, workloadid, request.data),
+ "payload": (worker_self, vimid, workloadid,
+ request.data, specified_project_idorname),
"repeat": 0, # one time job
# format of status: retcode:0 is ok, otherwise error code from http status, Status ENUM, Message
"status": (
self._logger.info("vimid, workload id: %s, %s" % (vimid, workloadid))
self._logger.debug("META: %s" % request.META)
+ # Get the specified tenant id
+ specified_project_idorname = request.META.get("Project", None)
+
resp_template = {
"template_type": "HEAT",
"workload_id": workloadid,
# by name
progress_code, progress_status, progress_msg =\
worker_self.workload_status(
- vimid, stack_name=workload_name)
+ vimid, stack_name=workload_name,
+ project_idorname=specified_project_idorname
+ )
else:
# by id
progress_code, progress_status, progress_msg =\
worker_self.workload_status(
- vimid, stack_id=workloadid)
+ vimid, stack_id=workloadid,
+ project_idorname=specified_project_idorname
+ )
resp_template["workload_status"] = progress_status
resp_template["workload_status_reason"] = progress_msg
)
progress_code, progress_status, progress_msg =\
worker_self.workload_status(
- vimid, stack_id=workloadid)
+ vimid, stack_id=workloadid,
+ project_idorname=specified_project_idorname)
resp_template["workload_status"] = progress_status
resp_template["workload_status_reason"] = progress_msg
self._logger.info("vimid, workload id: %s, %s" % (vimid, workloadid))
self._logger.debug("META: %s" % request.META)
+ # Get the specified tenant id
+ specified_project_idorname = request.META.get("Project", None)
+
resp_template = {
"template_type": "HEAT",
"workload_id": workloadid,
backlog_item = {
"id": workloadid,
"worker": worker_self.workload_delete,
- "payload": (worker_self, vimid, workloadid, request.data),
+ "payload": (worker_self, vimid, workloadid, request.data,
+ specified_project_idorname),
"repeat": 0, # one time job
# format of status: retcode:0 is ok, otherwise error code from http status, Status ENUM, Message
"status": (
# try 2: reuse the input: template_data
return template_data
- def workload_create(self, vimid, workload_data):
+ def workload_create(self, vimid, workload_data, project_idorname=None):
'''
Instantiate a stack over target cloud region (OpenStack instance)
The template for workload will be fetched from sdc client
retcode, v2_token_resp_json, os_status = \
helper.MultiCloudIdentityHelper(
settings.MULTICLOUD_API_V1_PREFIX,
- cloud_owner, regionid, "/v2.0/tokens"
+ cloud_owner, regionid, "/v2.0/tokens",
+ {"Project": project_idorname}
)
if retcode > 0 or not v2_token_resp_json:
errmsg = "authenticate fails:%s,%s, %s" %\