Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/omevv.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Dell OpenManage Ansible Modules
4 # Version 9.8.0
5 # Copyright (C) 2024-2025 Dell Inc. or its subsidiaries. All Rights Reserved.
6
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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)