From 9496adf85b7ea0732d49679fdbe9c38e9c8100f8 Mon Sep 17 00:00:00 2001 From: comprelzhang Date: Sat, 8 May 2021 10:04:23 +0800 Subject: [PATCH] =?UTF-8?q?[update]=E6=9B=B4=E6=96=B0route=20entry=20=20ro?= =?UTF-8?q?ute=20table=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/apibase_backend.py | 2 +- .../network/route_entry_controller.py | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/apps/api/apibase_backend.py b/apps/api/apibase_backend.py index e0d4da5c..2f479238 100644 --- a/apps/api/apibase_backend.py +++ b/apps/api/apibase_backend.py @@ -682,7 +682,7 @@ def run_query(self, rid, region, zone, data=out_data) x_json = self.reverse_asset_object(provider=provider_object["name"], data=x_json) - x_json.update(query_data) + # x_json.update(query_data) if x_json.get("instance_type"): instance_type, resource_info = InstanceTypeObject().convert_asset(provider=provider_object["name"], diff --git a/apps/controller/network/route_entry_controller.py b/apps/controller/network/route_entry_controller.py index c2e6ef91..604963ac 100644 --- a/apps/controller/network/route_entry_controller.py +++ b/apps/controller/network/route_entry_controller.py @@ -7,6 +7,10 @@ from core.controller import BackendIdController from core.controller import BaseController from lib.uuid_util import get_uuid +from lib.logs import logger +from core.response_hooks import format_string +from apps.controller.configer.model_args import source_columns_outputs +from apps.api.configer.region import ZoneApi from apps.api.network.route_entry import RouteEntryApi from apps.api.network.route_entry import RouteEntryBackendApi from apps.controller.source_controller import BaseSourceController @@ -167,3 +171,58 @@ class RTRuleSourceController(BaseSourceController): allow_methods = ("POST",) resource = RouteEntryBackendApi() + def one_query(self, rid, provider, region, zone, secret, + resource_id, ignore_ids, **kwargs): + ''' + + :param rid: + :param provider: + :param region: + :param zone: + :param secret: + :param resource_id: + :param ignore_ids: + :param kwargs: + :return: + ''' + + result = self.fetch_source(rid=rid, provider=provider, region=region, zone=zone, + secret=secret, resource_id=resource_id, + **kwargs) + result_data = [] + + register_zones = ZoneApi().region_zones(region, provider) + + for x_result in result: + x_res = source_columns_outputs(self.resource.resource_name) + x_res.update(x_result) + + route_table_id = kwargs.get("route_table_id") + if not x_res.get("route_table_id") and route_table_id: + x_res["route_table_id"] = route_table_id + + res = {"region": region, "secret": secret, "provider": provider} + + if x_res.get("resource_id") in ignore_ids: + continue + + if x_res.get("zone") and (x_res.get("zone") not in register_zones): + logger.info("resource: %s ,zone: %s searched not in register zone, skip it" % ( + x_res.get("resource_id"), x_res.get("zone"))) + if x_res.get("x_ora_zone") and (x_res.get("x_ora_zone") not in register_zones): + continue + + x_res.pop("x_ora_zone", None) + + for x, value in x_res.items(): + if isinstance(value, dict): + res[x] = format_string(value) + else: + if value is None: + res[x] = '' + else: + res[x] = str(value) + + result_data.append(res) + + return result_data