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_policy.py
Go to the documentation of this file.
1#!/usr/bin/python
2
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6from __future__ import absolute_import, division, print_function
7__metaclass__ = type
8
9
10ANSIBLE_METADATA = {
11 'metadata_version': '1.1',
12 'status': ['preview'],
13 'supported_by': 'community'
14}
15
16DOCUMENTATION = '''
17---
18module: aci_firmware_policy
19
20short_description: This creates a firmware policy
21
22version_added: "2.8"
23
24description:
25 - This module creates a firmware policy for firmware groups. The firmware policy is create first and then
26 - referenced by the firmware group. You will assign the firmware and specify if you want to ignore the compatibility
27 - check
28options:
29 name:
30 description:
31 - Name of the firmware policy
32 required: true
33 version:
34 description:
35 - The version of the firmware associated with this policy. This value is very import as well as constructing
36 - it correctly. The syntax for this field is n9000-xx.x. If you look at the firmware repository using the UI
37 - each version will have a "Full Version" column, this is the value you need to use. So, if the Full Version
38 - is 13.1(1i), the value for this field would be n9000-13.1(1i)
39 required: true
40 ignoreCompat:
41 description:
42 - Check if compatibility checks should be ignored
43 required: false
44 state:
45 description:
46 - Use C(present) or C(absent) for adding or removing.
47 - Use C(query) for listing an object or multiple objects.
48 default: present
49 choices: ['absent', 'present', 'query']
50
51extends_documentation_fragment:
52 - aci
53
54author:
55 - Steven Gerhart (@sgerhart)
56'''
57
58EXAMPLES = '''
59 - name: firmware policy
60 aci_firmware_policy:
61 host: "{{ inventory_hostname }}"
62 username: "{{ user }}"
63 password: "{{ pass }}"
64 validate_certs: no
65 name: test2FrmPol
66 version: n9000-13.2(1m)
67 ignoreCompat: False
68 state: present
69
70'''
71
72RETURN = '''
73current:
74 description: The existing configuration from the APIC after the module has finished
75 returned: success
76 type: list
77 sample:
78 [
79 {
80 "fvTenant": {
81 "attributes": {
82 "descr": "Production environment",
83 "dn": "uni/tn-production",
84 "name": "production",
85 "nameAlias": "",
86 "ownerKey": "",
87 "ownerTag": ""
88 }
89 }
90 }
91 ]
92error:
93 description: The error information as returned from the APIC
94 returned: failure
95 type: dict
96 sample:
97 {
98 "code": "122",
99 "text": "unknown managed object class foo"
100 }
101raw:
102 description: The raw output returned by the APIC REST API (xml or json)
103 returned: parse error
104 type: str
105 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
106sent:
107 description: The actual/minimal configuration pushed to the APIC
108 returned: info
109 type: list
110 sample:
111 {
112 "fvTenant": {
113 "attributes": {
114 "descr": "Production environment"
115 }
116 }
117 }
118previous:
119 description: The original configuration from the APIC before the module has started
120 returned: info
121 type: list
122 sample:
123 [
124 {
125 "fvTenant": {
126 "attributes": {
127 "descr": "Production",
128 "dn": "uni/tn-production",
129 "name": "production",
130 "nameAlias": "",
131 "ownerKey": "",
132 "ownerTag": ""
133 }
134 }
135 }
136 ]
137proposed:
138 description: The assembled configuration from the user-provided parameters
139 returned: info
140 type: dict
141 sample:
142 {
143 "fvTenant": {
144 "attributes": {
145 "descr": "Production environment",
146 "name": "production"
147 }
148 }
149 }
150filter_string:
151 description: The filter string used for the request
152 returned: failure or debug
153 type: str
154 sample: ?rsp-prop-include=config-only
155method:
156 description: The HTTP method used for the request to the APIC
157 returned: failure or debug
158 type: str
159 sample: POST
160response:
161 description: The HTTP response from the APIC
162 returned: failure or debug
163 type: str
164 sample: OK (30 bytes)
165status:
166 description: The HTTP status from the APIC
167 returned: failure or debug
168 type: int
169 sample: 200
170url:
171 description: The HTTP url used for the request to the APIC
172 returned: failure or debug
173 type: str
174 sample: https://10.11.12.13/api/mo/uni/tn-production.json
175'''
176
177
178from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
179from ansible.module_utils.basic import AnsibleModule
180
181
182def main():
183 argument_spec = aci_argument_spec()
184 argument_spec.update(
185 name=dict(type='str', aliases=['name']), # Not required for querying all objects
186 version=dict(type='str', aliases=['version']),
187 ignoreCompat=dict(type=bool),
188 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
189 )
190
191 module = AnsibleModule(
192 argument_spec=argument_spec,
193 supports_check_mode=True,
194 required_if=[
195 ['state', 'absent', ['name']],
196 ['state', 'present', ['name', 'version']],
197 ],
198 )
199
200 state = module.params['state']
201 name = module.params['name']
202 version = module.params['version']
203
204 if module.params['ignoreCompat']:
205 ignore = 'yes'
206 else:
207 ignore = 'no'
208
209 aci = ACIModule(module)
210 aci.construct_url(
211 root_class=dict(
212 aci_class='firmwareFwP',
213 aci_rn='fabric/fwpol-{0}'.format(name),
214 target_filter={'name': name},
215 module_object=name,
216 ),
217
218
219 )
220
221 aci.get_existing()
222
223 if state == 'present':
224 aci.payload(
225 aci_class='firmwareFwP',
226 class_config=dict(
227 name=name,
228 version=version,
229 ignoreCompat=ignore,
230 ),
231
232 )
233
234 aci.get_diff(aci_class='firmwareFwP')
235
236 aci.post_config()
237
238 elif state == 'absent':
239 aci.delete_config()
240
241 aci.exit_json()
242
243
244if __name__ == "__main__":
245 main()