mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-19 03:10:22 -07:00
ModuleHelper module utils: delegates unknown attributes to AnsibleModule (#4600)
* ModuleHelper module util: delegates unknown attributes to AnsibleModule * added changelog fragment * delegate only a few selected attrs * Update plugins/module_utils/mh/base.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/4600-mh-delegate.yaml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
f17d2669fa
commit
bca7f09b71
3 changed files with 17 additions and 2 deletions
|
@ -14,6 +14,9 @@ from ansible_collections.community.general.plugins.module_utils.mh.deco import m
|
|||
class ModuleHelperBase(object):
|
||||
module = None
|
||||
ModuleHelperException = _MHE
|
||||
_delegated_to_module = (
|
||||
'check_mode', 'get_bin_path', 'warn', 'deprecate',
|
||||
)
|
||||
|
||||
def __init__(self, module=None):
|
||||
self._changed = False
|
||||
|
@ -24,6 +27,15 @@ class ModuleHelperBase(object):
|
|||
if not isinstance(self.module, AnsibleModule):
|
||||
self.module = AnsibleModule(**self.module)
|
||||
|
||||
@property
|
||||
def diff_mode(self):
|
||||
return self.module._diff
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if attr in self._delegated_to_module:
|
||||
return getattr(self.module, attr)
|
||||
raise AttributeError("ModuleHelperBase has no attribute '%s'" % (attr, ))
|
||||
|
||||
def __init_module__(self):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue