Skip to content
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

Simple code refactoring needed #94

Open
Andersson007 opened this issue Aug 13, 2021 · 2 comments
Open

Simple code refactoring needed #94

Andersson007 opened this issue Aug 13, 2021 · 2 comments
Labels
easyfix help wanted Extra attention is needed

Comments

@Andersson007
Copy link
Contributor

SUMMARY

Relates #89 (comment)

the modules use the same function _exec. 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.

  1. Move the code to a library under plugins/module_utils
  2. It could be a parental class but i personally prefer composition.
  3. Or it could be just a function, say, 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)
ISSUE TYPE
  • Feature Idea
COMPONENT NAME

Many modules

@Andersson007
Copy link
Contributor Author

@aitorpazos i created this issue not to forget. if you're still interested in this, please put it explicitly here to avoid working in parallel

@Andersson007 Andersson007 added easyfix help wanted Extra attention is needed labels Aug 13, 2021
@aitorpazos
Copy link
Contributor

Sure, busy atm but will address it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easyfix help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants