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: 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<rid>[\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<rid>[\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<rid>[\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<rid>[\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 @@ </interface> </plugin> <plugin name="network_interface_attach"> - <interface action="apply" path="/terraform/v1/vm/backend/network_interface/attach" httpMethod='POST'> + <interface action="apply" path="/terraform/v1/vm/backend/network_interface/apply" httpMethod='POST'> <inputParameters> <parameter datatype="string" mappingType="entity" required="N">id</parameter> <parameter datatype="string" mappingType="entity" required="Y">name</parameter> @@ -1109,7 +1109,7 @@ <parameter datatype="string">resource_id</parameter> </outputParameters> </interface> - <interface action="destroy" path="/terraform/v1/vm/backend/network_interface/detach" httpMethod='POST'> + <interface action="destroy" path="/terraform/v1/vm/backend/network_interface/destroy" httpMethod='POST'> <inputParameters> <parameter datatype="string" mappingType="entity" required="Y">id</parameter> </inputParameters> @@ -1217,7 +1217,7 @@ <parameter datatype="string">errorCode</parameter> </outputParameters> </interface> - <interface action="attach_server" path="/terraform/v1/loadbalance/backend/lb/attach" httpMethod='POST'> + <interface action="attach_server" path="/terraform/v1/loadbalance/backend/lb/apply" httpMethod='POST'> <inputParameters> <parameter datatype="string" mappingType="entity" required="N">id</parameter> <parameter datatype="string" mappingType="entity" required="N">name</parameter> @@ -1240,7 +1240,7 @@ <parameter datatype="string">resource_id</parameter> </outputParameters> </interface> - <interface action="dettach_all" path="/terraform/v1/loadbalance/backend/lb/detach" httpMethod='POST'> + <interface action="dettach_all" path="/terraform/v1/loadbalance/backend/lb/destroy" httpMethod='POST'> <inputParameters> <parameter datatype="string" mappingType="entity" required="Y">id</parameter> </inputParameters> @@ -1250,7 +1250,7 @@ <parameter datatype="string">errorCode</parameter> </outputParameters> </interface> - <interface action="dettach_instance" path="/terraform/v1/loadbalance/backend/lb/detach/instance" httpMethod='POST'> + <interface action="dettach_instance" path="/terraform/v1/loadbalance/backend/lb/destroy/instance" httpMethod='POST'> <inputParameters> <parameter datatype="string" mappingType="entity" required="Y">id</parameter> <parameter datatype="string" mappingType="entity" required="Y">instance_id</parameter>