Solve the problem when adding template

Fix the bug that when user adding a template in dashboard, it always toasts "Unable to validate the Vitrage Templates service.".

Change-Id: Ifc4974150308c8b648c26f62129fac08d16e19e1
This commit is contained in:
Ziyu Bai 2019-12-13 17:15:28 +08:00
parent c9fb559b57
commit d19f5008e4

View File

@ -14,7 +14,6 @@
import json import json
import logging import logging
import tempfile
from horizon.utils.memoized import memoized from horizon.utils.memoized import memoized
from keystoneauth1.identity.generic.token import Token from keystoneauth1.identity.generic.token import Token
@ -132,11 +131,11 @@ def template_add(request):
template = json.loads(request.body) template = json.loads(request.body)
type = template.get('type') type = template.get('type')
params = template.get('params') params = template.get('params')
with tempfile.NamedTemporaryFile(suffix='.yaml') as temp: template_str = template.get('template')
temp.write(template.get('template')) response = vitrageclient(request).template \
temp.flush() .add(template_type=type,
temp.seek(0) params=params,
response = vitrageclient(request).template.add(temp.name, type, params) template_str=template_str)
return response return response
@ -144,11 +143,9 @@ def template_validate(request):
template = json.loads(request.body) template = json.loads(request.body)
type = template.get('type') type = template.get('type')
params = template.get('params') params = template.get('params')
with tempfile.NamedTemporaryFile(suffix='.yaml') as temp: template_str = template.get('template')
temp.write(template.get('template')) response = vitrageclient(request).template \
temp.flush() .validate(template_type=type,
temp.seek(0) params=params,
response = vitrageclient(request).template.validate(temp.name, template_str=template_str)
type,
params)
return response return response