Debian Codegraph @

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

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