Closed aitorpazos closed 3 years ago
@aitorpazos thanks for the PR! (btw fyi I'm going to release 1.1.0 within several days which will contain your module, thanks)
And also as we can see the modules share the same function. We could move it (and other shared things if exist), to plugins/module_utils/something.py
, document it there, and use everything instead of having the code duplicated.
rabbitmqctl_exec (obj, args, force_exec_in_check_mode=False)
where obj
is an argument via which the objects will pass themselves.the class could look like:
class RabbitMQ():
"""Doc explaining purpose, args, etc."""
def __init__(self, obj):
self. obj = obj
def exec(self, args, force_exec_in_check_mode=False):
"""Doc explaining purpose, args, etc."""
if not self.obj.module.check_mode or (self.obj.module.check_mode and force_exec_in_check_mode):
cmd = [self.obj._rabbitmqctl, '-q', '-n', self.obj.node]
rc, out, err = self.obj.module.run_command(cmd + args, check_rc=True)
return out.splitlines()
return list()
in the target classes you're changing here in __init__
we could initialize `self.rabbitmq = RabbitMQ(self)
and then _exec()
method could look like:
def _exec(self, args, force_exec_in_check_mode=False):
return self.rabbitmq.exec(args, force_exec_in_check_mode)
Just an idea.
@aitorpazos @odyssey4me what do you think?
I'm also OK with merge this as is and then, provided that the idea is interesting to you, @aitorpazos could implement it in a separate PR (or if you don't have time / wish, I could)
I agree, that would be cleaner, but I'll need to get some more time... (probably this weekend) We can go with option 2 PS: @Andersson007 sorry for not being able to help reviewing PR 83 yesterday
I agree, that would be cleaner, but I'll need to get some more time... (probably this weekend) We can go with option 2 PS: @Andersson007 sorry for not being able to help reviewing PR 83 yesterday
Cool, sounds good to me. And no problem with PR 83! Let's wait for Jesse's feedback for a couple of days.
and take your time, no rush with this at all
@aitorpazos thanks for the contribution! @odyssey4me thanks for reviewing!
This PR has been triggered by this comment in PR #65 (thanks to @Andersson007).
Hopefully it improves the code readability by renaming
run_in_check_mode
parameter toforce_exec_in_check_mode
in the_exec
function used in multiple modules.