mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Refactor E-Series Hosts module to use module_utils (#20893)
Refactor the NetApp E-Series module to utlize the common module_utils and doc_fragments.
This commit is contained in:
parent
a5b483da16
commit
1b9d9376e2
1 changed files with 4 additions and 61 deletions
|
@ -20,28 +20,9 @@ description:
|
|||
- Create, update, remove hosts on NetApp E-series storage arrays
|
||||
version_added: '2.2'
|
||||
author: Kevin Hulquest (@hulquest)
|
||||
extends_documentation_fragment:
|
||||
- netapp.eseries
|
||||
options:
|
||||
api_username:
|
||||
required: true
|
||||
description:
|
||||
- The username to authenticate with the SANtricity WebServices Proxy or embedded REST API.
|
||||
api_password:
|
||||
required: true
|
||||
description:
|
||||
- The password to authenticate with the SANtricity WebServices Proxy or embedded REST API.
|
||||
api_url:
|
||||
required: true
|
||||
description:
|
||||
- The url to the SANtricity WebServices Proxy or embedded REST API, for example C(https://prod-1.wahoo.acme.com/devmgr/v2).
|
||||
validate_certs:
|
||||
required: false
|
||||
default: true
|
||||
description:
|
||||
- Should https certificates be validated?
|
||||
ssid:
|
||||
description:
|
||||
- the id of the storage array you wish to act against
|
||||
required: True
|
||||
name:
|
||||
description:
|
||||
- If the host doesn't yet exist, the label to assign at creation time.
|
||||
|
@ -83,11 +64,9 @@ msg:
|
|||
"""
|
||||
import json
|
||||
|
||||
from ansible.module_utils.api import basic_auth_argument_spec
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.netapp import request, eseries_host_argument_spec
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
|
||||
HEADERS = {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -95,46 +74,10 @@ HEADERS = {
|
|||
}
|
||||
|
||||
|
||||
def request(url, data=None, headers=None, method='GET', use_proxy=True,
|
||||
force=False, last_mod_time=None, timeout=10, validate_certs=True,
|
||||
url_username=None, url_password=None, http_agent=None, force_basic_auth=True, ignore_errors=False):
|
||||
try:
|
||||
r = open_url(url=url, data=data, headers=headers, method=method, use_proxy=use_proxy,
|
||||
force=force, last_mod_time=last_mod_time, timeout=timeout, validate_certs=validate_certs,
|
||||
url_username=url_username, url_password=url_password, http_agent=http_agent,
|
||||
force_basic_auth=force_basic_auth)
|
||||
except HTTPError:
|
||||
err = get_exception()
|
||||
r = err.fp
|
||||
|
||||
try:
|
||||
raw_data = r.read()
|
||||
if raw_data:
|
||||
data = json.loads(raw_data)
|
||||
else:
|
||||
raw_data is None
|
||||
except:
|
||||
if ignore_errors:
|
||||
pass
|
||||
else:
|
||||
raise Exception(raw_data)
|
||||
|
||||
resp_code = r.getcode()
|
||||
|
||||
if resp_code >= 400 and not ignore_errors:
|
||||
raise Exception(resp_code, data)
|
||||
else:
|
||||
return resp_code, data
|
||||
|
||||
|
||||
class Host(object):
|
||||
def __init__(self):
|
||||
argument_spec = basic_auth_argument_spec()
|
||||
argument_spec = eseries_host_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
api_username=dict(type='str', required=True),
|
||||
api_password=dict(type='str', required=True, no_log=True),
|
||||
api_url=dict(type='str', required=True),
|
||||
ssid=dict(type='str', required=True),
|
||||
state=dict(type='str', required=True, choices=['absent', 'present']),
|
||||
group=dict(type='str', required=False),
|
||||
ports=dict(type='list', required=False),
|
||||
|
|
Loading…
Reference in a new issue