Debian Codegraph @

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