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_switch_policy_vpc_protection_group.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2017, Bruno Calogero <brunocalogero@hotmail.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_switch_policy_vpc_protection_group
17short_description: Manage switch policy explicit vPC protection groups (fabric:ExplicitGEp, fabric:NodePEp).
18description:
19- Manage switch policy explicit vPC protection groups on Cisco ACI fabrics.
20version_added: '2.5'
21options:
22 protection_group:
23 description:
24 - The name of the Explicit vPC Protection Group.
25 type: str
26 required: yes
27 aliases: [ name, protection_group_name ]
28 protection_group_id:
29 description:
30 - The Explicit vPC Protection Group ID.
31 type: int
32 required: yes
33 aliases: [ id ]
34 vpc_domain_policy:
35 description:
36 - The vPC domain policy to be associated with the Explicit vPC Protection Group.
37 type: str
38 aliases: [ vpc_domain_policy_name ]
39 switch_1_id:
40 description:
41 - The ID of the first Leaf Switch for the Explicit vPC Protection Group.
42 type: int
43 required: yes
44 switch_2_id:
45 description:
46 - The ID of the Second Leaf Switch for the Explicit vPC Protection Group.
47 type: int
48 required: yes
49 state:
50 description:
51 - Use C(present) or C(absent) for adding or removing.
52 - Use C(query) for listing an object or multiple objects.
53 type: str
54 choices: [ absent, present, query ]
55 default: present
56extends_documentation_fragment: aci
57seealso:
58- module: aci_switch_policy_leaf_profile
59- name: APIC Management Information Model reference
60 description: More information about the internal APIC classes B(fabric:ExplicitGEp) and B(fabric:NodePEp).
61 link: https://developer.cisco.com/docs/apic-mim-ref/
62author:
63- Bruno Calogero (@brunocalogero)
64'''
65
66EXAMPLES = r'''
67- name: Add vPC Protection Group
68 aci_switch_policy_vpc_protection_group:
69 host: apic
70 username: admin
71 password: SomeSecretPassword
72 protection_group: leafPair101-vpcGrp
73 protection_group_id: 6
74 switch_1_id: 1011
75 switch_2_id: 1012
76 state: present
77 delegate_to: localhost
78
79- name: Remove Explicit vPC Protection Group
80 aci_switch_policy_vpc_protection_group:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 protection_group: leafPair101-vpcGrp
85 state: absent
86 delegate_to: localhost
87
88- name: Query vPC Protection Groups
89 aci_switch_policy_vpc_protection_group:
90 host: apic
91 username: admin
92 password: SomeSecretPassword
93 state: query
94 delegate_to: localhost
95 register: query_result
96
97- name: Query our vPC Protection Group
98 aci_switch_policy_vpc_protection_group:
99 host: apic
100 username: admin
101 password: SomeSecretPassword
102 protection_group: leafPair101-vpcGrp
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
213from ansible.module_utils.basic import AnsibleModule
214from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
215
216
217def main():
218 argument_spec = aci_argument_spec()
219 argument_spec.update(
220 protection_group=dict(type='str', aliases=['name', 'protection_group_name']), # Not required for querying all objects
221 protection_group_id=dict(type='int', aliases=['id']),
222 vpc_domain_policy=dict(type='str', aliases=['vpc_domain_policy_name']),
223 switch_1_id=dict(type='int'),
224 switch_2_id=dict(type='int'),
225 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
226 )
227
228 module = AnsibleModule(
229 argument_spec=argument_spec,
230 supports_check_mode=True,
231 required_if=[
232 ['state', 'absent', ['protection_group']],
233 ['state', 'present', ['protection_group', 'protection_group_id', 'switch_1_id', 'switch_2_id']],
234 ],
235 )
236
237 protection_group = module.params['protection_group']
238 protection_group_id = module.params['protection_group_id']
239 vpc_domain_policy = module.params['vpc_domain_policy']
240 switch_1_id = module.params['switch_1_id']
241 switch_2_id = module.params['switch_2_id']
242 state = module.params['state']
243
244 aci = ACIModule(module)
245 aci.construct_url(
246 root_class=dict(
247 aci_class='fabricExplicitGEp',
248 aci_rn='fabric/protpol/expgep-{0}'.format(protection_group),
249 module_object=protection_group,
250 target_filter={'name': protection_group},
251 ),
252 child_classes=['fabricNodePEp', 'fabricNodePEp', 'fabricRsVpcInstPol'],
253 )
254
255 aci.get_existing()
256
257 if state == 'present':
258 aci.payload(
259 aci_class='fabricExplicitGEp',
260 class_config=dict(
261 name=protection_group,
262 id=protection_group_id,
263 ),
264 child_configs=[
265 dict(
266 fabricNodePEp=dict(
267 attributes=dict(
268 id='{0}'.format(switch_1_id),
269 ),
270 ),
271 ),
272 dict(
273 fabricNodePEp=dict(
274 attributes=dict(
275 id='{0}'.format(switch_2_id),
276 ),
277 ),
278 ),
279 dict(
280 fabricRsVpcInstPol=dict(
281 attributes=dict(
282 tnVpcInstPolName=vpc_domain_policy,
283 ),
284 ),
285 ),
286 ],
287 )
288
289 aci.get_diff(aci_class='fabricExplicitGEp')
290
291 aci.post_config()
292
293 elif state == 'absent':
294 aci.delete_config()
295
296 aci.exit_json()
297
298
299if __name__ == "__main__":
300 main()