summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuique Llorente <ellorent@redhat.com>2018-07-10 15:56:29 +0200
committerQuique Llorente <ellorent@redhat.com>2018-07-10 16:19:58 +0200
commite36f4ef99e38e2e62dd3e2994a89b19c5d0d5f60 (patch)
tree89ff2c32976ff1fcfafcc7db8e50bf83ef2d4fb9
parent0969e906f3f8190d50a3d8b3ebc10f19ef65c34e (diff)
Add adhoc template variables
Notes
Notes (review): Code-Review+2: Paul Belanger <pabelanger@redhat.com> Workflow+1: Paul Belanger <pabelanger@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 10 Jul 2018 17:04:20 +0000 Reviewed-on: https://review.openstack.org/581368 Project: openstack-infra/grafyaml Branch: refs/heads/master
-rw-r--r--grafana_dashboards/schema/template/__init__.py3
-rw-r--r--grafana_dashboards/schema/template/adhoc.py29
-rw-r--r--grafana_dashboards/schema/template/base.py2
-rw-r--r--tests/schema/fixtures/dashboard-0032.json21
-rw-r--r--tests/schema/fixtures/dashboard-0032.yaml8
5 files changed, 62 insertions, 1 deletions
diff --git a/grafana_dashboards/schema/template/__init__.py b/grafana_dashboards/schema/template/__init__.py
index acc2bd8..a2858bf 100644
--- a/grafana_dashboards/schema/template/__init__.py
+++ b/grafana_dashboards/schema/template/__init__.py
@@ -14,6 +14,7 @@
14 14
15import voluptuous as v 15import voluptuous as v
16 16
17from grafana_dashboards.schema.template.adhoc import Adhoc
17from grafana_dashboards.schema.template.base import Base 18from grafana_dashboards.schema.template.base import Base
18from grafana_dashboards.schema.template.custom import Custom 19from grafana_dashboards.schema.template.custom import Custom
19from grafana_dashboards.schema.template.datasource import Datasource 20from grafana_dashboards.schema.template.datasource import Datasource
@@ -51,6 +52,8 @@ class Template(object):
51 schema = Custom().get_schema() 52 schema = Custom().get_schema()
52 if template['type'] == 'datasource': 53 if template['type'] == 'datasource':
53 schema = Datasource().get_schema() 54 schema = Datasource().get_schema()
55 if template['type'] == 'adhoc':
56 schema = Adhoc().get_schema()
54 57
55 res['list'].append(schema(template)) 58 res['list'].append(schema(template))
56 59
diff --git a/grafana_dashboards/schema/template/adhoc.py b/grafana_dashboards/schema/template/adhoc.py
new file mode 100644
index 0000000..e78255f
--- /dev/null
+++ b/grafana_dashboards/schema/template/adhoc.py
@@ -0,0 +1,29 @@
1# Copyright 2018 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import voluptuous as v
16
17from grafana_dashboards.schema.template.base import Base
18
19
20class Adhoc(Base):
21
22 def get_schema(self):
23 query = {
24 v.Required('datasource'): v.All(str),
25 v.Optional('hide'): v.All(int, v.Range(min=0, max=2)),
26 v.Optional('label', default=''): v.All(str),
27 }
28 query.update(self.base)
29 return v.Schema(query)
diff --git a/grafana_dashboards/schema/template/base.py b/grafana_dashboards/schema/template/base.py
index 620caa5..007b702 100644
--- a/grafana_dashboards/schema/template/base.py
+++ b/grafana_dashboards/schema/template/base.py
@@ -66,7 +66,7 @@ class Base(object):
66 self.base = { 66 self.base = {
67 v.Required('name'): v.All(str, v.Length(min=1)), 67 v.Required('name'): v.All(str, v.Length(min=1)),
68 v.Required('type'): v.Any('query', 'interval', 'custom', 68 v.Required('type'): v.Any('query', 'interval', 'custom',
69 'datasource'), 69 'datasource', 'adhoc'),
70 } 70 }
71 71
72 def get_schema(self): 72 def get_schema(self):
diff --git a/tests/schema/fixtures/dashboard-0032.json b/tests/schema/fixtures/dashboard-0032.json
new file mode 100644
index 0000000..e80b2dc
--- /dev/null
+++ b/tests/schema/fixtures/dashboard-0032.json
@@ -0,0 +1,21 @@
1{
2 "dashboard": {
3 "new-dashboard": {
4 "rows": [],
5 "templating": {
6 "enabled": true,
7 "list": [
8 {
9 "datasource": "telegraf",
10 "hide": 0,
11 "label": "Influxdb filter",
12 "name": "foobar",
13 "type": "adhoc"
14 }
15 ]
16 },
17 "timezone": "utc",
18 "title": "New dashboard"
19 }
20 }
21}
diff --git a/tests/schema/fixtures/dashboard-0032.yaml b/tests/schema/fixtures/dashboard-0032.yaml
new file mode 100644
index 0000000..0c62ced
--- /dev/null
+++ b/tests/schema/fixtures/dashboard-0032.yaml
@@ -0,0 +1,8 @@
1dashboard:
2 templating:
3 - name: foobar
4 datasource: telegraf
5 hide: 0
6 label: "Influxdb filter"
7 type: adhoc
8 title: New dashboard