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_bd_to_l3out.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
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
9ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13DOCUMENTATION = r'''
14---
15module: aci_bd_to_l3out
16short_description: Bind Bridge Domain to L3 Out (fv:RsBDToOut)
17description:
18- Bind Bridge Domain to L3 Out on Cisco ACI fabrics.
19version_added: '2.4'
20options:
21 bd:
22 description:
23 - The name of the Bridge Domain.
24 type: str
25 aliases: [ bd_name, bridge_domain ]
26 l3out:
27 description:
28 - The name of the l3out to associate with th Bridge Domain.
29 type: str
30 tenant:
31 description:
32 - The name of the Tenant.
33 type: str
34 aliases: [ tenant_name ]
35 state:
36 description:
37 - Use C(present) or C(absent) for adding or removing.
38 - Use C(query) for listing an object or multiple objects.
39 type: str
40 choices: [ absent, present, query ]
41 default: present
42extends_documentation_fragment: aci
43notes:
44- The C(bd) and C(l3out) parameters should exist before using this module.
45 The M(aci_bd) and C(aci_l3out) can be used for these.
46seealso:
47- module: aci_bd
48- module: aci_l3out
49- name: APIC Management Information Model reference
50 description: More information about the internal APIC class B(fv:RsBDToOut).
51 link: https://developer.cisco.com/docs/apic-mim-ref/
52author:
53- Jacob McGill (@jmcgill298)
54'''
55
56EXAMPLES = r''' # '''
57
58RETURN = r'''
59current:
60 description: The existing configuration from the APIC after the module has finished
61 returned: success
62 type: list
63 sample:
64 [
65 {
66 "fvTenant": {
67 "attributes": {
68 "descr": "Production environment",
69 "dn": "uni/tn-production",
70 "name": "production",
71 "nameAlias": "",
72 "ownerKey": "",
73 "ownerTag": ""
74 }
75 }
76 }
77 ]
78error:
79 description: The error information as returned from the APIC
80 returned: failure
81 type: dict
82 sample:
83 {
84 "code": "122",
85 "text": "unknown managed object class foo"
86 }
87raw:
88 description: The raw output returned by the APIC REST API (xml or json)
89 returned: parse error
90 type: str
91 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
92sent:
93 description: The actual/minimal configuration pushed to the APIC
94 returned: info
95 type: list
96 sample:
97 {
98 "fvTenant": {
99 "attributes": {
100 "descr": "Production environment"
101 }
102 }
103 }
104previous:
105 description: The original configuration from the APIC before the module has started
106 returned: info
107 type: list
108 sample:
109 [
110 {
111 "fvTenant": {
112 "attributes": {
113 "descr": "Production",
114 "dn": "uni/tn-production",
115 "name": "production",
116 "nameAlias": "",
117 "ownerKey": "",
118 "ownerTag": ""
119 }
120 }
121 }
122 ]
123proposed:
124 description: The assembled configuration from the user-provided parameters
125 returned: info
126 type: dict
127 sample:
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production environment",
132 "name": "production"
133 }
134 }
135 }
136filter_string:
137 description: The filter string used for the request
138 returned: failure or debug
139 type: str
140 sample: ?rsp-prop-include=config-only
141method:
142 description: The HTTP method used for the request to the APIC
143 returned: failure or debug
144 type: str
145 sample: POST
146response:
147 description: The HTTP response from the APIC
148 returned: failure or debug
149 type: str
150 sample: OK (30 bytes)
151status:
152 description: The HTTP status from the APIC
153 returned: failure or debug
154 type: int
155 sample: 200
156url:
157 description: The HTTP url used for the request to the APIC
158 returned: failure or debug
159 type: str
160 sample: https://10.11.12.13/api/mo/uni/tn-production.json
161'''
162
163from ansible.module_utils.basic import AnsibleModule
164from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
165
166SUBNET_CONTROL_MAPPING = dict(
167 nd_ra='nd',
168 no_gw='no-default-gateway',
169 querier_ip='querier',
170 unspecified='',
171)
172
173
174def main():
175 argument_spec = aci_argument_spec()
176 argument_spec.update(
177 bd=dict(type='str', aliases=['bd_name', 'bridge_domain']), # Not required for querying all objects
178 l3out=dict(type='str'), # Not required for querying all objects
179 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
180 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
181 )
182
183 module = AnsibleModule(
184 argument_spec=argument_spec,
185 supports_check_mode=True,
186 required_together=[['gateway', 'mask']],
187 required_if=[
188 ['state', 'present', ['bd', 'l3out', 'tenant']],
189 ['state', 'absent', ['bd', 'l3out', 'tenant']],
190 ],
191 )
192
193 bd = module.params['bd']
194 l3out = module.params['l3out']
195 state = module.params['state']
196 tenant = module.params['tenant']
197
198 aci = ACIModule(module)
199 aci.construct_url(
200 root_class=dict(
201 aci_class='fvTenant',
202 aci_rn='tn-{0}'.format(tenant),
203 module_object=tenant,
204 target_filter={'name': tenant},
205 ),
206 subclass_1=dict(
207 aci_class='fvBD',
208 aci_rn='BD-{0}'.format(bd),
209 module_object=bd,
210 target_filter={'name': bd},
211 ),
212 subclass_2=dict(
213 aci_class='fvRsBDToOut',
214 aci_rn='rsBDToOut-{0}'.format(l3out),
215 module_object=l3out,
216 target_filter={'tnL3extOutName': l3out},
217 ),
218 )
219
220 aci.get_existing()
221
222 if state == 'present':
223 aci.payload(
224 aci_class='fvRsBDToOut',
225 class_config=dict(tnL3extOutName=l3out),
226 )
227
228 aci.get_diff(aci_class='fvRsBDToOut')
229
230 aci.post_config()
231
232 elif state == 'absent':
233 aci.delete_config()
234
235 aci.exit_json()
236
237
238if __name__ == "__main__":
239 main()