mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 10:51:24 -07:00
EthernetNetworkModule for HPE OneView (#28336)
* Adding module to manage ethernet network on HPE OneView * Adding unit tests to EthernetNetwork module * Added OneViewModuleException custom exceptions to module - Removed exception imports from hpOneView - Updated unit tests * Fixing mock import inside ethernet network module unit test * Fixing issues found in METADATA by CI * Updated paths to use solution name instead of vendor name * Fixed documentation, removed redundant if and improved readability * Updated _bulk_present to use and return `result`, same way as _present * Changed __ to _ in private methods following ansible style * Fixed some example inconsistencies and turned states doc into a list * Added adriane-cardozo to list of maintainers
This commit is contained in:
parent
000ccc838a
commit
fb6ed8d76c
4 changed files with 721 additions and 9 deletions
|
@ -36,10 +36,6 @@ import traceback
|
|||
|
||||
try:
|
||||
from hpOneView.oneview_client import OneViewClient
|
||||
from hpOneView.exceptions import (HPOneViewException,
|
||||
HPOneViewTaskError,
|
||||
HPOneViewValueError,
|
||||
HPOneViewResourceNotFound)
|
||||
HAS_HPE_ONEVIEW = True
|
||||
except ImportError:
|
||||
HAS_HPE_ONEVIEW = False
|
||||
|
@ -132,6 +128,69 @@ def _standardize_value(value):
|
|||
return str(value)
|
||||
|
||||
|
||||
class OneViewModuleException(Exception):
|
||||
"""
|
||||
OneView base Exception.
|
||||
|
||||
Attributes:
|
||||
msg (str): Exception message.
|
||||
oneview_response (dict): OneView rest response.
|
||||
"""
|
||||
|
||||
def __init__(self, data):
|
||||
self.msg = None
|
||||
self.oneview_response = None
|
||||
|
||||
if isinstance(data, six.string_types):
|
||||
self.msg = data
|
||||
else:
|
||||
self.oneview_response = data
|
||||
|
||||
if data and isinstance(data, dict):
|
||||
self.msg = data.get('message')
|
||||
|
||||
if self.oneview_response:
|
||||
Exception.__init__(self, self.msg, self.oneview_response)
|
||||
else:
|
||||
Exception.__init__(self, self.msg)
|
||||
|
||||
|
||||
class OneViewModuleTaskError(OneViewModuleException):
|
||||
"""
|
||||
OneView Task Error Exception.
|
||||
|
||||
Attributes:
|
||||
msg (str): Exception message.
|
||||
error_code (str): A code which uniquely identifies the specific error.
|
||||
"""
|
||||
|
||||
def __init__(self, msg, error_code=None):
|
||||
super(OneViewModuleTaskError, self).__init__(msg)
|
||||
self.error_code = error_code
|
||||
|
||||
|
||||
class OneViewModuleValueError(OneViewModuleException):
|
||||
"""
|
||||
OneView Value Error.
|
||||
The exception is raised when the data contains an inappropriate value.
|
||||
|
||||
Attributes:
|
||||
msg (str): Exception message.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class OneViewModuleResourceNotFound(OneViewModuleException):
|
||||
"""
|
||||
OneView Resource Not Found Exception.
|
||||
The exception is raised when an associated resource was not found.
|
||||
|
||||
Attributes:
|
||||
msg (str): Exception message.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class OneViewModuleBase(object):
|
||||
MSG_CREATED = 'Resource created successfully.'
|
||||
|
@ -221,7 +280,7 @@ class OneViewModuleBase(object):
|
|||
|
||||
It calls the inheritor 'execute_module' function and sends the return to the Ansible.
|
||||
|
||||
It handles any HPOneViewException in order to signal a failure to Ansible, with a descriptive error message.
|
||||
It handles any OneViewModuleException in order to signal a failure to Ansible, with a descriptive error message.
|
||||
|
||||
"""
|
||||
try:
|
||||
|
@ -236,7 +295,7 @@ class OneViewModuleBase(object):
|
|||
|
||||
self.module.exit_json(**result)
|
||||
|
||||
except HPOneViewException as exception:
|
||||
except OneViewModuleException as exception:
|
||||
error_msg = '; '.join(to_native(e) for e in exception.args)
|
||||
self.module.fail_json(msg=error_msg, exception=traceback.format_exc())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue