| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
from __future__ import (absolute_import, division, print_function) |
| 30 |
|
| 31 |
__metaclass__ = type |
| 32 |
|
| 33 |
from ansible_collections.dellemc.openmanage.plugins.module_utils.rest_api import RestAPI |
| 34 |
from ansible.module_utils.common.parameters import env_fallback |
| 35 |
from ansible.module_utils.basic import AnsibleModule |
| 36 |
|
| 37 |
root_omevv_uri = "/omevv/GatewayService/v1" |
| 38 |
|
| 39 |
|
| 40 |
class RestOMEVV(RestAPI): |
| 41 |
def __init__(self, module_params, protocol="https", |
| 42 |
root_uri=root_omevv_uri): |
| 43 |
super().__init__( |
| 44 |
root_uri=root_uri, |
| 45 |
module_params=module_params, |
| 46 |
req_session=False, |
| 47 |
protocol=protocol |
| 48 |
) |
| 49 |
self.username = module_params.get("vcenter_username") |
| 50 |
self.password = module_params.get("vcenter_password") |
| 51 |
self.uuid = module_params.get("vcenter_uuid", "") |
| 52 |
|
| 53 |
def invoke_request(self, method, path, data=None, query_param=None, headers=None, |
| 54 |
api_timeout=None, dump=True): |
| 55 |
""" |
| 56 |
Sends a request through the base invoke request method. |
| 57 |
|
| 58 |
Args: |
| 59 |
method (str): The HTTP method to use for the request. |
| 60 |
path (str): The path to request without query parameter. |
| 61 |
data (dict, optional): The payload to send with the request. Defaults to None. |
| 62 |
query_param (dict, optional): The dictionary of query parameters to send with the request. Defaults to None. |
| 63 |
headers (dict, optional): The dictionary of HTTP headers to send with the request. Defaults to None. |
| 64 |
api_timeout (int, optional): The timeout value for the request. Defaults to None. |
| 65 |
dump (bool, optional): Whether to dump the payload data. Defaults to True. |
| 66 |
|
| 67 |
Returns: |
| 68 |
Response: The response object from the request. |
| 69 |
""" |
| 70 |
if self.uuid: |
| 71 |
headers = headers or {} |
| 72 |
headers["x_omivv-api-vcenter-identifier"] = self.uuid |
| 73 |
return self._base_invoke_request(method, path, data, query_param, headers, |
| 74 |
api_timeout, dump) |
| 75 |
|
| 76 |
|
| 77 |
class OMEVVAnsibleModule(AnsibleModule): |
| 78 |
def __init__(self, argument_spec, bypass_checks=False, no_log=False, |
| 79 |
mutually_exclusive=None, required_together=None, |
| 80 |
required_one_of=None, add_file_common_args=False, |
| 81 |
supports_check_mode=False, required_if=None, required_by=None, |
| 82 |
uuid_required=True): |
| 83 |
omevv_argument_spec = { |
| 84 |
"hostname": {"required": True}, |
| 85 |
"vcenter_username": {"fallback": (env_fallback, ['OMEVV_VCENTER_USERNAME'])}, |
| 86 |
"vcenter_password": {"no_log": True, "fallback": (env_fallback, ['OMEVV_VCENTER_PASSWORD'])}, |
| 87 |
"port": {"default": 443, "type": "int"}, |
| 88 |
"validate_certs": {"default": True, "type": "bool"}, |
| 89 |
"ca_path": {"type": "path"}, |
| 90 |
"timeout": {"default": 30, "type": "int"} |
| 91 |
} |
| 92 |
argument_spec.update(omevv_argument_spec) |
| 93 |
if uuid_required: |
| 94 |
argument_spec["vcenter_uuid"] = {"fallback": (env_fallback, ['OMEVV_VCENTER_UUID']), "type": "str"} |
| 95 |
auth_required_together = [("vcenter_username", "vcenter_password")] |
| 96 |
|
| 97 |
if mutually_exclusive is None: |
| 98 |
mutually_exclusive = [] |
| 99 |
if required_together is None: |
| 100 |
required_together = [] |
| 101 |
required_together.extend(auth_required_together) |
| 102 |
if required_one_of is None: |
| 103 |
required_one_of = [] |
| 104 |
if required_by is None: |
| 105 |
required_by = {} |
| 106 |
|
| 107 |
super().__init__(argument_spec, bypass_checks, no_log, |
| 108 |
mutually_exclusive, required_together, |
| 109 |
required_one_of, add_file_common_args, |
| 110 |
supports_check_mode, required_if, required_by) |