Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_bgp_rr_asn.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_asn
16 short_description: Manage BGP Route Reflector ASN (bgp:AsP)
17 description:
18 - Manage the BGP Autonomous System Number of the fabric.
19 - This module is specifically for fabric BGP, for L3Out BGP use the aci_l3out_bgp_peer module
20 options:
21 asn:
22 description:
23 - BGP Autonomous System Number
24 type: int
25 state:
26 description:
27 - Use C(present) or C(absent) for adding or removing.
28 - Use C(query) for listing an object or multiple objects.
29 type: str
30 choices: [ absent, present, query ]
31 default: present
32 extends_documentation_fragment:
33 - cisco.aci.aci
34 - cisco.aci.annotation
35
36 seealso:
37 - name: APIC Management Information Model reference
38 description: More information about the internal APIC class B(bgp:AsP).
39 link: https://developer.cisco.com/docs/apic-mim-ref/
40 author:
41 - Tim Cragg (@timcragg)
42 """
43
44 EXAMPLES = r"""
45 - name: Set fabric BGP AS number
46 cisco.aci.aci_bgp_rr_asn:
47 host: apic
48 username: admin
49 password: SomeSecretPassword
50 asn: 65001
51 state: present
52 delegate_to: localhost
53
54 - name: Remove fabric BGP AS number
55 cisco.aci.aci_bgp_rr_asn:
56 host: apic
57 username: admin
58 password: SomeSecretPassword
59 state: absent
60 delegate_to: localhost
61
62 - name: Query fabric BGP AS number
63 cisco.aci.aci_bgp_rr_asn:
64 host: apic
65 username: admin
66 password: SomeSecretPassword
67 state: query
68 delegate_to: localhost
69 register: query_result
70 """
71
72 RETURN = r"""
73 current:
74 description: The existing configuration from the APIC after the module has finished
75 returned: success
76 type: list
77 sample:
78 [
79 {
80 "fvTenant": {
81 "attributes": {
82 "descr": "Production environment",
83 "dn": "uni/tn-production",
84 "name": "production",
85 "nameAlias": "",
86 "ownerKey": "",
87 "ownerTag": ""
88 }
89 }
90 }
91 ]
92 error:
93 description: The error information as returned from the APIC
94 returned: failure
95 type: dict
96 sample:
97 {
98 "code": "122",
99 "text": "unknown managed object class foo"
100 }
101 raw:
102 description: The raw output returned by the APIC REST API (xml or json)
103 returned: parse error
104 type: str
105 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
106 sent:
107 description: The actual/minimal configuration pushed to the APIC
108 returned: info
109 type: list
110 sample:
111 {
112 "fvTenant": {
113 "attributes": {
114 "descr": "Production environment"
115 }
116 }
117 }
118 previous:
119 description: The original configuration from the APIC before the module has started
120 returned: info
121 type: list
122 sample:
123 [
124 {
125 "fvTenant": {
126 "attributes": {
127 "descr": "Production",
128 "dn": "uni/tn-production",
129 "name": "production",
130 "nameAlias": "",
131 "ownerKey": "",
132 "ownerTag": ""
133 }
134 }
135 }
136 ]
137 proposed:
138 description: The assembled configuration from the user-provided parameters
139 returned: info
140 type: dict
141 sample:
142 {
143 "fvTenant": {
144 "attributes": {
145 "descr": "Production environment",
146 "name": "production"
147 }
148 }
149 }
150 filter_string:
151 description: The filter string used for the request
152 returned: failure or debug
153 type: str
154 sample: ?rsp-prop-include=config-only
155 method:
156 description: The HTTP method used for the request to the APIC
157 returned: failure or debug
158 type: str
159 sample: POST
160 response:
161 description: The HTTP response from the APIC
162 returned: failure or debug
163 type: str
164 sample: OK (30 bytes)
165 status:
166 description: The HTTP status from the APIC
167 returned: failure or debug
168 type: int
169 sample: 200
170 url:
171 description: The HTTP url used for the request to the APIC
172 returned: failure or debug
173 type: str
174 sample: https://10.11.12.13/api/mo/uni/tn-production.json
175 """
176
177 from ansible.module_utils.basic import AnsibleModule
178 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
179
180
181 def main():
182 argument_spec = aci_argument_spec()
183 argument_spec.update(aci_annotation_spec())
184 argument_spec.update(
185 asn=dict(type="int"),
186 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
187 )
188
189 module = AnsibleModule(
190 argument_spec=argument_spec,
191 supports_check_mode=True,
192 required_if=[
193 ["state", "present", ["asn"]],
194 ],
195 )
196
197 asn = module.params.get("asn")
198 state = module.params.get("state")
199
200 aci = ACIModule(module)
201 aci.construct_url(
202 root_class=dict(
203 aci_class="bgpInstPol",
204 aci_rn="fabric/bgpInstP-default",
205 module_object="default",
206 target_filter={"name": "default"},
207 ),
208 subclass_1=dict(
209 aci_class="bgpAsP",
210 aci_rn="as",
211 module_object="name",
212 target_filter={"name": ""},
213 ),
214 )
215
216 aci.get_existing()
217
218 if state == "present":
219 aci.payload(
220 aci_class="bgpAsP",
221 class_config=dict(
222 asn=asn,
223 ),
224 )
225
226 aci.get_diff(aci_class="bgpAsP")
227
228 aci.post_config()
229
230 elif state == "absent":
231 aci.delete_config()
232
233 aci.exit_json()
234
235
236 if __name__ == "__main__":
237 main()