Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Dag Wieers (dagwieers) <[email protected]>
5 # Copyright: (c) 2020, Cindy Zhao (cizhao) <[email protected]>
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_firmware_source
17 short_description: Manage firmware image sources (firmware:OSource)
18 description:
19 - Manage firmware image sources on Cisco ACI fabrics.
20 options:
21 source:
22 description:
23 - The identifying name for the outside source of images, such as an HTTP or SCP server.
24 type: str
25 aliases: [ name, source_name ]
26 polling_interval:
27 description:
28 - Polling interval in minutes.
29 type: int
30 url_protocol:
31 description:
32 - The Firmware download protocol.
33 type: str
34 choices: [ http, local, scp, usbkey ]
35 default: scp
36 aliases: [ url_proto ]
37 url:
38 description:
39 The firmware URL for the image(s) on the source.
40 type: str
41 url_password:
42 description:
43 - The Firmware password or key string.
44 - Providing this option will always result in a change because it is a secure property that cannot be retrieved from APIC.
45 type: str
46 url_username:
47 description:
48 The username for the source.
49 type: str
50 state:
51 description:
52 - Use C(present) or C(absent) for adding or removing.
53 - Use C(query) for listing an object or multiple objects.
54 type: str
55 choices: [ absent, present, query ]
56 default: present
57 name_alias:
58 description:
59 - The alias for the current object. This relates to the nameAlias field in ACI.
60 type: str
61 extends_documentation_fragment:
62 - cisco.aci.aci
63 - cisco.aci.annotation
64
65 seealso:
66 - name: APIC Management Information Model reference
67 description: More information about the internal APIC class B(firmware:OSource).
68 link: https://developer.cisco.com/docs/apic-mim-ref/
69 author:
70 - Dag Wieers (@dagwieers)
71 """
72
73 EXAMPLES = r"""
74 - name: Add firmware source
75 cisco.aci.aci_firmware_source:
76 host: apic
77 username: admin
78 password: SomeSecretPassword
79 source: aci-msft-pkg-3.1.1i.zip
80 url: foo.bar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip
81 url_protocol: http
82 state: present
83 delegate_to: localhost
84
85 - name: Remove firmware source
86 cisco.aci.aci_firmware_source:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 source: aci-msft-pkg-3.1.1i.zip
91 state: absent
92 delegate_to: localhost
93
94 - name: Query a specific firmware source
95 cisco.aci.aci_firmware_source:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 source: aci-msft-pkg-3.1.1i.zip
100 state: query
101 delegate_to: localhost
102 register: query_result
103
104 - name: Query all firmware sources
105 cisco.aci.aci_firmware_source:
106 host: apic
107 username: admin
108 password: SomeSecretPassword
109 state: query
110 delegate_to: localhost
111 register: query_result
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
220 from ansible.module_utils.basic import AnsibleModule
221 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
222
223
224 def main():
225 argument_spec = aci_argument_spec()
226 argument_spec.update(aci_annotation_spec())
227 argument_spec.update(
228 source=dict(type="str", aliases=["name", "source_name"]), # Not required for querying all objects
229 polling_interval=dict(type="int"),
230 url=dict(type="str"),
231 url_username=dict(type="str"),
232 url_password=dict(type="str", no_log=True),
233 url_protocol=dict(type="str", default="scp", choices=["http", "local", "scp", "usbkey"], aliases=["url_proto"]),
234 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
235 name_alias=dict(type="str"),
236 )
237
238 module = AnsibleModule(
239 argument_spec=argument_spec,
240 supports_check_mode=True,
241 required_if=[
242 ["state", "absent", ["source"]],
243 ["state", "present", ["url_protocol", "source", "url"]],
244 ],
245 )
246
247 polling_interval = module.params.get("polling_interval")
248 url_protocol = module.params.get("url_protocol")
249 state = module.params.get("state")
250 source = module.params.get("source")
251 url = module.params.get("url")
252 url_password = module.params.get("url_password")
253 url_username = module.params.get("url_username")
254 name_alias = module.params.get("name_alias")
255
256 aci = ACIModule(module)
257 aci.construct_url(
258 root_class=dict(
259 aci_class="fabricInst",
260 aci_rn="fabric",
261 module_object="fabric",
262 target_filter={"name": "fabric"},
263 ),
264 subclass_1=dict(
265 aci_class="firmwareRepoP",
266 aci_rn="fwrepop",
267 module_object="fwrepop",
268 target_filter={"name": "fwrepop"},
269 ),
270 subclass_2=dict(
271 aci_class="firmwareOSource",
272 aci_rn="osrc-{0}".format(source),
273 module_object=source,
274 target_filter={"name": source},
275 ),
276 config_only=False,
277 )
278 aci.get_existing()
279
280 if state == "present":
281 aci.payload(
282 aci_class="firmwareOSource",
283 class_config=dict(
284 name=source,
285 url=url,
286 password=url_password,
287 pollingInterval=polling_interval,
288 proto=url_protocol,
289 user=url_username,
290 nameAlias=name_alias,
291 ),
292 )
293
294 aci.get_diff(aci_class="firmwareOSource")
295
296 aci.post_config()
297
298 elif state == "absent":
299 aci.delete_config()
300
301 aci.exit_json()
302
303
304 if __name__ == "__main__":
305 main()