Skip to content

Commit 05759df

Browse files
committed
Refine API wrapper for "Plugins"
1 parent 434a98c commit 05759df

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased
44

5+
* Refine API wrapper for "Plugins"
6+
57

68
## 3.8.0 (2023-09-15)
79

grafana_client/elements/plugin.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ def __init__(self, client):
99
self.client = client
1010
self.logger = logging.getLogger(__name__)
1111

12-
def health_check_plugin(self, pluginId):
13-
"""
14-
:return:
15-
"""
16-
path = "/plugins/%s/health" % pluginId
17-
r = self.client.GET(path)
18-
return r
19-
2012
def get_installed_plugins(self):
2113
"""
2214
:return:
@@ -25,7 +17,7 @@ def get_installed_plugins(self):
2517
r = self.client.GET(path)
2618
return r
2719

28-
def install_plugin(self, pluginId, version):
20+
def install_plugin(self, pluginId, version, errors="raise"):
2921
"""
3022
: return:
3123
"""
@@ -34,10 +26,15 @@ def install_plugin(self, pluginId, version):
3426
r = self.client.POST(path, json={"version": version})
3527
return r
3628
except Exception as ex:
37-
self.logger.info("Skipped installing %s and err = %s", pluginId, ex)
29+
if errors == "raise":
30+
raise
31+
elif errors == "ignore":
32+
self.logger.info(f"Skipped installing plugin {pluginId}: {ex}")
33+
else:
34+
raise ValueError(f"error={errors} is invalid")
3835
return None
3936

40-
def uninstall_plugin(self, pluginId):
37+
def uninstall_plugin(self, pluginId, errors="raise"):
4138
"""
4239
: return:
4340
"""
@@ -46,17 +43,26 @@ def uninstall_plugin(self, pluginId):
4643
r = self.client.POST(path)
4744
return r
4845
except Exception as ex:
49-
self.logger.info("Skipped uninstalling %s and error = %s", pluginId, ex)
46+
if errors == "raise":
47+
raise
48+
elif errors == "ignore":
49+
self.logger.info(f"Skipped uninstalling plugin {pluginId}: {ex}")
50+
else:
51+
raise ValueError(f"error={errors} is invalid")
5052
return None
5153

54+
def health_check_plugin(self, pluginId):
55+
"""
56+
:return:
57+
"""
58+
path = "/plugins/%s/health" % pluginId
59+
r = self.client.GET(path)
60+
return r
61+
5262
def get_plugin_metrics(self, pluginId):
5363
"""
5464
: return:
5565
"""
56-
try:
57-
path = "/plugins/%s/metrics" % pluginId
58-
r = self.client.GET(path)
59-
return r
60-
except Exception as ex:
61-
self.logger.info("Got error in fetching metrics for plugin %s and error = %s", pluginId, ex)
62-
return None
66+
path = "/plugins/%s/metrics" % pluginId
67+
r = self.client.GET(path)
68+
return r

0 commit comments

Comments
 (0)