From afa281d0f6b8cf5726a40c8fd2d31cab23faa889 Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Wed, 29 May 2024 01:31:25 +0900 Subject: [PATCH] refactor: add json_metadata for performance Signed-off-by: Jongmin Kim --- .../service/cloud_service_service.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/spaceone/inventory/service/cloud_service_service.py b/src/spaceone/inventory/service/cloud_service_service.py index 26562a9..1bab865 100644 --- a/src/spaceone/inventory/service/cloud_service_service.py +++ b/src/spaceone/inventory/service/cloud_service_service.py @@ -111,6 +111,15 @@ def create_resource(self, params: dict) -> CloudService: elif "data" not in params: raise ERROR_REQUIRED_PARAMETER(key="data") + if "json_metadata" in params: + params["metadata"] = utils.load_json(params["json_metadata"]) + if not isinstance(params["metadata"], dict): + raise ERROR_INVALID_PARAMETER_TYPE( + key="json_metadata", type=type(params["metadata"]) + ) + + del params["json_metadata"] + domain_id = params["domain_id"] workspace_id = params["workspace_id"] secret_project_id = self.transaction.get_meta("secret.project_id") @@ -198,9 +207,6 @@ def update_resource(self, params: dict) -> CloudService: ch_mgr: ChangeHistoryManager = self.locator.get_manager("ChangeHistoryManager") if "json_data" in params: - _LOGGER.debug( - f"[update_resource] load json_data: {params['cloud_service_id']}" - ) params["data"] = utils.load_json(params["json_data"]) if not isinstance(params["data"], dict): raise ERROR_INVALID_PARAMETER_TYPE( @@ -209,6 +215,15 @@ def update_resource(self, params: dict) -> CloudService: del params["json_data"] + if "json_metadata" in params: + params["metadata"] = utils.load_json(params["json_metadata"]) + if not isinstance(params["metadata"], dict): + raise ERROR_INVALID_PARAMETER_TYPE( + key="json_metadata", type=type(params["metadata"]) + ) + + del params["json_metadata"] + secret_project_id = self.transaction.get_meta("secret.project_id") cloud_service_id = params["cloud_service_id"] @@ -281,7 +296,6 @@ def update_resource(self, params: dict) -> CloudService: params = self.cloud_svc_mgr.merge_data(params, old_cloud_svc_data) - _LOGGER.debug(f"[update_resource] merged params: {params}") cloud_svc_vo = self.cloud_svc_mgr.update_cloud_service_by_vo( params, cloud_svc_vo )