Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_fabric_leaf_switch_assoc.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": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_fabric_leaf_switch_assoc
15 short_description: Manage leaf switch bindings to profiles and policy groups (fabric:LeafS and fabric:RsLeNodePGrp).
16 description:
17 - Manage fabric leaf switch associations (fabric:LeafS) to an existing fabric
18 leaf profile (fabric:leafP) in an ACI fabric, and bind them to a
19 policy group (fabric:RsLeNodePGrp)
20 options:
21 profile:
22 description:
23 - Name of an existing fabric leaf switch profile
24 type: str
25 aliases: [ leaf_profile, leaf_switch_profile ]
26 name:
27 description:
28 - Name of the switch association
29 type: str
30 aliases: [ association_name, switch_association ]
31 policy_group:
32 description:
33 - Name of an existing leaf switch policy group
34 type: str
35 description:
36 description:
37 - Description of the Fabric Switch Association
38 type: str
39 aliases: [ descr ]
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 notes:
53 - The C(profile) must exist before using this module in your playbook.
54 The M(cisco.aci.aci_fabric_leaf_profile) module can be used for this.
55 seealso:
56 - name: APIC Management Information Model reference
57 description: More information about the internal APIC classes B(fabricLeafS) and B(fabricRsLeNodePGrp).
58 link: https://developer.cisco.com/docs/apic-mim-ref/
59 author:
60 - Tim Cragg (@timcragg)
61 """
62
63 EXAMPLES = r"""
64 - name: Create a leaf switch profile association
65 cisco.aci.aci_fabric_leaf_switch_assoc:
66 host: apic
67 username: admin
68 password: SomeSecretPassword
69 profile: my_leaf_profile
70 name: my_leaf_switch_assoc
71 policy_group: my_leaf_pol_grp
72 state: present
73 delegate_to: localhost
74 - name: Remove a leaf switch profile association
75 cisco.aci.aci_fabric_leaf_switch_assoc:
76 host: apic
77 username: admin
78 password: SomeSecretPassword
79 profile: my_leaf_profile
80 name: my_leaf_switch_assoc
81 state: absent
82 delegate_to: localhost
83 - name: Query a leaf profile association
84 cisco.aci.aci_fabric_leaf_switch_assoc:
85 host: apic
86 username: admin
87 password: SomeSecretPassword
88 profile: my_leaf_profile
89 name: my_leaf_switch_assoc
90 state: query
91 delegate_to: localhost
92 register: query_result
93 - name: Query all leaf profiles
94 cisco.aci.aci_fabric_leaf_switch_assoc:
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_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
210 from ansible.module_utils.basic import AnsibleModule
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(
218 profile=dict(type="str", aliases=["leaf_profile", "leaf_switch_profile"]),
219 name=dict(type="str", aliases=["association_name", "switch_association"]),
220 policy_group=dict(type="str"),
221 description=dict(type="str", aliases=["descr"]),
222 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
223 )
224
225 module = AnsibleModule(
226 argument_spec=argument_spec,
227 supports_check_mode=True,
228 required_if=[
229 ["state", "absent", ["profile", "name"]],
230 ["state", "present", ["profile", "name"]],
231 ],
232 )
233
234 aci = ACIModule(module)
235
236 profile = module.params.get("profile")
237 name = module.params.get("name")
238 policy_group = module.params.get("policy_group")
239 description = module.params.get("description")
240 state = module.params.get("state")
241 child_classes = ["fabricRsLeNodePGrp", "fabricNodeBlk"]
242
243 aci.construct_url(
244 root_class=dict(
245 aci_class="fabricLeafP",
246 aci_rn="fabric/leprof-{0}".format(profile),
247 module_object=profile,
248 target_filter={"name": profile},
249 ),
250 subclass_1=dict(
251 aci_class="fabricLeafS",
252 aci_rn="leaves-{0}-typ-range".format(name),
253 module_object=name,
254 target_filter={"name": name},
255 ),
256 child_classes=child_classes,
257 )
258
259 aci.get_existing()
260
261 if state == "present":
262 child_configs = []
263 if policy_group:
264 tDn = "uni/fabric/funcprof/lenodepgrp-{0}".format(policy_group)
265 child_configs.append(dict(fabricRsLeNodePGrp=dict(attributes=dict(tDn=tDn))))
266 aci.payload(
267 aci_class="fabricLeafS",
268 class_config=dict(name=name, descr=description),
269 child_configs=child_configs,
270 )
271
272 aci.get_diff(aci_class="fabricLeafS")
273
274 aci.post_config()
275
276 elif state == "absent":
277 aci.delete_config()
278
279 aci.exit_json()
280
281
282 if __name__ == "__main__":
283 main()