Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_l2out_logical_interface_profile
15 short_description: Manage Layer 2 Outside (L2Out) interface profiles (l2ext:LIfP)
16 description:
17 - Manage interface profiles of L2 outside (BD extension) on Cisco ACI fabrics.
18 options:
19 tenant:
20 description:
21 - Name of an existing tenant.
22 type: str
23 aliases: [ tenant_name ]
24 l2out:
25 description:
26 - Name of an existing L2Out.
27 type: str
28 aliases: [ l2out_name ]
29 node_profile:
30 description:
31 - Name of the node profile.
32 type: str
33 default: default
34 aliases: [ node_profile_name, logical_node ]
35 interface_profile:
36 description:
37 - Name of the interface profile.
38 type: str
39 aliases: [ name, interface_profile_name, logical_interface ]
40 state:
41 description:
42 - Use C(present) or C(absent) for adding or removing.
43 - Use C(query) for listing an object or multiple objects.
44 type: str
45 choices: [ absent, present, query ]
46 default: present
47 extends_documentation_fragment:
48 - cisco.aci.aci
49 - cisco.aci.annotation
50 - cisco.aci.owner
51
52 seealso:
53 - module: cisco.aci.aci_l2out
54 - module: cisco.aci.aci_l2out_logical_node_profile
55 - module: cisco.aci.aci_l2out_logical_interface_path
56 - module: cisco.aci.aci_l2out_extepg
57 - name: APIC Management Information Model reference
58 description: More information about the internal APIC class B(l2ext:LIfP).
59 link: https://developer.cisco.com/docs/apic-mim-ref/
60 author:
61 - Oleksandr Kreshchenko (@alexkross)
62 """
63
64 EXAMPLES = r"""
65 - name: Add new interface profile
66 cisco.aci.aci_l2out_logical_interface_profile:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 tenant: my_tenant
71 l2out: my_l2out
72 node_profile: my_node_profile
73 interface_profile: my_interface_profile
74 state: present
75 delegate_to: localhost
76
77 - name: Delete interface profile
78 cisco.aci.aci_l2out_logical_interface_profile:
79 host: apic
80 username: admin
81 password: SomeSecretPassword
82 tenant: my_tenant
83 l2out: my_l2out
84 node_profile: my_node_profile
85 interface_profile: my_interface_profile
86 state: absent
87 delegate_to: localhost
88
89 - name: Query an interface profile
90 cisco.aci.aci_l2out_logical_interface_profile:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 tenant: my_tenant
95 l2out: my_l2out
96 node_profile: my_node_profile
97 interface_profile: my_interface_profile
98 state: query
99 delegate_to: localhost
100 register: query_result
101
102 - name: Query all interface profiles
103 cisco.aci.aci_l2out_logical_interface_profile:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 state: query
108 delegate_to: localhost
109 register: query_result
110 """
111
112 RETURN = r"""
113 current:
114 description: The existing configuration from the APIC after the module has finished
115 returned: success
116 type: list
117 sample:
118 [
119 {
120 "fvTenant": {
121 "attributes": {
122 "descr": "Production environment",
123 "dn": "uni/tn-production",
124 "name": "production",
125 "nameAlias": "",
126 "ownerKey": "",
127 "ownerTag": ""
128 }
129 }
130 }
131 ]
132 error:
133 description: The error information as returned from the APIC
134 returned: failure
135 type: dict
136 sample:
137 {
138 "code": "122",
139 "text": "unknown managed object class foo"
140 }
141 raw:
142 description: The raw output returned by the APIC REST API (xml or json)
143 returned: parse error
144 type: str
145 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
146 sent:
147 description: The actual/minimal configuration pushed to the APIC
148 returned: info
149 type: list
150 sample:
151 {
152 "fvTenant": {
153 "attributes": {
154 "descr": "Production environment"
155 }
156 }
157 }
158 previous:
159 description: The original configuration from the APIC before the module has started
160 returned: info
161 type: list
162 sample:
163 [
164 {
165 "fvTenant": {
166 "attributes": {
167 "descr": "Production",
168 "dn": "uni/tn-production",
169 "name": "production",
170 "nameAlias": "",
171 "ownerKey": "",
172 "ownerTag": ""
173 }
174 }
175 }
176 ]
177 proposed:
178 description: The assembled configuration from the user-provided parameters
179 returned: info
180 type: dict
181 sample:
182 {
183 "fvTenant": {
184 "attributes": {
185 "descr": "Production environment",
186 "name": "production"
187 }
188 }
189 }
190 filter_string:
191 description: The filter string used for the request
192 returned: failure or debug
193 type: str
194 sample: ?rsp-prop-include=config-only
195 method:
196 description: The HTTP method used for the request to the APIC
197 returned: failure or debug
198 type: str
199 sample: POST
200 response:
201 description: The HTTP response from the APIC
202 returned: failure or debug
203 type: str
204 sample: OK (30 bytes)
205 status:
206 description: The HTTP status from the APIC
207 returned: failure or debug
208 type: int
209 sample: 200
210 url:
211 description: The HTTP url used for the request to the APIC
212 returned: failure or debug
213 type: str
214 sample: https://10.11.12.13/api/mo/uni/tn-production.json
215 """
216
217
218 from ansible.module_utils.basic import AnsibleModule
219 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
220
221
222 def main():
223 argument_spec = aci_argument_spec()
224 argument_spec.update(aci_annotation_spec())
225 argument_spec.update(aci_owner_spec())
226 argument_spec.update( # See comments in aci_static_binding_to_epg module.
227 tenant=dict(type="str", aliases=["tenant_name"]),
228 l2out=dict(type="str", aliases=["l2out_name"]),
229 node_profile=dict(type="str", default="default", aliases=["node_profile_name", "logical_node"]),
230 interface_profile=dict(type="str", aliases=["name", "interface_profile_name", "logical_interface"]),
231 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
232 )
233
234 module = AnsibleModule(
235 argument_spec=argument_spec,
236 supports_check_mode=True,
237 required_if=[
238 ["state", "absent", ["tenant", "l2out", "node_profile", "interface_profile"]],
239 ["state", "present", ["tenant", "l2out", "node_profile", "interface_profile"]],
240 ],
241 )
242
243 tenant = module.params.get("tenant")
244 l2out = module.params.get("l2out")
245 node_profile = module.params.get("node_profile")
246 interface_profile = module.params.get("interface_profile")
247 state = module.params.get("state")
248
249 aci = ACIModule(module)
250
251 aci.construct_url(
252 root_class=dict(
253 aci_class="fvTenant",
254 aci_rn="tn-{0}".format(tenant),
255 module_object=tenant,
256 target_filter={"name": tenant},
257 ),
258 subclass_1=dict(
259 aci_class="l2extOut",
260 aci_rn="l2out-{0}".format(l2out),
261 module_object=l2out,
262 target_filter={"name": l2out},
263 ),
264 subclass_2=dict(
265 aci_class="l2extLNodeP",
266 aci_rn="lnodep-{0}".format(node_profile),
267 module_object=node_profile,
268 target_filter={"name": node_profile},
269 ),
270 subclass_3=dict(
271 aci_class="l2extLIfP",
272 aci_rn="lifp-{0}".format(interface_profile),
273 module_object=interface_profile,
274 target_filter={"name": interface_profile},
275 ),
276 )
277
278 aci.get_existing()
279
280 if state == "present":
281 # child_configs = []
282 aci.payload(
283 aci_class="l2extLIfP",
284 class_config=dict(name=interface_profile),
285 # child_configs=child_configs
286 )
287
288 aci.get_diff(aci_class="l2extLIfP")
289
290 aci.post_config()
291
292 elif state == "absent":
293 aci.delete_config()
294
295 aci.exit_json()
296
297
298 if __name__ == "__main__":
299 main()