Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_fabric_spine_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_spine_switch_assoc
15 short_description: Manage spine switch bindings to profiles and policy groups (fabric:SpineS and fabric:RsSpNodePGrp)
16 description:
17 - Manage fabric spine switch associations (fabric:SpineS) to an existing fabric
18 spine profile (fabric:SpineP) in an ACI fabric, and bind them to a
19 policy group (fabric:RsSpNodePGrp)
20 options:
21 profile:
22 description:
23 - Name of an existing fabric spine switch profile
24 type: str
25 aliases: [ spine_profile, spine_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 spine 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_spine_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(fabricSpineS) and B(fabricRsSpNodePGrp).
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 spine switch profile association
65 cisco.aci.aci_fabric_spine_switch_assoc:
66 host: apic
67 username: admin
68 password: SomeSecretPassword
69 profile: my_spine_profile
70 name: my_spine_switch_assoc
71 policy_group: my_spine_pol_grp
72 state: present
73 delegate_to: localhost
74
75 - name: Remove a spine switch profile association
76 cisco.aci.aci_fabric_spine_switch_assoc:
77 host: apic
78 username: admin
79 password: SomeSecretPassword
80 profile: my_spine_profile
81 name: my_spine_switch_assoc
82 state: absent
83 delegate_to: localhost
84
85 - name: Query a spine profile association
86 cisco.aci.aci_fabric_spine_switch_assoc:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 profile: my_spine_profile
91 name: my_spine_switch_assoc
92 state: query
93 delegate_to: localhost
94 register: query_result
95
96 - name: Query all spine profiles
97 cisco.aci.aci_fabric_spine_switch_assoc:
98 host: apic
99 username: admin
100 password: SomeSecretPassword
101 state: query
102 delegate_to: localhost
103 register: query_result
104 """
105
106 RETURN = r"""
107 current:
108 description: The existing configuration from the APIC after the module has finished
109 returned: success
110 type: list
111 sample:
112 [
113 {
114 "fvTenant": {
115 "attributes": {
116 "descr": "Production environment",
117 "dn": "uni/tn-production",
118 "name": "production",
119 "nameAlias": "",
120 "ownerKey": "",
121 "ownerTag": ""
122 }
123 }
124 }
125 ]
126 error:
127 description: The error information as returned from the APIC
128 returned: failure
129 type: dict
130 sample:
131 {
132 "code": "122",
133 "text": "unknown managed object class foo"
134 }
135 raw:
136 description: The raw output returned by the APIC REST API (xml or json)
137 returned: parse error
138 type: str
139 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
140 sent:
141 description: The actual/minimal configuration pushed to the APIC
142 returned: info
143 type: list
144 sample:
145 {
146 "fvTenant": {
147 "attributes": {
148 "descr": "Production environment"
149 }
150 }
151 }
152 previous:
153 description: The original configuration from the APIC before the module has started
154 returned: info
155 type: list
156 sample:
157 [
158 {
159 "fvTenant": {
160 "attributes": {
161 "descr": "Production",
162 "dn": "uni/tn-production",
163 "name": "production",
164 "nameAlias": "",
165 "ownerKey": "",
166 "ownerTag": ""
167 }
168 }
169 }
170 ]
171 proposed:
172 description: The assembled configuration from the user-provided parameters
173 returned: info
174 type: dict
175 sample:
176 {
177 "fvTenant": {
178 "attributes": {
179 "descr": "Production environment",
180 "name": "production"
181 }
182 }
183 }
184 filter_string:
185 description: The filter string used for the request
186 returned: failure or debug
187 type: str
188 sample: ?rsp-prop-include=config-only
189 method:
190 description: The HTTP method used for the request to the APIC
191 returned: failure or debug
192 type: str
193 sample: POST
194 response:
195 description: The HTTP response from the APIC
196 returned: failure or debug
197 type: str
198 sample: OK (30 bytes)
199 status:
200 description: The HTTP status from the APIC
201 returned: failure or debug
202 type: int
203 sample: 200
204 url:
205 description: The HTTP url used for the request to the APIC
206 returned: failure or debug
207 type: str
208 sample: https://10.11.12.13/api/mo/uni/tn-production.json
209 """
210
211
212 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
213 from ansible.module_utils.basic import AnsibleModule
214
215
216 def main():
217 argument_spec = aci_argument_spec()
218 argument_spec.update(aci_annotation_spec())
219 argument_spec.update(aci_owner_spec())
220 argument_spec.update(
221 profile=dict(type="str", aliases=["spine_profile", "spine_switch_profile"]),
222 name=dict(type="str", aliases=["association_name", "switch_association"]),
223 policy_group=dict(type="str"),
224 description=dict(type="str", aliases=["descr"]),
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", ["profile", "name"]],
233 ["state", "present", ["profile", "name"]],
234 ],
235 )
236
237 aci = ACIModule(module)
238
239 profile = module.params.get("profile")
240 name = module.params.get("name")
241 policy_group = module.params.get("policy_group")
242 description = module.params.get("description")
243 state = module.params.get("state")
244 child_classes = ["fabricRsSpNodePGrp", "fabricNodeBlk"]
245
246 aci.construct_url(
247 root_class=dict(
248 aci_class="fabricSpineP",
249 aci_rn="fabric/spprof-{0}".format(profile),
250 module_object=profile,
251 target_filter={"name": profile},
252 ),
253 subclass_1=dict(
254 aci_class="fabricSpineS",
255 aci_rn="spines-{0}-typ-range".format(name),
256 module_object=name,
257 target_filter={"name": name},
258 ),
259 child_classes=child_classes,
260 )
261
262 aci.get_existing()
263
264 if state == "present":
265 child_configs = []
266 if policy_group:
267 tDn = "uni/fabric/funcprof/spnodepgrp-{0}".format(policy_group)
268 child_configs.append(dict(fabricRsSpNodePGrp=dict(attributes=dict(tDn=tDn))))
269 aci.payload(
270 aci_class="fabricSpineS",
271 class_config=dict(name=name, descr=description),
272 child_configs=child_configs,
273 )
274
275 aci.get_diff(aci_class="fabricSpineS")
276
277 aci.post_config()
278
279 elif state == "absent":
280 aci.delete_config()
281
282 aci.exit_json()
283
284
285 if __name__ == "__main__":
286 main()