ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_firmware_source.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2018, Dag Wieers (dagwieers) <dag@wieers.com>
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import absolute_import, division, print_function
8__metaclass__ = type
9
10ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'certified'}
13
14DOCUMENTATION = r'''
15---
16module: aci_firmware_source
17short_description: Manage firmware image sources (firmware:OSource)
18description:
19- Manage firmware image sources on Cisco ACI fabrics.
20version_added: '2.5'
21options:
22 source:
23 description:
24 - The identifying name for the outside source of images, such as an HTTP or SCP server.
25 type: str
26 required: yes
27 aliases: [ name, source_name ]
28 polling_interval:
29 description:
30 - Polling interval in minutes.
31 type: int
32 url_protocol:
33 description:
34 - The Firmware download protocol.
35 type: str
36 choices: [ http, local, scp, usbkey ]
37 default: scp
38 aliases: [ url_proto ]
39 url:
40 description:
41 The firmware URL for the image(s) on the source.
42 type: str
43 url_password:
44 description:
45 The Firmware password or key string.
46 type: str
47 url_username:
48 description:
49 The username for the source.
50 type: str
51 state:
52 description:
53 - Use C(present) or C(absent) for adding or removing.
54 - Use C(query) for listing an object or multiple objects.
55 type: str
56 choices: [ absent, present, query ]
57 default: present
58extends_documentation_fragment: aci
59seealso:
60- name: APIC Management Information Model reference
61 description: More information about the internal APIC class B(firmware:OSource).
62 link: https://developer.cisco.com/docs/apic-mim-ref/
63author:
64- Dag Wieers (@dagwieers)
65'''
66
67EXAMPLES = r'''
68- name: Add firmware source
69 aci_firmware_source:
70 host: apic
71 username: admin
72 password: SomeSecretPassword
73 source: aci-msft-pkg-3.1.1i.zip
74 url: foo.bar.cisco.com/download/cisco/aci/aci-msft-pkg-3.1.1i.zip
75 url_protocol: http
76 state: present
77 delegate_to: localhost
78
79- name: Remove firmware source
80 aci_firmware_source:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 source: aci-msft-pkg-3.1.1i.zip
85 state: absent
86 delegate_to: localhost
87
88- name: Query a specific firmware source
89 aci_firmware_source:
90 host: apic
91 username: admin
92 password: SomeSecretPassword
93 source: aci-msft-pkg-3.1.1i.zip
94 state: query
95 delegate_to: localhost
96 register: query_result
97
98- name: Query all firmware sources
99 aci_firmware_source:
100 host: apic
101 username: admin
102 password: SomeSecretPassword
103 state: query
104 delegate_to: localhost
105 register: query_result
106'''
107
108RETURN = r'''
109current:
110 description: The existing configuration from the APIC after the module has finished
111 returned: success
112 type: list
113 sample:
114 [
115 {
116 "fvTenant": {
117 "attributes": {
118 "descr": "Production environment",
119 "dn": "uni/tn-production",
120 "name": "production",
121 "nameAlias": "",
122 "ownerKey": "",
123 "ownerTag": ""
124 }
125 }
126 }
127 ]
128error:
129 description: The error information as returned from the APIC
130 returned: failure
131 type: dict
132 sample:
133 {
134 "code": "122",
135 "text": "unknown managed object class foo"
136 }
137raw:
138 description: The raw output returned by the APIC REST API (xml or json)
139 returned: parse error
140 type: str
141 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
142sent:
143 description: The actual/minimal configuration pushed to the APIC
144 returned: info
145 type: list
146 sample:
147 {
148 "fvTenant": {
149 "attributes": {
150 "descr": "Production environment"
151 }
152 }
153 }
154previous:
155 description: The original configuration from the APIC before the module has started
156 returned: info
157 type: list
158 sample:
159 [
160 {
161 "fvTenant": {
162 "attributes": {
163 "descr": "Production",
164 "dn": "uni/tn-production",
165 "name": "production",
166 "nameAlias": "",
167 "ownerKey": "",
168 "ownerTag": ""
169 }
170 }
171 }
172 ]
173proposed:
174 description: The assembled configuration from the user-provided parameters
175 returned: info
176 type: dict
177 sample:
178 {
179 "fvTenant": {
180 "attributes": {
181 "descr": "Production environment",
182 "name": "production"
183 }
184 }
185 }
186filter_string:
187 description: The filter string used for the request
188 returned: failure or debug
189 type: str
190 sample: ?rsp-prop-include=config-only
191method:
192 description: The HTTP method used for the request to the APIC
193 returned: failure or debug
194 type: str
195 sample: POST
196response:
197 description: The HTTP response from the APIC
198 returned: failure or debug
199 type: str
200 sample: OK (30 bytes)
201status:
202 description: The HTTP status from the APIC
203 returned: failure or debug
204 type: int
205 sample: 200
206url:
207 description: The HTTP url used for the request to the APIC
208 returned: failure or debug
209 type: str
210 sample: https://10.11.12.13/api/mo/uni/tn-production.json
211'''
212
213
214from ansible.module_utils.basic import AnsibleModule
215from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
216
217
218def main():
219 argument_spec = aci_argument_spec()
220 argument_spec.update(
221 source=dict(type='str', aliases=['name', 'source_name']), # Not required for querying all objects
222 polling_interval=dict(type='int'),
223 url=dict(type='str'),
224 url_username=dict(type='str'),
225 url_password=dict(type='str', no_log=True),
226 url_protocol=dict(type='str', default='scp', choices=['http', 'local', 'scp', 'usbkey'], aliases=['url_proto']),
227 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
228 )
229
230 module = AnsibleModule(
231 argument_spec=argument_spec,
232 supports_check_mode=True,
233 required_if=[
234 ['state', 'absent', ['source']],
235 ['state', 'present', ['url_protocol', 'source', 'url']],
236 ],
237 )
238
239 polling_interval = module.params['polling_interval']
240 url_protocol = module.params['url_protocol']
241 state = module.params['state']
242 source = module.params['source']
243 url = module.params['url']
244 url_password = module.params['url_password']
245 url_username = module.params['url_username']
246
247 aci = ACIModule(module)
248 aci.construct_url(
249 root_class=dict(
250 aci_class='firmwareOSource',
251 aci_rn='fabric/fwrepop',
252 module_object=source,
253 target_filter={'name': source},
254 ),
255 )
256 aci.get_existing()
257
258 if state == 'present':
259 aci.payload(
260 aci_class='firmwareOSource',
261 class_config=dict(
262 name=source,
263 url=url,
264 password=url_password,
265 pollingInterval=polling_interval,
266 proto=url_protocol,
267 user=url_username,
268 ),
269 )
270
271 aci.get_diff(aci_class='firmwareOSource')
272
273 aci.post_config()
274
275 elif state == 'absent':
276 aci.delete_config()
277
278 aci.exit_json()
279
280
281if __name__ == "__main__":
282 main()