Add datasource to template schema.
the following patch will allow us to use datasource type in template schema. Change-Id: I15cce5f8f97d1837b94eaa7067d7ebe8e449f8f4 Signed-off-by: Eldad Marciano <emarcian@redhat.com>
This commit is contained in:
parent
e86eb350b3
commit
2da2da1a9a
@ -16,6 +16,7 @@ import voluptuous as v
|
||||
|
||||
from grafana_dashboards.schema.template.base import Base
|
||||
from grafana_dashboards.schema.template.custom import Custom
|
||||
from grafana_dashboards.schema.template.datasource import Datasource
|
||||
from grafana_dashboards.schema.template.interval import Interval
|
||||
from grafana_dashboards.schema.template.query import Query
|
||||
|
||||
@ -48,6 +49,8 @@ class Template(object):
|
||||
schema = Interval().get_schema()
|
||||
if template['type'] == 'custom':
|
||||
schema = Custom().get_schema()
|
||||
if template['type'] == 'datasource':
|
||||
schema = Datasource().get_schema()
|
||||
|
||||
res['list'].append(schema(template))
|
||||
|
||||
|
@ -65,7 +65,8 @@ class Base(object):
|
||||
def __init__(self):
|
||||
self.base = {
|
||||
v.Required('name'): v.All(str, v.Length(min=1)),
|
||||
v.Required('type'): v.Any('query', 'interval', 'custom'),
|
||||
v.Required('type'): v.Any('query', 'interval', 'custom',
|
||||
'datasource'),
|
||||
}
|
||||
|
||||
def get_schema(self):
|
||||
|
34
grafana_dashboards/schema/template/datasource.py
Normal file
34
grafana_dashboards/schema/template/datasource.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright 2018 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import voluptuous as v
|
||||
|
||||
from grafana_dashboards.schema.template.base import Base
|
||||
|
||||
|
||||
class Datasource(Base):
|
||||
|
||||
current = {
|
||||
v.Required('text'): v.All(str, v.Length(min=1)),
|
||||
v.Required('value'): v.All(str, v.Length(min=1)),
|
||||
}
|
||||
|
||||
def get_schema(self):
|
||||
query = {
|
||||
v.Required('query', default=''): v.All(str),
|
||||
v.Required('current'): v.Any(self.current),
|
||||
v.Optional('hide'): v.All(int, v.Range(min=0, max=2)),
|
||||
}
|
||||
query.update(self.base)
|
||||
return v.Schema(query)
|
23
tests/schema/fixtures/dashboard-0028.json
Normal file
23
tests/schema/fixtures/dashboard-0028.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"dashboard": {
|
||||
"new-dashboard": {
|
||||
"rows": [],
|
||||
"templating": {
|
||||
"enabled": true,
|
||||
"list": [
|
||||
{
|
||||
"current": {
|
||||
"text": "prometheus",
|
||||
"value": "prometheus"
|
||||
},
|
||||
"name": "foobar",
|
||||
"query": "prometheus",
|
||||
"type": "datasource"
|
||||
}
|
||||
]
|
||||
},
|
||||
"timezone": "utc",
|
||||
"title": "New dashboard"
|
||||
}
|
||||
}
|
||||
}
|
9
tests/schema/fixtures/dashboard-0028.yaml
Normal file
9
tests/schema/fixtures/dashboard-0028.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
dashboard:
|
||||
templating:
|
||||
- name: foobar
|
||||
query: prometheus
|
||||
type: datasource
|
||||
current:
|
||||
value: prometheus
|
||||
text: prometheus
|
||||
title: New dashboard
|
Loading…
x
Reference in New Issue
Block a user