Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Tim Cragg (@timcragg) <[email protected]>
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 = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_config_export_policy
16 short_description: Manage Configuration Export Policy (config:ExportP)
17 description:
18 - Manage Configuration Export Policies on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - The name of the Configuration Export Policy.
23 type: str
24 description:
25 description:
26 - The description of the Configuration Export Policy.
27 type: str
28 format:
29 description:
30 - The format of the export file.
31 - This defaults to json on the APIC when unset on creation.
32 type: str
33 choices: [ json, xml ]
34 target_dn:
35 description:
36 - The distinguished name of the object to be exported.
37 - If no target_dn is included, the APIC will export the policy universe.
38 type: str
39 snapshot:
40 description:
41 - Enables a snapshot of the configuration export policy.
42 - This defaults to False on the APIC when unset on creation.
43 type: bool
44 export_destination:
45 description:
46 - The name of the remote path policy used for storing the generated configuration backup data for the configuration export policy.
47 type: str
48 scheduler:
49 description:
50 - The name of the scheduler policy used for running scheduled export jobs.
51 type: str
52 start_now:
53 description:
54 - Specifies if the configuration export policy should be applied now or at another time.
55 - This defaults to False on the APIC when unset on creation.
56 type: bool
57 state:
58 description:
59 - Use C(present) or C(absent) for adding or removing.
60 - Use C(query) for listing an object or multiple objects.
61 type: str
62 choices: [ absent, present, query ]
63 default: present
64 extends_documentation_fragment:
65 - cisco.aci.aci
66 - cisco.aci.annotation
67
68 seealso:
69 - name: APIC Management Information Model reference
70 description: More information about the internal APIC class B(config:ExportP).
71 link: https://developer.cisco.com/docs/apic-mim-ref/
72
73 author:
74 - Tim Cragg (@timcragg)
75 """
76
77 EXAMPLES = r"""
78 - name: Add a Configuration Export Policy
79 cisco.aci.aci_config_export_policy:
80 host: apic
81 username: admin
82 password: SomeSecretPassword
83 name: ans_conf_export
84 state: present
85 delegate_to: localhost
86
87 - name: Query a Configuration Export Policy
88 cisco.aci.aci_config_export_policy:
89 host: apic
90 username: admin
91 password: SomeSecretPassword
92 name: ans_conf_export
93 state: query
94 delegate_to: localhost
95
96 - name: Query all Configuration Export Policies
97 cisco.aci.aci_config_export_policy:
98 host: apic
99 username: admin
100 password: SomeSecretPassword
101 state: query
102 delegate_to: localhost
103
104 - name: Remove a Configuration Export Policies
105 cisco.aci.aci_file_remote_path:
106 host: apic
107 username: admin
108 password: SomeSecretPassword
109 name: ans_conf_export
110 state: absent
111 delegate_to: localhost
112 """
113
114 RETURN = r"""
115 current:
116 description: The existing configuration from the APIC after the module has finished
117 returned: success
118 type: list
119 sample:
120 [
121 {
122 "fvTenant": {
123 "attributes": {
124 "descr": "Production environment",
125 "dn": "uni/tn-production",
126 "name": "production",
127 "nameAlias": "",
128 "ownerKey": "",
129 "ownerTag": ""
130 }
131 }
132 }
133 ]
134 error:
135 description: The error information as returned from the APIC
136 returned: failure
137 type: dict
138 sample:
139 {
140 "code": "122",
141 "text": "unknown managed object class foo"
142 }
143 raw:
144 description: The raw output returned by the APIC REST API (xml or json)
145 returned: parse error
146 type: str
147 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
148 sent:
149 description: The actual/minimal configuration pushed to the APIC
150 returned: info
151 type: list
152 sample:
153 {
154 "fvTenant": {
155 "attributes": {
156 "descr": "Production environment"
157 }
158 }
159 }
160 previous:
161 description: The original configuration from the APIC before the module has started
162 returned: info
163 type: list
164 sample:
165 [
166 {
167 "fvTenant": {
168 "attributes": {
169 "descr": "Production",
170 "dn": "uni/tn-production",
171 "name": "production",
172 "nameAlias": "",
173 "ownerKey": "",
174 "ownerTag": ""
175 }
176 }
177 }
178 ]
179 proposed:
180 description: The assembled configuration from the user-provided parameters
181 returned: info
182 type: dict
183 sample:
184 {
185 "fvTenant": {
186 "attributes": {
187 "descr": "Production environment",
188 "name": "production"
189 }
190 }
191 }
192 filter_string:
193 description: The filter string used for the request
194 returned: failure or debug
195 type: str
196 sample: ?rsp-prop-include=config-only
197 method:
198 description: The HTTP method used for the request to the APIC
199 returned: failure or debug
200 type: str
201 sample: POST
202 response:
203 description: The HTTP response from the APIC
204 returned: failure or debug
205 type: str
206 sample: OK (30 bytes)
207 status:
208 description: The HTTP status from the APIC
209 returned: failure or debug
210 type: int
211 sample: 200
212 url:
213 description: The HTTP url used for the request to the APIC
214 returned: failure or debug
215 type: str
216 sample: https://10.11.12.13/api/mo/uni/tn-production.json
217 """
218
219 from ansible.module_utils.basic import AnsibleModule
220 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
221
222
223 def main():
224 argument_spec = aci_argument_spec()
225 argument_spec.update(aci_annotation_spec())
226 argument_spec.update(
227 name=dict(type="str"),
228 description=dict(type="str"),
229 format=dict(type="str", choices=["json", "xml"]),
230 target_dn=dict(type="str"),
231 snapshot=dict(type="bool"),
232 export_destination=dict(type="str"),
233 scheduler=dict(type="str"),
234 start_now=dict(type="bool"),
235 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
236 )
237
238 module = AnsibleModule(
239 argument_spec=argument_spec,
240 supports_check_mode=True,
241 required_if=[
242 ["state", "present", ["name"]],
243 ["state", "absent", ["name"]],
244 ],
245 )
246
247 aci = ACIModule(module)
248
249 name = module.params.get("name")
250 description = module.params.get("description")
251 format = module.params.get("format")
252 target_dn = module.params.get("target_dn")
253 snapshot = aci.boolean(module.params.get("snapshot"))
254 export_destination = module.params.get("export_destination")
255 scheduler = module.params.get("scheduler")
256 start_now = aci.boolean(module.params.get("start_now"), "triggered", "untriggered")
257 state = module.params.get("state")
258
259 aci.construct_url(
260 root_class=dict(
261 aci_class="configExportP",
262 aci_rn="fabric/configexp-{0}".format(name),
263 module_object=name,
264 target_filter={"name": name},
265 ),
266 child_classes=["configRsExportScheduler", "configRsRemotePath"],
267 )
268 aci.get_existing()
269
270 if state == "present":
271 child_configs = []
272 if scheduler is not None:
273 child_configs.append(
274 dict(
275 configRsExportScheduler=dict(
276 attributes=dict(tnTrigSchedPName=scheduler),
277 )
278 )
279 )
280 if export_destination is not None:
281 child_configs.append(
282 dict(
283 configRsRemotePath=dict(
284 attributes=dict(tnFileRemotePathName=export_destination),
285 )
286 )
287 )
288 aci.payload(
289 aci_class="configExportP",
290 class_config=dict(
291 name=name,
292 descr=description,
293 format=format,
294 targetDn=target_dn,
295 snapshot=snapshot,
296 adminSt=start_now,
297 ),
298 child_configs=child_configs,
299 )
300
301 aci.get_diff(aci_class="configExportP")
302
303 aci.post_config()
304
305 elif state == "absent":
306 aci.delete_config()
307
308 aci.exit_json()
309
310
311 if __name__ == "__main__":
312 main()