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

Finished release 0.21.

parents 40c05c0d 439cdab1
No related branches found
No related tags found
No related merge requests found
...@@ -73,26 +73,17 @@ def delete_dashboards(request: TokenRequest): ...@@ -73,26 +73,17 @@ 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, folder_id=None):
param = { param = {
**({'query': title} if title else {}), **({'query': title} if title else {}),
'type': 'dash-db', 'type': 'dash-db',
'limit': 5000, 'limit': 5000,
'page': 1 'page': 1
} }
if folder_id is not None:
param['folderIds'] = folder_id
r = request.get('api/search', params=param) r = request.get('api/search', params=param)
if r and len(r) > 0: if r and len(r) > 0:
if title: if title:
......
...@@ -6,7 +6,7 @@ from brian_dashboard_manager.grafana.utils.request import TokenRequest ...@@ -6,7 +6,7 @@ from brian_dashboard_manager.grafana.utils.request import TokenRequest
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def delete_folder(request: TokenRequest, title, uid=None): def delete_folder(request: TokenRequest, title=None, uid=None):
if uid: if uid:
r = request.delete(f'api/folders/{uid}') r = request.delete(f'api/folders/{uid}')
return r is not None return r is not None
......
...@@ -18,12 +18,11 @@ from brian_dashboard_manager.grafana.organization import \ ...@@ -18,12 +18,11 @@ 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, \
delete_folder delete_folder, get_folders
from brian_dashboard_manager.inventory_provider.interfaces import \ from brian_dashboard_manager.inventory_provider.interfaces import \
get_gws_direct, get_gws_indirect, get_interfaces get_gws_direct, get_gws_indirect, get_interfaces
...@@ -309,6 +308,11 @@ def provision(config): ...@@ -309,6 +308,11 @@ def provision(config):
updated = find_dashboard(token_request) or [] updated = find_dashboard(token_request) or []
updated = reduce(get_uid, updated, {}) updated = reduce(get_uid, updated, {})
# General is a base folder present in Grafana
folders_to_keep = ['General', 'Aggregates']
folders_to_keep.extend([dash['folder_name']
for dash in dashboards.values()])
def update_dash_list(dashboards): def update_dash_list(dashboards):
for dashboard in dashboards: for dashboard in dashboards:
if isinstance(dashboard, Future): if isinstance(dashboard, Future):
...@@ -452,12 +456,16 @@ def provision(config): ...@@ -452,12 +456,16 @@ def provision(config):
# get dashboard UIDs from ignored folders # get dashboard UIDs from ignored folders
# and make sure we don't touch them # and make sure we don't touch them
for name in ignored_folders: for name in ignored_folders:
folders_to_keep.append(name)
logger.info( logger.info(
f'Ignoring dashboards under the folder {org["name"]}/{name}') f'Ignoring dashboards under the folder {org["name"]}/{name}')
folder = find_folder(token_request, name, create=False) folder = find_folder(token_request, name, create=False)
if folder is None: if folder is None:
continue continue
to_ignore = list_dashboards(token_request, folder['id']) to_ignore = find_dashboard(token_request, folder_id=folder['id'])
if to_ignore is None:
continue
for dash in to_ignore: for dash in to_ignore:
# mark it updated, so we don't modify it. # mark it updated, so we don't modify it.
...@@ -468,6 +476,13 @@ def provision(config): ...@@ -468,6 +476,13 @@ def provision(config):
logger.info(f'Deleting stale dashboard with UID {dash}') logger.info(f'Deleting stale dashboard with UID {dash}')
delete_dashboard(token_request, {'uid': dash}) delete_dashboard(token_request, {'uid': dash})
all_folders = get_folders(token_request)
folders_to_keep = set(folders_to_keep)
for folder in all_folders:
if folder['title'] not in folders_to_keep:
delete_folder(token_request, uid=folder['uid'])
logger.info(f'Time to complete: {time.time() - start}') logger.info(f'Time to complete: {time.time() - start}')
for org_id, token in tokens: for org_id, token in tokens:
delete_api_token(request, org_id, token) delete_api_token(request, org_id, token)
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
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.21] - 2021-09-14
- Delete left-over and unmanaged folders
## [0.20] - 2021-09-13 ## [0.20] - 2021-09-13
- Don't automatically create ignored folders, just ignore them if they are present. - Don't automatically create ignored folders, just ignore them if they are present
## [0.19] - 2021-09-13 ## [0.19] - 2021-09-13
- [POL1-501] create config option ignored_folders for provisioning folders with manually maintained dashboards - [POL1-501] create config option ignored_folders for provisioning folders with manually maintained dashboards
......
...@@ -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.20", version="0.21",
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