Debian Codegraph @

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

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