Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 """ this is cifs_server module
3
4 (c) 2018-2026, NetApp, Inc
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6 """
7
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10
11 DOCUMENTATION = '''
12 ---
13 module: na_ontap_cifs_server
14 short_description: NetApp ONTAP CIFS server configuration
15 extends_documentation_fragment:
16 - netapp.ontap.netapp.na_ontap
17 version_added: 2.6.0
18 author: NetApp Ansible Team (@carchi8py) <[email protected]>
19
20 description:
21 - Creating / deleting and modifying the CIFS server .
22
23 options:
24
25 state:
26 description:
27 - Whether the specified cifs_server should exist or not.
28 default: present
29 choices: ['present', 'absent']
30 type: str
31
32 service_state:
33 description:
34 - CIFS Server Administrative Status.
35 choices: ['stopped', 'started']
36 type: str
37
38 name:
39 description:
40 - Specifies the cifs_server name.
41 required: true
42 aliases: ['cifs_server_name']
43 type: str
44
45 comment:
46 description:
47 - A descriptive text comment for the CIFS server.
48 - SMB clients can see the CIFS server comment when browsing servers on the network.
49 - Only supported with REST.
50 type: str
51 version_added: 22.13.0
52
53 admin_user_name:
54 description:
55 - Specifies the cifs server admin username.
56 - When used with absent, the account will be deleted if admin_password is also provided.
57 type: str
58
59 admin_password:
60 description:
61 - Specifies the cifs server admin password.
62 - When used with absent, the account will be deleted if admin_user_name is also provided.
63 type: str
64
65 domain:
66 description:
67 - The Fully Qualified Domain Name of the Windows Active Directory this CIFS server belongs to.
68 type: str
69
70 workgroup:
71 description:
72 - The NetBIOS name of the domain or workgroup this CIFS server belongs to.
73 type: str
74
75 ou:
76 description:
77 - The Organizational Unit (OU) within the Windows Active Directory this CIFS server belongs to.
78 version_added: 2.7.0
79 type: str
80
81 default_site:
82 description:
83 - Specifies the site within the Active Directory domain to associate with the CIFS server if Data ONTAP cannot determine an appropriate site.
84 - Only supported with REST and requires ontap version 9.13.1 or later.
85 version_added: 22.8.0
86 type: str
87
88 force:
89 type: bool
90 description:
91 - When state is present, if this is set and a machine account with the same name as specified in 'name' exists in the Active Directory,
92 it will be overwritten and reused.
93 - When state is absent, if this is set, the local CIFS configuration is deleted regardless of communication errors.
94 - For REST, it requires ontap version 9.11.
95 version_added: 2.7.0
96
97 vserver:
98 description:
99 - The name of the vserver to use.
100 required: true
101 type: str
102
103 from_name:
104 description:
105 - Specifies the existing cifs_server name.
106 - This option is used to rename cifs_server.
107 - Supported only in REST and requires force to be set to True.
108 - Requires ontap version 9.11.0.
109 - if the service is running, it will be stopped to perform the rename action, and automatically restarts.
110 - if the service is stopped, it will be briefly restarted after the rename action, and stopped again.
111 type: str
112 version_added: 21.19.0
113
114 encrypt_dc_connection:
115 description:
116 - Specifies whether encryption is required for domain controller connections.
117 - Only supported with REST and requires ontap version 9.8 or later. Use na_ontap_vserver_cifs_security with ZAPI.
118 type: bool
119 version_added: 21.20.0
120
121 kdc_encryption:
122 description:
123 - Specifies whether AES-128 and AES-256 encryption is enabled for all Kerberos-based communication with the Active Directory KDC.
124 - Only supported with REST. Use na_ontap_vserver_cifs_security with ZAPI.
125 type: bool
126 version_added: 21.20.0
127
128 smb_encryption:
129 description:
130 - Determine whether SMB encryption is required for incoming CIFS traffic.
131 - Only supported with REST. Use na_ontap_vserver_cifs_security with ZAPI.
132 type: bool
133 version_added: 21.20.0
134
135 smb_signing:
136 description:
137 - Specifies whether signing is required for incoming CIFS traffic.
138 - Only supported with REST. Use na_ontap_vserver_cifs_security with ZAPI.
139 type: bool
140 version_added: 21.20.0
141
142 restrict_anonymous:
143 description:
144 - Specifies what level of access an anonymous user is granted.
145 - Only supported with REST.
146 choices: ['no_enumeration', 'no_restriction', 'no_access']
147 type: str
148 version_added: 21.20.0
149
150 aes_netlogon_enabled:
151 description:
152 - Specifies whether or not an AES session key is enabled for the Netlogon channel.
153 - Only supported with REST and requires ontap version 9.10.1 or later.
154 type: bool
155 version_added: 21.20.0
156
157 ldap_referral_enabled:
158 description:
159 - Specifies whether or not LDAP referral chasing is enabled for AD LDAP connections.
160 - Only supported with REST and requires ontap version 9.10.1 or later. Use na_ontap_vserver_cifs_security with ZAPI.
161 type: bool
162 version_added: 21.20.0
163
164 use_ldaps:
165 description:
166 - Specifies whether or not to use use LDAPS for secure Active Directory LDAP connections.
167 - Only supported with REST and requires ontap version 9.10.1 or later. Use na_ontap_vserver_cifs_security with ZAPI.
168 type: bool
169 version_added: 21.20.0
170
171 use_start_tls:
172 description:
173 - Specifies whether or not to use SSL/TLS for allowing secure LDAP communication with Active Directory LDAP servers.
174 - Only supported with REST and requires ontap version 9.10.1 or later. Use na_ontap_vserver_cifs_security with ZAPI.
175 type: bool
176 version_added: 21.20.0
177
178 try_ldap_channel_binding:
179 description:
180 - Specifies whether or not channel binding is attempted in the case of TLS/LDAPS.
181 - Only supported with REST and requires ontap version 9.10.1 or later. Use na_ontap_vserver_cifs_security with ZAPI.
182 type: bool
183 version_added: 21.20.0
184
185 session_security:
186 description:
187 - Specifies client session security for AD LDAP connections.
188 - Only supported with REST and requires ontap version 9.10.1 or later. Use na_ontap_vserver_cifs_security with ZAPI.
189 choices: ['none', 'sign', 'seal']
190 type: str
191 version_added: 21.20.0
192
193 lm_compatibility_level:
194 description:
195 - Specifies CIFS server minimum security level, also known as the LMCompatibilityLevel.
196 - Only supported with REST and requires ontap version 9.8 or later. Use na_ontap_vserver_cifs_security with ZAPI.
197 choices: ['lm_ntlm_ntlmv2_krb', 'ntlm_ntlmv2_krb', 'ntlmv2_krb', 'krb']
198 type: str
199 version_added: 22.9.0
200
201 is_multichannel_enabled:
202 description:
203 - Specifies whether the CIFS server supports Multichannel or not.
204 - Only supported with REST and requires ontap version 9.10 or later.
205 type: bool
206 version_added: 22.10.0
207
208 lambda_config:
209 description:
210 - Configuration parameters for AWS Lambda proxy functionality.
211 - These option and suboptions are only supported with REST.
212 type: dict
213 version_added: 23.4.0
214 suboptions:
215 function_name:
216 description:
217 - The name of the AWS Lambda function to invoke.
218 type: str
219 required: true
220 aws_region:
221 description:
222 - The name of the AWS region.
223 type: str
224 required: true
225 aws_profile:
226 description:
227 - The name of the AWS profile to use for authentication.
228 type: str
229
230 notes:
231 - Supports AWS Lambda proxy functionality when using REST. See README for example usage.
232 '''
233
234 EXAMPLES = '''
235 - name: Create cifs_server
236 netapp.ontap.na_ontap_cifs_server:
237 state: present
238 name: data2
239 vserver: svm1
240 service_state: stopped
241 domain: "{{ id_domain }}"
242 admin_user_name: "{{ domain_login }}"
243 admin_password: "{{ domain_pwd }}"
244 hostname: "{{ netapp_hostname }}"
245 username: "{{ netapp_username }}"
246 password: "{{ netapp_password }}"
247
248 - name: Delete cifs_server
249 netapp.ontap.na_ontap_cifs_server:
250 state: absent
251 name: data2
252 vserver: svm1
253 admin_user_name: "{{ domain_login }}"
254 admin_password: "{{ domain_pwd }}"
255 hostname: "{{ netapp_hostname }}"
256 username: "{{ netapp_username }}"
257 password: "{{ netapp_password }}"
258
259 - name: Start cifs_server
260 netapp.ontap.na_ontap_cifs_server:
261 state: present
262 name: data2
263 vserver: svm1
264 service_state: started
265 hostname: "{{ netapp_hostname }}"
266 username: "{{ netapp_username }}"
267 password: "{{ netapp_password }}"
268
269 - name: Stop cifs_server
270 netapp.ontap.na_ontap_cifs_server:
271 state: present
272 name: data2
273 vserver: svm1
274 service_state: stopped
275 hostname: "{{ netapp_hostname }}"
276 username: "{{ netapp_username }}"
277 password: "{{ netapp_password }}"
278
279 - name: Rename cifs_server - REST
280 netapp.ontap.na_ontap_cifs_server:
281 state: present
282 from_name: data2
283 name: cifs
284 vserver: svm1
285 force: true
286 hostname: "{{ netapp_hostname }}"
287 username: "{{ netapp_username }}"
288 password: "{{ netapp_password }}"
289
290 - name: Modify cifs_server security - REST
291 netapp.ontap.na_ontap_cifs_server:
292 state: present
293 name: data2
294 vserver: svm1
295 service_state: stopped
296 encrypt_dc_connection: true
297 smb_encryption: true
298 kdc_encryption: true
299 smb_signing: true
300 aes_netlogon_enabled: true
301 ldap_referral_enabled: true
302 session_security: seal
303 try_ldap_channel_binding: false
304 use_ldaps: true
305 use_start_tls: true
306 restrict_anonymous: no_access
307 domain: "{{ id_domain }}"
308 admin_user_name: "{{ domain_login }}"
309 admin_password: "{{ domain_pwd }}"
310 hostname: "{{ netapp_hostname }}"
311 username: "{{ netapp_username }}"
312 password: "{{ netapp_password }}"
313 '''
314
315 RETURN = '''
316 '''
317
318 import traceback
319
320 from ansible.module_utils.basic import AnsibleModule
321 from ansible.module_utils._text import to_native
322 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
323 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
324 from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
325 from ansible_collections.netapp.ontap.plugins.module_utils import rest_generic
326
327
328 class NetAppOntapcifsServer:
329 """
330 object to describe cifs_server info
331 """
332
333 def __init__(self):
334
335 self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
336 self.argument_spec.update(dict(
337 state=dict(required=False, choices=['present', 'absent'], default='present'),
338 service_state=dict(required=False, choices=['stopped', 'started']),
339 name=dict(required=True, type='str', aliases=['cifs_server_name']),
340 workgroup=dict(required=False, type='str', default=None),
341 domain=dict(required=False, type='str'),
342 admin_user_name=dict(required=False, type='str'),
343 admin_password=dict(required=False, type='str', no_log=True),
344 ou=dict(required=False, type='str'),
345 default_site=dict(required=False, type='str'),
346 force=dict(required=False, type='bool'),
347 vserver=dict(required=True, type='str'),
348 comment=dict(required=False, type='str'),
349 from_name=dict(required=False, type='str'),
350 smb_signing=dict(required=False, type='bool'),
351 encrypt_dc_connection=dict(required=False, type='bool'),
352 kdc_encryption=dict(required=False, type='bool'),
353 smb_encryption=dict(required=False, type='bool'),
354 restrict_anonymous=dict(required=False, type='str', choices=['no_enumeration', 'no_restriction', 'no_access']),
355 aes_netlogon_enabled=dict(required=False, type='bool'),
356 ldap_referral_enabled=dict(required=False, type='bool'),
357 session_security=dict(required=False, type='str', choices=['none', 'sign', 'seal']),
358 lm_compatibility_level=dict(required=False, type='str', choices=['lm_ntlm_ntlmv2_krb', 'ntlm_ntlmv2_krb', 'ntlmv2_krb', 'krb']),
359 try_ldap_channel_binding=dict(required=False, type='bool'),
360 use_ldaps=dict(required=False, type='bool'),
361 use_start_tls=dict(required=False, type='bool'),
362 is_multichannel_enabled=dict(required=False, type='bool'),
363 ))
364 self.argument_spec.update(netapp_utils.na_ontap_lambda_argument_spec())
365
366 self.module = AnsibleModule(
367 argument_spec=self.argument_spec,
368 supports_check_mode=True,
369 mutually_exclusive=[('use_ldaps', 'use_start_tls')],
370 required_if=[
371 ['use_lambda', True, ('lambda_config',)]
372 ]
373 )
374
375 self.na_helper = NetAppModule()
376 self.parameters = self.na_helper.set_parameters(self.module.params)
377
378 self.parameters['cifs_server_name'] = self.parameters['name']
379 # Set up Rest API
380 self.rest_api = OntapRestAPI(self.module)
381 unsupported_rest_properties = ['workgroup']
382 partially_supported_rest_properties = [['encrypt_dc_connection', (9, 8)], ['lm_compatibility_level', (9, 8)],
383 ['aes_netlogon_enabled', (9, 10, 1)], ['ldap_referral_enabled', (9, 10, 1)], ['session_security', (9, 10, 1)],
384 ['try_ldap_channel_binding', (9, 10, 1)], ['use_ldaps', (9, 10, 1)], ['use_start_tls', (9, 10, 1)],
385 ['is_multichannel_enabled', (9, 10, 1)], ['force', (9, 11)], ['default_site', (9, 13, 1)]]
386 self.use_rest = self.rest_api.is_rest_supported_properties(self.parameters, unsupported_rest_properties, partially_supported_rest_properties)
387
388 if not self.use_rest:
389 if self.parameters.get('use_lambda'):
390 self.module.fail_json(msg="Error: AWS Lambda proxy for ONTAP APIs is only supported with REST.")
391 unsupported_zapi_properties = ['comment', 'smb_signing', 'encrypt_dc_connection', 'kdc_encryption', 'smb_encryption', 'restrict_anonymous',
392 'aes_netlogon_enabled', 'ldap_referral_enabled', 'try_ldap_channel_binding', 'session_security',
393 'lm_compatibility_level', 'use_ldaps', 'use_start_tls', 'from_name', 'default_site', 'is_multichannel_enabled']
394 used_unsupported_zapi_properties = [option for option in unsupported_zapi_properties if option in self.parameters]
395 if used_unsupported_zapi_properties:
396 self.module.fail_json(msg="Error: %s options supported only with REST." % " ,".join(used_unsupported_zapi_properties))
397 if not netapp_utils.has_netapp_lib():
398 self.module.fail_json(msg=netapp_utils.netapp_lib_is_required())
399 self.server = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=self.parameters['vserver'])
400
401 def get_cifs_server(self):
402 """
403 Return details about the CIFS-server
404 :param:
405 name : Name of the name of the cifs_server
406
407 :return: Details about the cifs_server. None if not found.
408 :rtype: dict
409 """
410 cifs_server_info = netapp_utils.zapi.NaElement('cifs-server-get-iter')
411 cifs_server_attributes = netapp_utils.zapi.NaElement('cifs-server-config')
412 cifs_server_attributes.add_new_child('cifs-server', self.parameters['cifs_server_name'])
413 cifs_server_attributes.add_new_child('vserver', self.parameters['vserver'])
414 query = netapp_utils.zapi.NaElement('query')
415 query.add_child_elem(cifs_server_attributes)
416 cifs_server_info.add_child_elem(query)
417 result = self.server.invoke_successfully(cifs_server_info, True)
418 return_value = None
419
420 if result.get_child_by_name('num-records') and \
421 int(result.get_child_content('num-records')) >= 1:
422
423 cifs_server_attributes = result.get_child_by_name('attributes-list').\
424 get_child_by_name('cifs-server-config')
425 service_state = cifs_server_attributes.get_child_content('administrative-status')
426 return_value = {
427 'cifs_server_name': self.parameters['cifs_server_name'],
428 'service_state': 'started' if service_state == 'up' else 'stopped'
429 }
430 return return_value
431
432 def create_cifs_server(self):
433 """
434 calling zapi to create cifs_server
435 """
436 options = {'cifs-server': self.parameters['cifs_server_name']}
437 if 'service_state' in self.parameters:
438 options['administrative-status'] = 'up' if self.parameters['service_state'] == 'started' else 'down'
439 if 'workgroup' in self.parameters:
440 options['workgroup'] = self.parameters['workgroup']
441 if 'domain' in self.parameters:
442 options['domain'] = self.parameters['domain']
443 if 'admin_user_name' in self.parameters:
444 options['admin-username'] = self.parameters['admin_user_name']
445 if 'admin_password' in self.parameters:
446 options['admin-password'] = self.parameters['admin_password']
447 if 'ou' in self.parameters:
448 options['organizational-unit'] = self.parameters['ou']
449 if 'force' in self.parameters:
450 options['force-account-overwrite'] = str(self.parameters['force']).lower()
451
452 cifs_server_create = netapp_utils.zapi.NaElement.create_node_with_children(
453 'cifs-server-create', **options)
454
455 try:
456 self.server.invoke_successfully(cifs_server_create,
457 enable_tunneling=True)
458 except netapp_utils.zapi.NaApiError as exc:
459 self.module.fail_json(msg='Error Creating cifs_server %s: %s' %
460 (self.parameters['cifs_server_name'], to_native(exc)), exception=traceback.format_exc())
461
462 def delete_cifs_server(self):
463 """
464 calling zapi to create cifs_server
465 """
466 options = {}
467 if 'admin_user_name' in self.parameters:
468 options['admin-username'] = self.parameters['admin_user_name']
469 if 'admin_password' in self.parameters:
470 options['admin-password'] = self.parameters['admin_password']
471 if 'force' in self.parameters:
472 options['force-account-delete'] = str(self.parameters['force']).lower()
473
474 if options:
475 cifs_server_delete = netapp_utils.zapi.NaElement.create_node_with_children('cifs-server-delete', **options)
476 else:
477 cifs_server_delete = netapp_utils.zapi.NaElement.create_node_with_children('cifs-server-delete')
478
479 try:
480 self.server.invoke_successfully(cifs_server_delete,
481 enable_tunneling=True)
482 except netapp_utils.zapi.NaApiError as exc:
483 self.module.fail_json(msg='Error deleting cifs_server %s: %s' % (self.parameters['cifs_server_name'], to_native(exc)),
484 exception=traceback.format_exc())
485
486 def start_cifs_server(self):
487 """
488 RModify the cifs_server.
489 """
490 cifs_server_modify = netapp_utils.zapi.NaElement.create_node_with_children(
491 'cifs-server-start')
492 try:
493 self.server.invoke_successfully(cifs_server_modify,
494 enable_tunneling=True)
495 except netapp_utils.zapi.NaApiError as e:
496 self.module.fail_json(msg='Error modifying cifs_server %s: %s' % (self.parameters['cifs_server_name'], to_native(e)),
497 exception=traceback.format_exc())
498
499 def stop_cifs_server(self):
500 """
501 RModify the cifs_server.
502 """
503 cifs_server_modify = netapp_utils.zapi.NaElement.create_node_with_children(
504 'cifs-server-stop')
505 try:
506 self.server.invoke_successfully(cifs_server_modify, enable_tunneling=True)
507 except netapp_utils.zapi.NaApiError as e:
508 self.module.fail_json(msg='Error modifying cifs_server %s: %s' % (self.parameters['cifs_server_name'], to_native(e)),
509 exception=traceback.format_exc())
510
511 def get_cifs_server_rest(self, from_name=None):
512 """
513 get details of the cifs_server.
514 """
515 if not self.use_rest:
516 return self.get_cifs_server()
517 query = {'svm.name': self.parameters['vserver'],
518 'fields': 'svm.uuid,'
519 'enabled,'
520 'comment,'
521 'security.smb_encryption,'
522 'security.kdc_encryption,'
523 'security.smb_signing,'
524 'security.restrict_anonymous,'
525 'ad_domain,'}
526 query['name'] = from_name or self.parameters['cifs_server_name']
527 api = 'protocols/cifs/services'
528 if self.rest_api.meets_rest_minimum_version(self.use_rest, 9, 8):
529 security_option_9_8 = ('security.encrypt_dc_connection,'
530 'security.lm_compatibility_level,')
531 query['fields'] += security_option_9_8
532
533 if self.rest_api.meets_rest_minimum_version(self.use_rest, 9, 10, 1):
534 security_option_9_10 = ('security.use_ldaps,'
535 'security.use_start_tls,'
536 'security.try_ldap_channel_binding,'
537 'security.session_security,'
538 'security.ldap_referral_enabled,'
539 'security.aes_netlogon_enabled,')
540 query['fields'] += security_option_9_10
541
542 if self.rest_api.meets_rest_minimum_version(self.use_rest, 9, 10, 1):
543 service_option_9_10 = ('options.multichannel,')
544 query['fields'] += service_option_9_10
545 record, error = rest_generic.get_one_record(self.rest_api, api, query)
546 if error:
547 self.module.fail_json(msg="Error on fetching cifs: %s" % error)
548 if record:
549 record['service_state'] = 'started' if record.pop('enabled') else 'stopped'
550 return {
551 'svm': {'uuid': self.na_helper.safe_get(record, ['svm', 'uuid'])},
552 'cifs_server_name': self.na_helper.safe_get(record, ['name']),
553 'service_state': self.na_helper.safe_get(record, ['service_state']),
554 'smb_signing': self.na_helper.safe_get(record, ['security', 'smb_signing']),
555 'encrypt_dc_connection': self.na_helper.safe_get(record, ['security', 'encrypt_dc_connection']),
556 'kdc_encryption': self.na_helper.safe_get(record, ['security', 'kdc_encryption']),
557 'smb_encryption': self.na_helper.safe_get(record, ['security', 'smb_encryption']),
558 'aes_netlogon_enabled': self.na_helper.safe_get(record, ['security', 'aes_netlogon_enabled']),
559 'ldap_referral_enabled': self.na_helper.safe_get(record, ['security', 'ldap_referral_enabled']),
560 'session_security': self.na_helper.safe_get(record, ['security', 'session_security']),
561 'lm_compatibility_level': self.na_helper.safe_get(record, ['security', 'lm_compatibility_level']),
562 'try_ldap_channel_binding': self.na_helper.safe_get(record, ['security', 'try_ldap_channel_binding']),
563 'use_ldaps': self.na_helper.safe_get(record, ['security', 'use_ldaps']),
564 'use_start_tls': self.na_helper.safe_get(record, ['security', 'use_start_tls']),
565 'restrict_anonymous': self.na_helper.safe_get(record, ['security', 'restrict_anonymous']),
566 'is_multichannel_enabled': self.na_helper.safe_get(record, ['options', 'multichannel']),
567 'comment': self.na_helper.safe_get(record, ['comment']),
568 'ou': self.na_helper.safe_get(record, ['ad_domain', 'organizational_unit']),
569 'domain': self.na_helper.safe_get(record, ['ad_domain', 'fqdn']),
570 'default_site': self.na_helper.safe_get(record, ['ad_domain', 'default_site']),
571 }
572 return record
573
574 def build_ad_domain(self, params=None):
575 if params is None:
576 params = self.parameters
577 ad_domain = {}
578 if 'admin_user_name' in params:
579 ad_domain['user'] = params['admin_user_name']
580 if 'admin_password' in params:
581 ad_domain['password'] = params['admin_password']
582 if 'ou' in params:
583 ad_domain['organizational_unit'] = params['ou']
584 if 'domain' in params:
585 ad_domain['fqdn'] = params['domain']
586 if 'default_site' in params:
587 ad_domain['default_site'] = params['default_site']
588 return ad_domain
589
590 def create_modify_body_rest(self, params=None):
591 """
592 Function to define body for create and modify cifs server
593 """
594 body, query, security, service_options = {}, {}, {}, {}
595 if params is None:
596 params = self.parameters
597 security_options = ['smb_signing', 'encrypt_dc_connection', 'kdc_encryption', 'smb_encryption', 'restrict_anonymous',
598 'aes_netlogon_enabled', 'ldap_referral_enabled', 'try_ldap_channel_binding', 'session_security',
599 'lm_compatibility_level', 'use_ldaps', 'use_start_tls']
600 ad_domain = self.build_ad_domain(params)
601 if ad_domain:
602 body['ad_domain'] = ad_domain
603 if 'force' in self.parameters:
604 query['force'] = self.parameters['force']
605 for key in security_options:
606 if key in params:
607 security[key] = params[key]
608 if security:
609 body['security'] = security
610 # for parameters having different key names in REST API and module inputs
611 for key, option in [
612 ('multichannel', 'is_multichannel_enabled'),
613 ]:
614 if option in params:
615 service_options.update({key: params[option]})
616 if service_options:
617 body['options'] = service_options
618 if 'vserver' in params:
619 body['svm.name'] = params['vserver']
620 if 'cifs_server_name' in params:
621 body['name'] = params['cifs_server_name']
622 if 'service_state' in params:
623 body['enabled'] = params['service_state'] == 'started'
624 if 'comment' in params:
625 body['comment'] = params['comment']
626 return body, query
627
628 def create_cifs_server_rest(self):
629 """
630 create the cifs_server.
631 """
632 if not self.use_rest:
633 return self.create_cifs_server()
634 body, query = self.create_modify_body_rest()
635 api = 'protocols/cifs/services'
636 dummy, error = rest_generic.post_async(self.rest_api, api, body, query)
637 if error is not None:
638 self.module.fail_json(msg="Error on creating cifs: %s" % error)
639
640 def delete_cifs_server_rest(self, current):
641 """
642 delete the cifs_server.
643 """
644 if not self.use_rest:
645 return self.delete_cifs_server()
646 ad_domain = self.build_ad_domain()
647 body = {'ad_domain': ad_domain} if ad_domain else None
648 query = {}
649 if 'force' in self.parameters:
650 query['force'] = self.parameters['force']
651 api = 'protocols/cifs/services'
652 dummy, error = rest_generic.delete_async(self.rest_api, api, current['svm']['uuid'], query, body=body)
653 if error is not None:
654 self.module.fail_json(msg="Error on deleting cifs server: %s" % error)
655
656 def modify_cifs_server_rest(self, current, modify):
657 """
658 Modify the state of CIFS server.
659 rename: cifs server should be in stopped state
660 """
661 if not self.use_rest:
662 return self.modify_cifs_server()
663 body, query = self.create_modify_body_rest(modify)
664 api = 'protocols/cifs/services'
665 dummy, error = rest_generic.patch_async(self.rest_api, api, current['svm']['uuid'], body, query)
666 if error is not None:
667 self.module.fail_json(msg="Error on modifying cifs server: %s" % error)
668
669 def modify_cifs_server(self):
670 """
671 Start or stop cifs server in ZAPI.
672 """
673 if self.parameters.get('service_state') == 'stopped':
674 self.stop_cifs_server()
675 else:
676 self.start_cifs_server()
677
678 def apply(self):
679 current = self.get_cifs_server_rest()
680 cd_action = self.na_helper.get_cd_action(current, self.parameters)
681 if cd_action == 'create' and 'from_name' in self.parameters:
682 current = self.get_cifs_server_rest(self.parameters['from_name'])
683 if current is None:
684 self.module.fail_json(msg='Error renaming cifs server: %s - no cifs server with from_name: %s.'
685 % (self.parameters['name'], self.parameters['from_name']))
686 if not self.parameters.get('force'):
687 self.module.fail_json(msg='Error: cannot rename cifs server from %s to %s without force.'
688 % (self.parameters['from_name'], self.parameters['name']))
689 # rename is handled in modify in REST.
690 cd_action = None
691 modify = self.na_helper.get_modified_attributes(current, self.parameters) if cd_action is None else None
692 if self.na_helper.changed and not self.module.check_mode:
693 if cd_action == 'create':
694 self.create_cifs_server_rest()
695 elif cd_action == 'delete':
696 self.delete_cifs_server_rest(current)
697 else:
698 self.modify_cifs_server_rest(current, modify)
699 # rename will enable the cifs server also, so disable it if service_state is stopped.
700 if 'cifs_server_name' in modify and self.parameters.get('service_state') == 'stopped':
701 self.modify_cifs_server_rest(current, {'service_state': 'stopped'})
702 result = netapp_utils.generate_result(self.na_helper.changed, cd_action, modify)
703 self.module.exit_json(**result)
704
705
706 def main():
707 cifs_server = NetAppOntapcifsServer()
708 cifs_server.apply()
709
710
711 if __name__ == '__main__':
712 main()