From 2ffded73e99197bb172c915b36fb312e9dfd1712 Mon Sep 17 00:00:00 2001 From: Quique Llorente Date: Wed, 11 Jul 2018 08:52:14 +0200 Subject: [PATCH] Add panel type 'row' Change-Id: I47ea73eab779fa311d22a930acdc33ac2a9230f8 --- grafana_dashboards/schema/panel/__init__.py | 3 ++ grafana_dashboards/schema/panel/base.py | 2 +- grafana_dashboards/schema/panel/row.py | 28 ++++++++++++++++ tests/schema/fixtures/dashboard-0033.json | 36 +++++++++++++++++++++ tests/schema/fixtures/dashboard-0033.yaml | 12 +++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 grafana_dashboards/schema/panel/row.py create mode 100644 tests/schema/fixtures/dashboard-0033.json create mode 100644 tests/schema/fixtures/dashboard-0033.yaml diff --git a/grafana_dashboards/schema/panel/__init__.py b/grafana_dashboards/schema/panel/__init__.py index ab103eb..d9dab40 100644 --- a/grafana_dashboards/schema/panel/__init__.py +++ b/grafana_dashboards/schema/panel/__init__.py @@ -17,6 +17,7 @@ import voluptuous as v from grafana_dashboards.schema.panel.base import Base from grafana_dashboards.schema.panel.dashlist import Dashlist from grafana_dashboards.schema.panel.graph import Graph +from grafana_dashboards.schema.panel.row import Row from grafana_dashboards.schema.panel.singlestat import Singlestat from grafana_dashboards.schema.panel.text import Text @@ -42,6 +43,8 @@ class Panel(object): schema = Singlestat().get_schema() elif panel['type'] == 'text': schema = Text().get_schema() + elif panel['type'] == 'row': + schema = Row().get_schema() res.append(schema(panel)) diff --git a/grafana_dashboards/schema/panel/base.py b/grafana_dashboards/schema/panel/base.py index 79a0483..cfb6c26 100644 --- a/grafana_dashboards/schema/panel/base.py +++ b/grafana_dashboards/schema/panel/base.py @@ -41,7 +41,7 @@ class Base(object): v.Required('span', default=12): v.All(int, v.Range(min=0, max=12)), v.Required('title'): v.All(str, v.Length(min=1)), v.Required('type'): v.Any( - 'dashlist', 'graph', 'singlestat', 'text'), + 'dashlist', 'graph', 'singlestat', 'text', 'row'), v.Optional('id'): int, v.Optional('format'): v.Any(self.formats, v.Length(min=1)), v.Optional('transparent'): v.All(bool), diff --git a/grafana_dashboards/schema/panel/row.py b/grafana_dashboards/schema/panel/row.py new file mode 100644 index 0000000..b48ac56 --- /dev/null +++ b/grafana_dashboards/schema/panel/row.py @@ -0,0 +1,28 @@ +# 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.panel.base import Base + + +class Row(Base): + + def get_schema(self): + row = { + v.Required('collapsed'): v.All(bool), + v.Optional('panels', default=[]): v.All([str]) + } + row.update(self.base) + return v.Schema(row) diff --git a/tests/schema/fixtures/dashboard-0033.json b/tests/schema/fixtures/dashboard-0033.json new file mode 100644 index 0000000..d061ed1 --- /dev/null +++ b/tests/schema/fixtures/dashboard-0033.json @@ -0,0 +1,36 @@ +{ + "dashboard": { + "new-dashboard": { + "rows": [ + { + "collapse": false, + "editable": true, + "height": "250px", + "panels": [ + { + "collapsed": false, + "editable": true, + "error": false, + "panels": [], + "span": 12, + "title": "Main", + "type": "row" + } + ], + "showTitle": false, + "title": "New row" + } + ], + "templating": { + "enabled": false, + "list": [] + }, + "time": { + "from": "2018-02-07T08:42:27.000Z", + "to": "2018-02-07T13:48:32.000Z" + }, + "timezone": "utc", + "title": "New dashboard" + } + } +} diff --git a/tests/schema/fixtures/dashboard-0033.yaml b/tests/schema/fixtures/dashboard-0033.yaml new file mode 100644 index 0000000..efc4f5d --- /dev/null +++ b/tests/schema/fixtures/dashboard-0033.yaml @@ -0,0 +1,12 @@ +dashboard: + time: + from: "2018-02-07T08:42:27.000Z" + to: "2018-02-07T13:48:32.000Z" + title: New dashboard + rows: + - title: New row + height: 250px + panels: + - collapsed: false + title: Main + type: row