mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-31 13:29:08 -07:00
Use common functions for handling import errors (#51851)
* Use common functions for handling import errors * use refactored version of gitlab modules
This commit is contained in:
parent
28dcfa985f
commit
c1e51ef486
39 changed files with 233 additions and 93 deletions
|
@ -34,14 +34,16 @@ import json
|
|||
import os
|
||||
import traceback
|
||||
|
||||
HPE_ONEVIEW_IMP_ERR = None
|
||||
try:
|
||||
from hpOneView.oneview_client import OneViewClient
|
||||
HAS_HPE_ONEVIEW = True
|
||||
except ImportError:
|
||||
HPE_ONEVIEW_IMP_ERR = traceback.format_exc()
|
||||
HAS_HPE_ONEVIEW = False
|
||||
|
||||
from ansible.module_utils import six
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.common._collections_compat import Mapping
|
||||
|
||||
|
@ -202,7 +204,6 @@ class OneViewModuleBase(object):
|
|||
MSG_ALREADY_PRESENT = 'Resource is already present.'
|
||||
MSG_ALREADY_ABSENT = 'Resource is already absent.'
|
||||
MSG_DIFF_AT_KEY = 'Difference found at key \'{0}\'. '
|
||||
HPE_ONEVIEW_SDK_REQUIRED = 'HPE OneView Python SDK is required for this module.'
|
||||
|
||||
ONEVIEW_COMMON_ARGS = dict(
|
||||
config=dict(type='path'),
|
||||
|
@ -257,7 +258,7 @@ class OneViewModuleBase(object):
|
|||
|
||||
def _check_hpe_oneview_sdk(self):
|
||||
if not HAS_HPE_ONEVIEW:
|
||||
self.module.fail_json(msg=self.HPE_ONEVIEW_SDK_REQUIRED)
|
||||
self.module.fail_json(msg=missing_required_lib('hpOneView'), exception=HPE_ONEVIEW_IMP_ERR)
|
||||
|
||||
def _create_oneview_client(self):
|
||||
if self.module.params.get('hostname'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue