Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:WeBankPartners/wecube-plugins-terraf…
Browse files Browse the repository at this point in the history
…orm into dev
  • Loading branch information
pobu168 committed May 6, 2021
2 parents c5265a9 + 5d42e39 commit cb36330
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 16 deletions.
15 changes: 13 additions & 2 deletions apps/api/apibase_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion apps/api/conductor/valueReverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion apps/background/resource/vm/instance_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions apps/controller/configer/config_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions apps/controller/configer/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,15 @@
},
"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',
'region', 'extend_info'],
"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"],
Expand Down
2 changes: 1 addition & 1 deletion apps/controller/database/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 2 additions & 2 deletions apps/controller/storage/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
11 changes: 11 additions & 0 deletions apps/controller/vm/instance_type_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions apps/controller/vm/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),

]
10 changes: 5 additions & 5 deletions register.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit cb36330

Please sign in to comment.