Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
brian
brian-dashboard-manager
Commits
551b809a
Commit
551b809a
authored
3 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Add public delete dashboard method
parent
acc19a9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brian_dashboard_manager/grafana/dashboard.py
+28
-5
28 additions, 5 deletions
brian_dashboard_manager/grafana/dashboard.py
with
28 additions
and
5 deletions
brian_dashboard_manager/grafana/dashboard.py
+
28
−
5
View file @
551b809a
...
...
@@ -24,16 +24,40 @@ def get_dashboard_definitions(dir=None): # pragma: no cover
yield
dashboard
def
delete_dashboard
(
request
:
TokenRequest
,
dashboard
,
folder_id
=
None
):
try
:
r
=
None
uid
=
dashboard
.
get
(
'
uid
'
)
if
uid
:
return
_delete_dashboard
(
request
,
uid
)
elif
dashboard
.
get
(
'
title
'
)
and
folder_id
:
dash
=
_search_dashboard
(
request
,
dashboard
,
folder_id
)
if
dash
is
None
:
return
True
r
=
request
.
delete
(
f
'
api/dashboards/uid/
{
dash
.
get
(
"
uid
"
)
}
'
)
logger
.
info
(
f
'
Deleted dashboard:
{
dashboard
.
get
(
"
title
"
)
}
'
)
return
r
is
not
None
except
HTTPError
:
dump
=
json
.
dumps
(
dashboard
,
indent
=
2
)
logger
.
exception
(
f
'
Error when deleting dashboard:
\n
{
dump
}
'
)
return
None
# Deletes a single dashboard for the organization
# the API token is registered to.
def
_delete_dashboard
(
request
:
TokenRequest
,
uid
:
int
):
try
:
r
=
request
.
delete
(
f
'
api/dashboards/uid/
{
uid
}
'
)
if
r
and
'
deleted
'
in
r
.
get
(
'
message
'
,
''
):
return
r
except
HTTPError
:
return
True
except
HTTPError
as
e
:
if
e
.
response
is
not
None
and
e
.
response
.
status_code
==
404
:
return
True
logger
.
exception
(
f
'
Error when deleting dashboard with UID #
{
uid
}
'
)
return
Non
e
return
Fals
e
# Deletes all dashboards for the organization
...
...
@@ -55,10 +79,9 @@ def find_dashboard(request: TokenRequest, title):
return
r
[
0
]
return
None
# Searches Grafana for a dashboard
# matching the title of the provided dashboard.
def
_search_dashboard
(
request
:
TokenRequest
,
dashboard
:
Dict
,
folder_id
=
None
):
try
:
r
=
request
.
get
(
'
api/search
'
,
params
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment