Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_ntp_policy.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Tim Cragg (@timcragg)
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {
12 "metadata_version": "1.1",
13 "status": ["preview"],
14 "supported_by": "community",
15 }
16
17 DOCUMENTATION = r"""
18 ---
19 module: aci_ntp_policy
20 short_description: Manage NTP policies (datetime:Pol)
21 description:
22 - Manage NTP policy configuration on Cisco ACI fabrics.
23 options:
24 name:
25 description:
26 - Name of the NTP policy
27 type: str
28 aliases: [ ntp_policy ]
29 description:
30 description:
31 - Description of the NTP policy
32 type: str
33 admin_state:
34 description:
35 - Admin state of the policy
36 type: str
37 choices: [ disabled, enabled ]
38 server_state:
39 description:
40 - Allow switches to act as NTP servers
41 type: str
42 choices: [ disabled, enabled ]
43 auth_state:
44 description:
45 - Enable authentication
46 type: str
47 choices: [ disabled, enabled ]
48 master_mode:
49 description:
50 - Enable master mode. Only applicable if server_state is enabled
51 type: str
52 choices: [ disabled, enabled ]
53 stratum:
54 description:
55 - The NTP stratum value.
56 - The APIC defaults to C(8) when not provided.
57 - The allowed minimum is C(1) and the allowed maximum is C(15).
58 type: int
59 state:
60 description:
61 - Use C(present) or C(absent) for adding or removing.
62 - Use C(query) for listing an object or multiple objects.
63 type: str
64 choices: [ absent, present, query ]
65 default: present
66 extends_documentation_fragment:
67 - cisco.aci.aci
68 - cisco.aci.annotation
69 - cisco.aci.owner
70
71 seealso:
72 - name: APIC Management Information Model reference
73 description: More information about the internal APIC class B(datetime:Pol).
74 link: https://developer.cisco.com/docs/apic-mim-ref/
75 author:
76 - Tim Cragg (@timcragg)
77 - Akini Ross (@akinross)
78 """
79
80 EXAMPLES = r"""
81 - name: Add a new NTP policy
82 cisco.aci.aci_ntp_policy:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 name: my_ntp_policy
87 description: via Ansible
88 admin_state: enabled
89 state: present
90 delegate_to: localhost
91
92 - name: Remove a NTP policy
93 cisco.aci.aci_ntp_policy:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 name: my_ntp_policy
98 state: absent
99 delegate_to: localhost
100
101 - name: Query a NTP policy
102 cisco.aci.aci_ntp_policy:
103 host: apic
104 username: admin
105 password: SomeSecretPassword
106 name: my_ntp_policy
107 state: query
108 delegate_to: localhost
109 register: query_result
110
111 - name: Query all NTP policies
112 cisco.aci.aci_ntp_policy:
113 host: apic
114 username: admin
115 password: SomeSecretPassword
116 state: query
117 delegate_to: localhost
118 register: query_result
119 """
120
121 RETURN = r"""
122 current:
123 description: The existing configuration from the APIC after the module has finished
124 returned: success
125 type: list
126 sample:
127 [
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production environment",
132 "dn": "uni/tn-production",
133 "name": "production",
134 "nameAlias": "",
135 "ownerKey": "",
136 "ownerTag": ""
137 }
138 }
139 }
140 ]
141 error:
142 description: The error information as returned from the APIC
143 returned: failure
144 type: dict
145 sample:
146 {
147 "code": "122",
148 "text": "unknown managed object class foo"
149 }
150 raw:
151 description: The raw output returned by the APIC REST API (xml or json)
152 returned: parse error
153 type: str
154 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
155 sent:
156 description: The actual/minimal configuration pushed to the APIC
157 returned: info
158 type: list
159 sample:
160 {
161 "fvTenant": {
162 "attributes": {
163 "descr": "Production environment"
164 }
165 }
166 }
167 previous:
168 description: The original configuration from the APIC before the module has started
169 returned: info
170 type: list
171 sample:
172 [
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production",
177 "dn": "uni/tn-production",
178 "name": "production",
179 "nameAlias": "",
180 "ownerKey": "",
181 "ownerTag": ""
182 }
183 }
184 }
185 ]
186 proposed:
187 description: The assembled configuration from the user-provided parameters
188 returned: info
189 type: dict
190 sample:
191 {
192 "fvTenant": {
193 "attributes": {
194 "descr": "Production environment",
195 "name": "production"
196 }
197 }
198 }
199 filter_string:
200 description: The filter string used for the request
201 returned: failure or debug
202 type: str
203 sample: ?rsp-prop-include=config-only
204 method:
205 description: The HTTP method used for the request to the APIC
206 returned: failure or debug
207 type: str
208 sample: POST
209 response:
210 description: The HTTP response from the APIC
211 returned: failure or debug
212 type: str
213 sample: OK (30 bytes)
214 status:
215 description: The HTTP status from the APIC
216 returned: failure or debug
217 type: int
218 sample: 200
219 url:
220 description: The HTTP url used for the request to the APIC
221 returned: failure or debug
222 type: str
223 sample: https://10.11.12.13/api/mo/uni/tn-production.json
224 """
225
226 from ansible.module_utils.basic import AnsibleModule
227 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
228
229
230 def main():
231 argument_spec = aci_argument_spec()
232 argument_spec.update(aci_annotation_spec())
233 argument_spec.update(aci_owner_spec())
234 argument_spec.update(
235 name=dict(type="str", aliases=["ntp_policy"]),
236 description=dict(type="str"),
237 admin_state=dict(type="str", choices=["disabled", "enabled"]),
238 server_state=dict(type="str", choices=["disabled", "enabled"]),
239 auth_state=dict(type="str", choices=["disabled", "enabled"]),
240 master_mode=dict(type="str", choices=["disabled", "enabled"]),
241 stratum=dict(type="int"),
242 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
243 )
244
245 module = AnsibleModule(
246 argument_spec=argument_spec,
247 supports_check_mode=True,
248 required_if=[
249 ["state", "absent", ["name"]],
250 ["state", "present", ["name"]],
251 ],
252 )
253
254 name = module.params.get("name")
255 description = module.params.get("description")
256 admin_state = module.params.get("admin_state")
257 server_state = module.params.get("server_state")
258 auth_state = module.params.get("auth_state")
259 master_mode = module.params.get("master_mode")
260 stratum = module.params.get("stratum")
261 state = module.params.get("state")
262 child_classes = ["datetimeNtpProv"]
263
264 aci = ACIModule(module)
265 aci.construct_url(
266 root_class=dict(
267 aci_class="datetimePol",
268 aci_rn="fabric/time-{0}".format(name),
269 module_object=name,
270 target_filter={"name": name},
271 ),
272 child_classes=child_classes,
273 )
274
275 aci.get_existing()
276
277 if state == "present":
278 aci.payload(
279 aci_class="datetimePol",
280 class_config=dict(
281 name=name,
282 descr=description,
283 adminSt=admin_state,
284 serverState=server_state,
285 authSt=auth_state,
286 masterMode=master_mode,
287 StratumValue=stratum,
288 ),
289 )
290
291 aci.get_diff(aci_class="datetimePol")
292
293 aci.post_config()
294
295 elif state == "absent":
296 aci.delete_config()
297
298 aci.exit_json()
299
300
301 if __name__ == "__main__":
302 main()