From 05759df3be5f53e8c5f86d84513685171408acfe Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 20 Sep 2023 23:38:31 +0200 Subject: [PATCH] Refine API wrapper for "Plugins" --- CHANGELOG.md | 2 ++ grafana_client/elements/plugin.py | 44 ++++++++++++++++++------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca830a2..17eb42b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +* Refine API wrapper for "Plugins" + ## 3.8.0 (2023-09-15) diff --git a/grafana_client/elements/plugin.py b/grafana_client/elements/plugin.py index 2ee0911..404851e 100644 --- a/grafana_client/elements/plugin.py +++ b/grafana_client/elements/plugin.py @@ -9,14 +9,6 @@ def __init__(self, client): self.client = client self.logger = logging.getLogger(__name__) - def health_check_plugin(self, pluginId): - """ - :return: - """ - path = "/plugins/%s/health" % pluginId - r = self.client.GET(path) - return r - def get_installed_plugins(self): """ :return: @@ -25,7 +17,7 @@ def get_installed_plugins(self): r = self.client.GET(path) return r - def install_plugin(self, pluginId, version): + def install_plugin(self, pluginId, version, errors="raise"): """ : return: """ @@ -34,10 +26,15 @@ def install_plugin(self, pluginId, version): r = self.client.POST(path, json={"version": version}) return r except Exception as ex: - self.logger.info("Skipped installing %s and err = %s", pluginId, ex) + if errors == "raise": + raise + elif errors == "ignore": + self.logger.info(f"Skipped installing plugin {pluginId}: {ex}") + else: + raise ValueError(f"error={errors} is invalid") return None - def uninstall_plugin(self, pluginId): + def uninstall_plugin(self, pluginId, errors="raise"): """ : return: """ @@ -46,17 +43,26 @@ def uninstall_plugin(self, pluginId): r = self.client.POST(path) return r except Exception as ex: - self.logger.info("Skipped uninstalling %s and error = %s", pluginId, ex) + if errors == "raise": + raise + elif errors == "ignore": + self.logger.info(f"Skipped uninstalling plugin {pluginId}: {ex}") + else: + raise ValueError(f"error={errors} is invalid") return None + def health_check_plugin(self, pluginId): + """ + :return: + """ + path = "/plugins/%s/health" % pluginId + r = self.client.GET(path) + return r + def get_plugin_metrics(self, pluginId): """ : return: """ - try: - path = "/plugins/%s/metrics" % pluginId - r = self.client.GET(path) - return r - except Exception as ex: - self.logger.info("Got error in fetching metrics for plugin %s and error = %s", pluginId, ex) - return None + path = "/plugins/%s/metrics" % pluginId + r = self.client.GET(path) + return r