summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiaohua Zhang <xiaohua.zhang@windriver.com>2019-04-08 04:37:12 +0000
committerXiaohua Zhang <xiaohua.zhang@windriver.com>2019-04-08 04:37:12 +0000
commitdfad902004f1ff9b86651f10ae5cc13814d954a0 (patch)
treee3066d174e0c16ea9540f4df7ae05e12925db629
parentcdaa33fc9ee8acefdfabbdbb5c3f04c57fd3d932 (diff)
Add multi-tenant support for infra_workload API
Change-Id: I0e792dc29967ed3f3fc487dd7fbff4039e601d92 Issue-ID: MULTICLOUD-543 Signed-off-by: Xiaohua Zhang <xiaohua.zhang@windriver.com>
-rw-r--r--share/common/msapi/helper.py7
-rw-r--r--share/newton_base/resource/infra_workload_helper.py27
-rw-r--r--share/starlingx_base/resource/infra_workload.py33
3 files changed, 47 insertions, 20 deletions
diff --git a/share/common/msapi/helper.py b/share/common/msapi/helper.py
index bd8932f3..b2ff1d6b 100644
--- a/share/common/msapi/helper.py
+++ b/share/common/msapi/helper.py
@@ -33,7 +33,8 @@ logger = logging.getLogger(__name__)
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,
@@ -48,7 +49,9 @@ class Helper(object):
# 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"]
diff --git a/share/newton_base/resource/infra_workload_helper.py b/share/newton_base/resource/infra_workload_helper.py
index 4805a5e4..bfc3fc86 100644
--- a/share/newton_base/resource/infra_workload_helper.py
+++ b/share/newton_base/resource/infra_workload_helper.py
@@ -33,11 +33,12 @@ class InfraWorkloadHelper(object):
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"
@@ -84,7 +85,8 @@ class InfraWorkloadHelper(object):
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" %\
@@ -112,7 +114,7 @@ class InfraWorkloadHelper(object):
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,
@@ -129,8 +131,10 @@ class InfraWorkloadHelper(object):
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)
@@ -291,7 +295,7 @@ class InfraWorkloadHelper(object):
# 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,
@@ -308,8 +312,10 @@ class InfraWorkloadHelper(object):
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)
@@ -387,7 +393,7 @@ class InfraWorkloadHelper(object):
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:
@@ -403,7 +409,8 @@ class InfraWorkloadHelper(object):
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" % \
diff --git a/share/starlingx_base/resource/infra_workload.py b/share/starlingx_base/resource/infra_workload.py
index 912d3f69..745e9f03 100644
--- a/share/starlingx_base/resource/infra_workload.py
+++ b/share/starlingx_base/resource/infra_workload.py
@@ -43,6 +43,9 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
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,
@@ -61,7 +64,7 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
# 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
@@ -82,7 +85,8 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
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": (
@@ -136,6 +140,9 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
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,
@@ -172,12 +179,16 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
# 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
@@ -196,7 +207,8 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
)
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
@@ -234,6 +246,9 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
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,
@@ -262,7 +277,8 @@ class InfraWorkload(newton_infra_workload.InfraWorkload):
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": (
@@ -446,7 +462,7 @@ class InfraWorkloadHelper(infra_workload_helper.InfraWorkloadHelper):
# 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
@@ -497,7 +513,8 @@ class InfraWorkloadHelper(infra_workload_helper.InfraWorkloadHelper):
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" %\