Debian Codegraph @

ansible_collections/netapp/ontap/plugins/modules/na_ontap_domain_tunnel.py

raw
1 #!/usr/bin/python
2
3 # (c) 2021-2026, NetApp, Inc
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'certified'}
13
14 DOCUMENTATION = '''
15 module: na_ontap_domain_tunnel
16 short_description: NetApp ONTAP domain tunnel
17 extends_documentation_fragment:
18 - netapp.ontap.netapp.na_ontap_rest
19 version_added: '21.3.0'
20 author: NetApp Ansible Team (@carchi8py) <[email protected]>
21 description:
22 - Create, delete or modify the domain tunnel.
23 options:
24 state:
25 description:
26 - Whether the domain tunnel should exist or not.
27 choices: ['present', 'absent']
28 default: present
29 type: str
30
31 vserver:
32 description:
33 - The name of the vserver that the domain tunnel should be created or deleted on.
34 required: true
35 type: str
36
37 lambda_config:
38 description:
39 - Configuration parameters for AWS Lambda proxy functionality.
40 - These option and suboptions are only supported with REST.
41 type: dict
42 version_added: 23.5.0
43 suboptions:
44 function_name:
45 description:
46 - The name of the AWS Lambda function to invoke.
47 type: str
48 required: true
49 aws_region:
50 description:
51 - The name of the AWS region.
52 type: str
53 required: true
54 aws_profile:
55 description:
56 - The name of the AWS profile to use for authentication.
57 type: str
58
59 notes:
60 - Supports AWS Lambda proxy functionality. See README for example usage.
61 '''
62
63 EXAMPLES = """
64 - name: Create Domain Tunnel
65 netapp.ontap.na_ontap_domain_tunnel:
66 state: present
67 vserver: svm1
68 username: "{{ netapp_username }}"
69 password: "{{ netapp_password }}"
70 hostname: "{{ netapp_hostname }}"
71 """
72
73 RETURN = """
74
75 """
76
77 from ansible.module_utils.basic import AnsibleModule
78 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
79 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
80 from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
81
82 # HAS_NETAPP_LIB = netapp_utils.has_netapp_lib()
83
84
85 class NetAppOntapDomainTunnel(object):
86
87 def __init__(self):
88 """
89 Initialize the ONTAP domain tunnel class
90 """
91 self.argument_spec = netapp_utils.na_ontap_rest_only_spec()
92 self.argument_spec.update(dict(
93 state=dict(choices=['present', 'absent'], default='present'),
94 vserver=dict(required=True, type='str')
95 ))
96 self.argument_spec.update(netapp_utils.na_ontap_lambda_argument_spec())
97
98 self.module = AnsibleModule(
99 argument_spec=self.argument_spec,
100 required_if=[
101 ('use_lambda', True, ['lambda_config']),
102 ],
103 supports_check_mode=True
104 )
105
106 self.na_helper = NetAppModule()
107 self.parameters = self.na_helper.set_parameters(self.module.params)
108
109 self.rest_api = OntapRestAPI(self.module)
110 self.use_rest = self.rest_api.is_rest()
111
112 if not self.use_rest:
113 self.module.fail_json(msg=self.rest_api.requires_ontap_version('na_ontap_domain_tunnel', '9.7'))
114
115 def get_domain_tunnel(self):
116 """
117 Get the current domain tunnel info
118 """
119 api = "/security/authentication/cluster/ad-proxy"
120 message, error = self.rest_api.get(api)
121
122 if error:
123 if int(error['code']) != 4: # error code 4 is empty table
124 self.module.fail_json(msg=error)
125 if message:
126 message = {
127 'vserver': message['svm']['name']
128 }
129 return message
130 else:
131 return None
132
133 def create_domain_tunnel(self):
134 """
135 Creates the domain tunnel on the specified vserver
136 """
137 api = "/security/authentication/cluster/ad-proxy"
138 body = {
139 "svm": {
140 "name": self.parameters['vserver']
141 }
142 }
143 dummy, error = self.rest_api.post(api, body)
144 if error:
145 self.module.fail_json(msg=error)
146
147 def modify_domain_tunnel(self):
148 """
149 Modifies the domain tunnel on the specified vserver
150 """
151 api = "/security/authentication/cluster/ad-proxy"
152 body = {
153 "svm": {
154 "name": self.parameters['vserver']
155 }
156 }
157 dummy, error = self.rest_api.patch(api, body)
158 if error:
159 self.module.fail_json(msg=error)
160
161 def delete_domain_tunnel(self):
162 """
163 Deletes the current domain tunnel
164 """
165 api = "/security/authentication/cluster/ad-proxy"
166
167 dummy, error = self.rest_api.delete(api)
168 if error:
169 self.module.fail_json(msg=error)
170
171 def apply(self):
172 current = self.get_domain_tunnel()
173 cd_action = self.na_helper.get_cd_action(current, self.parameters)
174 modify = self.na_helper.get_modified_attributes(current, self.parameters)
175
176 if self.na_helper.changed:
177 if not self.module.check_mode:
178 if cd_action == 'create':
179 self.create_domain_tunnel()
180 elif cd_action == 'delete':
181 self.delete_domain_tunnel()
182 elif modify:
183 self.modify_domain_tunnel()
184
185 result = netapp_utils.generate_result(self.na_helper.changed, cd_action, modify)
186 self.module.exit_json(**result)
187
188
189 def main():
190 """
191 Creates the NetApp ONTAP Domain Tunnel and runs the correct playbook task
192 """
193 obj = NetAppOntapDomainTunnel()
194 obj.apply()
195
196
197 if __name__ == '__main__':
198 main()