-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use shared function for verison check #327
base: main
Are you sure you want to change the base?
Conversation
plugins/module_utils/base.py
Outdated
@@ -52,3 +60,27 @@ def grafana_required_together(): | |||
|
|||
def grafana_mutually_exclusive(): | |||
return [['url_username', 'grafana_api_key']] | |||
|
|||
|
|||
def check_required_version(self, minimum_version): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice change proposal :)
I would rather create a BaseInterface class with this method and make all the interface classes inherit from it.
I guess that will be the same code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean something like this?
class BaseInterface:
def check_required_version(self, minimum_version):
if not self._module.params.get("skip_version_check"):
try:
response, info = fetch_url(
self._module,
"%s/api/health" % (self.grafana_url),
headers=self.headers,
method="GET",
)
content = json.loads(response.read())
version = content.get("version")
major_version = int(version.split(".")[0])
except GrafanaError as e:
self._module.fail_json(failed=True, msg=to_text(e))
if major_version < int(minimum_version):
self._module.fail_json(
failed=True,
msg="Need at least Grafana version %s to use this feature."
% minimum_version,
)
And then this?
class Interface1(BaseInterface):
def __init__(self):
super().__init__()
def some_method(self):
self.check_required_version(minimum_version)
If yes, I don't understand the point of this. Or do you mean something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I meant indeed.
You are using a function that requires providing self
at every call, self
being potentially any Grafana interface we have in the Collection that would require checking for a version.
So if you create a base class with this function and make all interface inherit from it, you are achieving the same thing with a more appropriate coding implementation (inheritance) and avoid passing self
to a function which is what a class method does anyway.
7d2da6e
to
bfa480a
Compare
SUMMARY
ISSUE TYPE
COMPONENT NAME
grafana_folder
grafana_team