From 165a4193b8dc3fb1b50b0aa0870a270421e6f1f5 Mon Sep 17 00:00:00 2001 From: comprelzhang Date: Thu, 6 May 2021 14:25:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[update]=E4=BF=AE=E5=A4=8Durl=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/controller/configer/config_controller.py | 1 + apps/controller/configer/defines.py | 4 ++-- apps/controller/database/route.py | 2 +- apps/controller/storage/route.py | 4 ++-- apps/controller/vm/instance_type_controller.py | 11 +++++++++++ apps/controller/vm/route.py | 4 ++-- register.xml | 10 +++++----- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/apps/controller/configer/config_controller.py b/apps/controller/configer/config_controller.py index 5328d142..62d8ef06 100644 --- a/apps/controller/configer/config_controller.py +++ b/apps/controller/configer/config_controller.py @@ -39,6 +39,7 @@ def list(self, request, data, orderby=None, page=None, pagesize=None, **kwargs): data.pop(key, None) return self.resource.list(filters=data, page=page, + filter_string=filter_string, pagesize=pagesize, orderby=orderby) def before_handler(self, request, data, **kwargs): diff --git a/apps/controller/configer/defines.py b/apps/controller/configer/defines.py index b7e24dcd..48ea4577 100644 --- a/apps/controller/configer/defines.py +++ b/apps/controller/configer/defines.py @@ -452,7 +452,7 @@ }, "network_interface_attach": { "apply": { - "path": "/terraform/v1/vm/backend/network_interface/attach", + "path": "/terraform/v1/vm/backend/network_interface/apply", "method": "POST", "notnull": ['name', 'provider', 'network_interface_id', 'instance_id', 'zone', 'region'], "inputParameters": ['id', 'name', 'secret', 'provider', 'network_interface_id', 'instance_id', 'zone', @@ -460,7 +460,7 @@ "outputParameters": ['errorMessage', 'errorCode', 'id', 'resource_id'] }, "destroy": { - "path": "/terraform/v1/vm/backend/network_interface/detach", + "path": "/terraform/v1/vm/backend/network_interface/destroy", "method": "POST", "notnull": ["id"], "inputParameters": ["id"], diff --git a/apps/controller/database/route.py b/apps/controller/database/route.py index 6e8a20a1..6388c896 100644 --- a/apps/controller/database/route.py +++ b/apps/controller/database/route.py @@ -14,7 +14,7 @@ urlpatterns = [ url(r'^mysql$', mysql_instance.MysqlController()), url(r'^mysql/(?P[\w-]+)$', mysql_instance.MysqlIdController()), - url(r'^backend/mysql/create$', mysql_instance.MysqlAddController()), + url(r'^backend/mysql/apply$', mysql_instance.MysqlAddController()), url(r'^backend/mysql/destroy$', mysql_instance.MysqlDeleteController()), url(r'^backend/mysql/source$', mysql_instance.MysqlSourceController()), url(r'^backend/mysql/security_group/source$', mysql_instance.MysqlSGSourceController()), diff --git a/apps/controller/storage/route.py b/apps/controller/storage/route.py index 3acd36cc..50a7f4a9 100644 --- a/apps/controller/storage/route.py +++ b/apps/controller/storage/route.py @@ -14,8 +14,8 @@ url(r'^disk_attach$', disk_attach_controller.DiskAttachController()), url(r'^disk_attach/(?P[\w-]+)$', disk_attach_controller.DiskAttachIdController()), - url(r'^backend/disk/attach$', disk_attach_controller.DiskAttachAddController()), - url(r'^backend/disk/detach$', disk_attach_controller.DiskDetachController()), + url(r'^backend/disk/apply', disk_attach_controller.DiskAttachAddController()), + url(r'^backend/disk/destroy', disk_attach_controller.DiskDetachController()), url(r'^object_storage$', object_storage_controller.ObjectStorageController()), url(r'^object_storage/(?P[\w-]+)$', object_storage_controller.ObjectStorageIdController()), diff --git a/apps/controller/vm/instance_type_controller.py b/apps/controller/vm/instance_type_controller.py index 3a69c4d7..9199b05d 100644 --- a/apps/controller/vm/instance_type_controller.py +++ b/apps/controller/vm/instance_type_controller.py @@ -28,7 +28,18 @@ def list(self, request, data, orderby=None, page=None, pagesize=None, **kwargs): validation.allowed_key(data, ["id", "provider", "origin_name", "cpu", "memory", "provider_id", "name", "enabled"]) + + filter_string = None + for key in ["origin_name", "provider", "name", "provider_id"]: + if data.get(key): + if filter_string: + filter_string += 'and ' + key + " like '%" + data.get(key) + "%' " + else: + filter_string = key + " like '%" + data.get(key) + "%' " + data.pop(key, None) + return self.resource.resource_object.list(filters=data, page=page, + filter_string=filter_string, pagesize=pagesize, orderby=orderby) def before_handler(self, request, data, **kwargs): diff --git a/apps/controller/vm/route.py b/apps/controller/vm/route.py index f5d25195..50a501b4 100644 --- a/apps/controller/vm/route.py +++ b/apps/controller/vm/route.py @@ -29,7 +29,7 @@ url(r'^network_interface_attach$', eni_attach_controller.EniAttachController()), url(r'^network_interface_attach/(?P[\w-]+)$', eni_attach_controller.EniAttachIdController()), - url(r'^backend/network_interface/attach$', eni_attach_controller.EniAttachAddController()), - url(r'^backend/network_interface/detach$', eni_attach_controller.EniDetachController()), + url(r'^backend/network_interface/apply$', eni_attach_controller.EniAttachAddController()), + url(r'^backend/network_interface/destroy$', eni_attach_controller.EniDetachController()), ] diff --git a/register.xml b/register.xml index fc42136b..ef4be351 100644 --- a/register.xml +++ b/register.xml @@ -1090,7 +1090,7 @@ - + id name @@ -1109,7 +1109,7 @@ resource_id - + id @@ -1217,7 +1217,7 @@ errorCode - + id name @@ -1240,7 +1240,7 @@ resource_id - + id @@ -1250,7 +1250,7 @@ errorCode - + id instance_id From cfbb871e2810dbdac843fa8332579cfe84026e2f Mon Sep 17 00:00:00 2001 From: comprelzhang Date: Thu, 6 May 2021 14:26:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[update]=20=E6=9B=B4=E6=96=B0=E5=80=BC?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/apibase_backend.py | 15 +++++++++++++-- apps/api/conductor/valueReverse.py | 9 ++++++++- apps/background/resource/vm/instance_type.py | 4 +++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/apps/api/apibase_backend.py b/apps/api/apibase_backend.py index f228676c..9b2af441 100644 --- a/apps/api/apibase_backend.py +++ b/apps/api/apibase_backend.py @@ -16,6 +16,7 @@ from apps.background.resource.configr.history import HistoryObject from apps.background.resource.configr.resource import ResourceObject from apps.background.resource.configr.value_config import ValueConfigObject +from apps.background.resource.vm.instance_type import InstanceTypeObject from apps.background.resource.resource_base import CrsObject from apps.api.conductor.region import RegionConductor from apps.api.conductor.provider import ProviderConductor @@ -550,7 +551,7 @@ def outer_equivalence(self, datas, defines): def read_query_result_controller(self, provider, result, data_source_argument): # if not data_source_argument: - # raise ValueError("data_source_argument not config") + # raise ValueError("data_source_argument not config") data_source_argument = data_source_argument or '' logger.info(format_json_dumps(result)) @@ -654,7 +655,17 @@ def run_query(self, rid, region, zone, data=out_data) x_json = self.reverse_asset_object(provider=provider_object["name"], data=x_json) - result_list.append(x_json) + + if x_json.get("instance_type"): + instance_type, resource_info = InstanceTypeObject().convert_asset(provider=provider_object["name"], + asset_name=x_json.get( + "instance_type")) + x_json["instance_type"] = instance_type + resource_info.update(x_json) + result_list.append(resource_info) + + else: + result_list.append(x_json) return result_list diff --git a/apps/api/conductor/valueReverse.py b/apps/api/conductor/valueReverse.py index 5c54ed41..feb8594e 100644 --- a/apps/api/conductor/valueReverse.py +++ b/apps/api/conductor/valueReverse.py @@ -42,7 +42,14 @@ def reset_values(self, provider, resource_name, data): if resource_values_config.get(key): _values_configs = resource_values_config.get(key) # value = convert_value(value, _values_configs.get(value)) - value = ReverseProperty.format_value(value, _values_configs.get(value)) + x_value = ReverseProperty.format_value(value, _values_configs.get(value)) + + if x_value != value: + value = x_value + else: + for m_key, m_value in _values_configs.items(): + if m_value == value: + value = m_key else: logger.debug("key: %s value config is null, skip..." % key) diff --git a/apps/background/resource/vm/instance_type.py b/apps/background/resource/vm/instance_type.py index ca88ac2c..d3b11445 100644 --- a/apps/background/resource/vm/instance_type.py +++ b/apps/background/resource/vm/instance_type.py @@ -13,11 +13,12 @@ class InstanceTypeObject(ResourceBaseObject): def __init__(self): self.resource = InstanceTypeManager() - def list(self, filters=None, page=None, pagesize=None, orderby=None): + def list(self, filters=None, page=None, pagesize=None, orderby=None, filter_string=None): filters = filters or {} filters["is_deleted"] = 0 count, results = self.resource.list(filters=filters, pageAt=page, + filter_string=filter_string, pageSize=pagesize, orderby=orderby) data = [] for res in results: @@ -71,6 +72,7 @@ def convert_resource_id(self, provider_id, name): return name, {"cpu": 0, "memory": 0} def convert_asset(self, provider, asset_name): + asset_name = str(asset_name) data = self.resource.get(filters={"provider": provider, "origin_name": asset_name}) if data: