Skip to content
Snippets Groups Projects
Commit a33e4bdc authored by Release Webservice's avatar Release Webservice
Browse files

Finished release 0.19.

parents f3075fcc cdd1ec22
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,18 @@ def delete_dashboards(request: TokenRequest): ...@@ -73,6 +73,18 @@ def delete_dashboards(request: TokenRequest):
return True return True
# lists all dashboards, optionally within a folder
def list_dashboards(request: TokenRequest, folder_id=None):
params = {
'query': ''
}
if folder_id is not None:
params['folderIds'] = folder_id
r = request.get('api/search', params=params)
return r
# Searches for a dashboard with given title # Searches for a dashboard with given title
def find_dashboard(request: TokenRequest, title=None): def find_dashboard(request: TokenRequest, title=None):
param = { param = {
...@@ -102,16 +114,17 @@ def find_dashboard(request: TokenRequest, title=None): ...@@ -102,16 +114,17 @@ def find_dashboard(request: TokenRequest, title=None):
# matching the title of the provided dashboard. # matching the title of the provided dashboard.
def _search_dashboard(request: TokenRequest, dashboard: Dict, folder_id=None): def _search_dashboard(request: TokenRequest, dashboard: Dict, folder_id=None):
try: try:
r = request.get('api/search', params={ params = {
'query': dashboard["title"] 'query': dashboard["title"]
}) }
if folder_id is not None:
params['folderIds'] = folder_id
r = request.get('api/search', params=params)
if r and isinstance(r, list): if r and isinstance(r, list):
if len(r) >= 1: if len(r) >= 1:
for dash in r: for dash in r:
if folder_id: if dash['title'].lower() == dashboard['title'].lower():
if folder_id != dash.get('folderId'):
continue
if dash['title'] == dashboard['title']:
definition = _get_dashboard(request, dash['uid']) definition = _get_dashboard(request, dash['uid'])
return definition return definition
return None return None
......
...@@ -18,7 +18,8 @@ from brian_dashboard_manager.grafana.organization import \ ...@@ -18,7 +18,8 @@ from brian_dashboard_manager.grafana.organization import \
get_organizations, create_organization, create_api_token, \ get_organizations, create_organization, create_api_token, \
delete_api_token, delete_expired_api_tokens, set_home_dashboard delete_api_token, delete_expired_api_tokens, set_home_dashboard
from brian_dashboard_manager.grafana.dashboard import find_dashboard, \ from brian_dashboard_manager.grafana.dashboard import find_dashboard, \
get_dashboard_definitions, create_dashboard, delete_dashboard get_dashboard_definitions, create_dashboard, delete_dashboard, \
list_dashboards
from brian_dashboard_manager.grafana.datasource import \ from brian_dashboard_manager.grafana.datasource import \
check_provisioned, create_datasource check_provisioned, create_datasource
from brian_dashboard_manager.grafana.folder import find_folder, \ from brian_dashboard_manager.grafana.folder import find_folder, \
...@@ -45,10 +46,21 @@ def provision_folder(token_request, folder_name, dash, ...@@ -45,10 +46,21 @@ def provision_folder(token_request, folder_name, dash,
Function to provision dashboards within a folder. Function to provision dashboards within a folder.
""" """
def _check_valid(interface):
return interface['dashboard_info']['name'] != ''
folder = find_folder(token_request, folder_name) folder = find_folder(token_request, folder_name)
tag = dash['tag'] tag = dash['tag']
interfaces = dash['interfaces'] interfaces = dash['interfaces']
empty_names = [iface for iface in interfaces if not _check_valid(iface)]
if any(empty_names):
for iface in empty_names:
logger.info('Invalid dashboard name on interface:')
logger.info(json.dumps(iface, indent=2))
interfaces = list(filter(_check_valid, interfaces))
# dashboard should include error panels # dashboard should include error panels
errors = dash.get('errors', False) errors = dash.get('errors', False)
...@@ -122,6 +134,7 @@ def provision(config): ...@@ -122,6 +134,7 @@ def provision(config):
all_orgs = get_organizations(request) all_orgs = get_organizations(request)
orgs_to_provision = config.get('organizations', DEFAULT_ORGANIZATIONS) orgs_to_provision = config.get('organizations', DEFAULT_ORGANIZATIONS)
ignored_folders = config.get('ignored_folders', [])
missing = (org['name'] for org in orgs_to_provision missing = (org['name'] for org in orgs_to_provision
if org['name'] not in [org['name'] for org in all_orgs]) if org['name'] not in [org['name'] for org in all_orgs])
...@@ -444,6 +457,16 @@ def provision(config): ...@@ -444,6 +457,16 @@ def provision(config):
# just hardcode that we updated home dashboard # just hardcode that we updated home dashboard
updated['home'] = True updated['home'] = True
# get dashboard UIDs from ignored folders
# and make sure we don't touch them
for name in ignored_folders:
folder = find_folder(request, name)
to_ignore = list_dashboards(request, folder['id'])
for dash in to_ignore:
# mark it updated, so we don't modify it.
updated[dash['uid']] = True
for dash, provisioned in updated.items(): for dash, provisioned in updated.items():
if not provisioned: if not provisioned:
logger.info(f'Deleting stale dashboard with UID {dash}') logger.info(f'Deleting stale dashboard with UID {dash}')
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [0.19] - 2021-09-13
- [POL1-501] create config option ignored_folders for provisioning folders with manually maintained dashboards
## [0.18] - 2021-08-23 ## [0.18] - 2021-08-23
- Only provision GWS folders for GEANT Staff organization temporarily - Only provision GWS folders for GEANT Staff organization temporarily
......
...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages ...@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='brian-dashboard-manager', name='brian-dashboard-manager',
version="0.18", version="0.19",
author='GEANT', author='GEANT',
author_email='swd@geant.org', author_email='swd@geant.org',
description='', description='',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment