Debian Codegraph @

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

raw
1 #!/usr/bin/python
2
3 # (c) 2021-2025, 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 __metaclass__ = type
8
9 DOCUMENTATION = """
10 module: na_ontap_fdsd
11 short_description: NetApp ONTAP create or remove a File Directory security descriptor.
12 extends_documentation_fragment:
13 - netapp.ontap.netapp.na_ontap_rest
14 version_added: 21.8.0
15 author: NetApp Ansible Team (@carchi8py) <[email protected]>
16
17 description:
18 - Create or remove a security descriptor.
19 options:
20 state:
21 description:
22 - Whether the specified security descriptor should exist or not.
23 choices: ['present', 'absent']
24 default: present
25 type: str
26
27 name:
28 description:
29 - Specifies the name of the security descriptor.
30 required: true
31 type: str
32
33 vserver:
34 description:
35 - Specifies the vserver.
36 required: true
37 type: str
38 """
39
40 EXAMPLES = """
41 - name: Create File Directory Security Descriptor
42 netapp.ontap.na_ontap_fdsd:
43 state: present
44 name: "ansible_sdl"
45 vserver: "svm1"
46 username: "{{ netapp_username }}"
47 password: "{{ netapp_password }}"
48 hostname: "{{ netapp_hostname }}"
49
50 - name: Delete File Directory Security Descriptor
51 netapp.ontap.na_ontap_fdsd:
52 state: absent
53 vserver: "svm1"
54 name: "ansible_sdl"
55 username: "{{ netapp_username }}"
56 password: "{{ netapp_password }}"
57 hostname: "{{ netapp_hostname }}"
58 """
59
60 RETURN = """
61
62 """
63
64 from ansible.module_utils.basic import AnsibleModule
65 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
66 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
67 from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
68 import ansible_collections.netapp.ontap.plugins.module_utils.rest_response_helpers as rrh
69
70
71 class NetAppOntapFDSD():
72 """
73 Creates or removes a File Directory Security Descriptor
74 """
75 def __init__(self):
76 """
77 Initialize the ONTAP File Directory Security Descripter class
78 """
79 self.argument_spec = netapp_utils.na_ontap_rest_only_spec()
80 self.argument_spec.update(dict(
81 state=dict(required=False, choices=['present', 'absent'], default='present'),
82 vserver=dict(required=True, type='str'),
83 name=dict(required=True, type='str')
84 ))
85
86 self.module = AnsibleModule(
87 argument_spec=self.argument_spec,
88 supports_check_mode=True
89 )
90
91 # set up variables
92 self.na_helper = NetAppModule()
93 self.parameters = self.na_helper.set_parameters(self.module.params)
94
95 self.rest_api = OntapRestAPI(self.module)
96 self.use_rest = self.rest_api.is_rest()
97
98 if not self.use_rest:
99 self.module.fail_json(msg=self.rest_api.requires_ontap_version('na_ontap_fdsd', '9.6'))
100
101 def get_fdsd(self):
102 """
103 Get File Directory Security Descriptor
104 """
105 api = "private/cli/vserver/security/file-directory/ntfs"
106 query = {
107 'ntfs-sd': self.parameters['name'],
108 'vserver': self.parameters['vserver']
109 }
110
111 message, error = self.rest_api.get(api, query)
112 records, error = rrh.check_for_0_or_more_records(api, message, error)
113
114 if error:
115 self.module.fail_json(msg=error)
116
117 return records if records else None
118
119 def add_fdsd(self):
120 """
121 Adds a new File Directory Security Descriptor
122 """
123 api = "private/cli/vserver/security/file-directory/ntfs"
124 body = {
125 'ntfs-sd': self.parameters['name'],
126 'vserver': self.parameters['vserver']
127 }
128
129 dummy, error = self.rest_api.post(api, body)
130
131 if error:
132 self.module.fail_json(msg=error)
133
134 def remove_fdsd(self):
135 """
136 Deletes a File Directory Security Descriptor
137 """
138 api = "private/cli/vserver/security/file-directory/ntfs"
139 body = {
140 'ntfs-sd': self.parameters['name'],
141 'vserver': self.parameters['vserver']
142 }
143
144 dummy, error = self.rest_api.delete(api, body)
145
146 if error:
147 self.module.fail_json(msg=error)
148
149 def apply(self):
150 current = self.get_fdsd()
151 cd_action = self.na_helper.get_cd_action(current, self.parameters)
152
153 if self.na_helper.changed:
154 if not self.module.check_mode:
155 if cd_action == 'create':
156 self.add_fdsd()
157 elif cd_action == 'delete':
158 self.remove_fdsd()
159
160 result = netapp_utils.generate_result(self.na_helper.changed, cd_action)
161 self.module.exit_json(**result)
162
163
164 def main():
165 """
166 Creates and removes File Directory Security Descriptors
167 """
168 obj = NetAppOntapFDSD()
169 obj.apply()
170
171
172 if __name__ == '__main__':
173 main()