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