| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2023, Anvitha Jain (@anvjain) <[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 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"} |
| 12 |
|
| 13 |
DOCUMENTATION = r""" |
| 14 |
--- |
| 15 |
module: aci_l3out_bfd_interface_profile |
| 16 |
short_description: Manage L3Out BFD Interface profiles (bfd:IfP) |
| 17 |
description: |
| 18 |
- Manage L3Out BFD Interface profile configuration on Cisco ACI fabrics |
| 19 |
- Only available in APIC version 5.2 or later and for non-cloud APICs |
| 20 |
options: |
| 21 |
tenant: |
| 22 |
description: |
| 23 |
- Name of an existing tenant |
| 24 |
type: str |
| 25 |
aliases: [ tenant_name ] |
| 26 |
l3out: |
| 27 |
description: |
| 28 |
- Name of an existing L3Out |
| 29 |
type: str |
| 30 |
aliases: [ l3out_name ] |
| 31 |
l3out_logical_node_profile: |
| 32 |
description: |
| 33 |
- Name of an existing L3Out Logical Node profile |
| 34 |
type: str |
| 35 |
aliases: [ logical_node_profile, logical_node_profile_name ] |
| 36 |
l3out_logical_interface_profile: |
| 37 |
description: |
| 38 |
- Name of an existing L3Out Logical Interface profile |
| 39 |
type: str |
| 40 |
aliases: [ logical_interface_profile, logical_interface_profile_name ] |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Name of the L3Out BFD Interface profile object |
| 44 |
type: str |
| 45 |
aliases: [ bfd_multihop_interface_profile ] |
| 46 |
name_alias: |
| 47 |
description: |
| 48 |
- Name Alias of the L3Out BFD Interface profile object |
| 49 |
type: str |
| 50 |
description: |
| 51 |
description: |
| 52 |
- Description of the L3Out BFD Interface profile object |
| 53 |
type: str |
| 54 |
aliases: [ descr ] |
| 55 |
authentication_type: |
| 56 |
description: |
| 57 |
- Authentication Type of the L3Out BFD Interface profile object |
| 58 |
- APIC sets the default value to none |
| 59 |
type: str |
| 60 |
choices: [ none, sha1 ] |
| 61 |
key: |
| 62 |
description: |
| 63 |
- Authentication Key of the L3Out BFD Interface profile object |
| 64 |
- Providing this option will always result in a change because it is a secure property that cannot be retrieved from APIC. |
| 65 |
type: str |
| 66 |
key_id: |
| 67 |
description: |
| 68 |
- Authentication Key ID of the L3Out BFD Interface profile object |
| 69 |
- APIC sets the default value to 3 |
| 70 |
- Allowed range is 1-255 |
| 71 |
type: int |
| 72 |
bfd_interface_policy: |
| 73 |
description: |
| 74 |
- The name of the Interface policy |
| 75 |
type: str |
| 76 |
aliases: [ interface_policy, interface_policy_name ] |
| 77 |
state: |
| 78 |
description: |
| 79 |
- Use C(present) or C(absent) for adding or removing. |
| 80 |
- Use C(query) for listing an object or multiple objects |
| 81 |
type: str |
| 82 |
choices: [ absent, present, query ] |
| 83 |
default: present |
| 84 |
extends_documentation_fragment: |
| 85 |
- cisco.aci.aci |
| 86 |
- cisco.aci.annotation |
| 87 |
|
| 88 |
notes: |
| 89 |
- The C(tenant), c(l3out), C(l3out_logical_node_profile) and C(l3out_logical_interface_profile) must exist before using this module in your playbook |
| 90 |
The M(cisco.aci.aci_tenant) modules can be used for this |
| 91 |
seealso: |
| 92 |
- name: APIC Management Information Model reference |
| 93 |
description: More information about the internal APIC class B(bfd:IfP) |
| 94 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 95 |
- module: cisco.aci.aci_tenant |
| 96 |
- module: cisco.aci.aci_l3out |
| 97 |
- module: cisco.aci.aci_l3out_logical_node_profile |
| 98 |
- module: cisco.aci.aci_l3out_logical_interface_profile |
| 99 |
- module: cisco.aci.aci_interface_policy_bfd |
| 100 |
author: |
| 101 |
- Anvitha Jain (@anvjain) |
| 102 |
""" |
| 103 |
|
| 104 |
EXAMPLES = r""" |
| 105 |
- name: Add a new L3Out BFD Interface Profile |
| 106 |
cisco.aci.aci_l3out_bfd_interface_profile: |
| 107 |
username: admin |
| 108 |
password: SomeSecretPassword |
| 109 |
tenant: ansible_tenant |
| 110 |
l3out: ansible_l3out |
| 111 |
l3out_logical_node_profile: ansible_node_profile |
| 112 |
l3out_logical_interface_profile: ansible_interface_profile |
| 113 |
state: present |
| 114 |
delegate_to: localhost |
| 115 |
|
| 116 |
- name: Query a new L3Out BFD Interface Profile |
| 117 |
cisco.aci.aci_l3out_bfd_interface_profile: |
| 118 |
username: admin |
| 119 |
password: SomeSecretPassword |
| 120 |
tenant: ansible_tenant |
| 121 |
l3out: ansible_l3out |
| 122 |
l3out_logical_node_profile: ansible_node_profile |
| 123 |
l3out_logical_interface_profile: ansible_interface_profile |
| 124 |
state: query |
| 125 |
delegate_to: localhost |
| 126 |
|
| 127 |
- name: Query all L3Out BFD Interface Profile |
| 128 |
cisco.aci.aci_l3out_bfd_interface_profile: |
| 129 |
username: admin |
| 130 |
password: SomeSecretPassword |
| 131 |
state: query |
| 132 |
delegate_to: localhost |
| 133 |
|
| 134 |
- name: Delete L3Out BFD Interface Profile |
| 135 |
cisco.aci.aci_l3out_bfd_interface_profile: |
| 136 |
username: admin |
| 137 |
password: SomeSecretPassword |
| 138 |
tenant: ansible_tenant |
| 139 |
l3out: ansible_l3out |
| 140 |
l3out_logical_node_profile: ansible_node_profile |
| 141 |
l3out_logical_interface_profile: ansible_interface_profile |
| 142 |
state: absent |
| 143 |
delegate_to: localhost |
| 144 |
""" |
| 145 |
|
| 146 |
RETURN = r""" |
| 147 |
current: |
| 148 |
description: The existing configuration from the APIC after the module has finished |
| 149 |
returned: success |
| 150 |
type: list |
| 151 |
sample: |
| 152 |
[ |
| 153 |
{ |
| 154 |
"fvTenant": { |
| 155 |
"attributes": { |
| 156 |
"descr": "Production environment", |
| 157 |
"dn": "uni/tn-production", |
| 158 |
"name": "production", |
| 159 |
"nameAlias": "", |
| 160 |
"ownerKey": "", |
| 161 |
"ownerTag": "" |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
] |
| 166 |
error: |
| 167 |
description: The error information as returned from the APIC |
| 168 |
returned: failure |
| 169 |
type: dict |
| 170 |
sample: |
| 171 |
{ |
| 172 |
"code": "122", |
| 173 |
"text": "unknown managed object class foo" |
| 174 |
} |
| 175 |
raw: |
| 176 |
description: The raw output returned by the APIC REST API (xml or json) |
| 177 |
returned: parse error |
| 178 |
type: str |
| 179 |
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>' |
| 180 |
sent: |
| 181 |
description: The actual/minimal configuration pushed to the APIC |
| 182 |
returned: info |
| 183 |
type: list |
| 184 |
sample: |
| 185 |
{ |
| 186 |
"fvTenant": { |
| 187 |
"attributes": { |
| 188 |
"descr": "Production environment" |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
previous: |
| 193 |
description: The original configuration from the APIC before the module has started |
| 194 |
returned: info |
| 195 |
type: list |
| 196 |
sample: |
| 197 |
[ |
| 198 |
{ |
| 199 |
"fvTenant": { |
| 200 |
"attributes": { |
| 201 |
"descr": "Production", |
| 202 |
"dn": "uni/tn-production", |
| 203 |
"name": "production", |
| 204 |
"nameAlias": "", |
| 205 |
"ownerKey": "", |
| 206 |
"ownerTag": "" |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
] |
| 211 |
proposed: |
| 212 |
description: The assembled configuration from the user-provided parameters |
| 213 |
returned: info |
| 214 |
type: dict |
| 215 |
sample: |
| 216 |
{ |
| 217 |
"fvTenant": { |
| 218 |
"attributes": { |
| 219 |
"descr": "Production environment", |
| 220 |
"name": "production" |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
filter_string: |
| 225 |
description: The filter string used for the request |
| 226 |
returned: failure or debug |
| 227 |
type: str |
| 228 |
sample: ?rsp-prop-include=config-only |
| 229 |
method: |
| 230 |
description: The HTTP method used for the request to the APIC |
| 231 |
returned: failure or debug |
| 232 |
type: str |
| 233 |
sample: POST |
| 234 |
response: |
| 235 |
description: The HTTP response from the APIC |
| 236 |
returned: failure or debug |
| 237 |
type: str |
| 238 |
sample: OK (30 bytes) |
| 239 |
status: |
| 240 |
description: The HTTP status from the APIC |
| 241 |
returned: failure or debug |
| 242 |
type: int |
| 243 |
sample: 200 |
| 244 |
url: |
| 245 |
description: The HTTP url used for the request to the APIC |
| 246 |
returned: failure or debug |
| 247 |
type: str |
| 248 |
sample: https://10.11.12.13/api/mo/uni/tn-production.json |
| 249 |
""" |
| 250 |
|
| 251 |
from ansible.module_utils.basic import AnsibleModule |
| 252 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec |
| 253 |
|
| 254 |
|
| 255 |
def main(): |
| 256 |
argument_spec = aci_argument_spec() |
| 257 |
argument_spec.update(aci_annotation_spec()) |
| 258 |
argument_spec.update( |
| 259 |
tenant=dict(type="str", aliases=["tenant_name"]), |
| 260 |
l3out=dict(type="str", aliases=["l3out_name"]), |
| 261 |
l3out_logical_node_profile=dict(type="str", aliases=["logical_node_profile_name", "logical_node_profile"]), |
| 262 |
l3out_logical_interface_profile=dict(type="str", aliases=["logical_interface_profile_name", "logical_interface_profile"]), |
| 263 |
name=dict(type="str", aliases=["bfd_multihop_interface_profile"]), |
| 264 |
name_alias=dict(type="str"), |
| 265 |
description=dict(type="str", aliases=["descr"]), |
| 266 |
authentication_type=dict(type="str", choices=["none", "sha1"]), |
| 267 |
key=dict(type="str", no_log=True), |
| 268 |
key_id=dict(type="int"), |
| 269 |
bfd_interface_policy=dict(type="str", aliases=["interface_policy", "interface_policy_name"]), |
| 270 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 271 |
) |
| 272 |
|
| 273 |
module = AnsibleModule( |
| 274 |
argument_spec=argument_spec, |
| 275 |
supports_check_mode=True, |
| 276 |
required_if=[ |
| 277 |
["state", "absent", ["tenant", "l3out", "l3out_logical_node_profile", "l3out_logical_interface_profile"]], |
| 278 |
["state", "present", ["tenant", "l3out", "l3out_logical_node_profile", "l3out_logical_interface_profile", "bfd_interface_policy"]], |
| 279 |
["authentication_type", "sha1", ["key"]], |
| 280 |
], |
| 281 |
) |
| 282 |
|
| 283 |
tenant = module.params.get("tenant") |
| 284 |
l3out = module.params.get("l3out") |
| 285 |
l3out_logical_node_profile = module.params.get("l3out_logical_node_profile") |
| 286 |
l3out_logical_interface_profile = module.params.get("l3out_logical_interface_profile") |
| 287 |
name = module.params.get("name") |
| 288 |
name_alias = module.params.get("name_alias") |
| 289 |
description = module.params.get("description") |
| 290 |
authentication_type = module.params.get("authentication_type") |
| 291 |
key = module.params.get("key") |
| 292 |
key_id = module.params.get("key_id") |
| 293 |
bfd_interface_policy = module.params.get("bfd_interface_policy") |
| 294 |
state = module.params.get("state") |
| 295 |
|
| 296 |
aci = ACIModule(module) |
| 297 |
aci.construct_url( |
| 298 |
root_class=dict( |
| 299 |
aci_class="fvTenant", |
| 300 |
aci_rn="tn-{0}".format(tenant), |
| 301 |
module_object=tenant, |
| 302 |
target_filter={"name": tenant}, |
| 303 |
), |
| 304 |
subclass_1=dict( |
| 305 |
aci_class="l3extOut", |
| 306 |
aci_rn="out-{0}".format(l3out), |
| 307 |
module_object=l3out, |
| 308 |
target_filter={"name": l3out}, |
| 309 |
), |
| 310 |
subclass_2=dict( |
| 311 |
aci_class="l3extLNodeP", |
| 312 |
aci_rn="lnodep-{0}".format(l3out_logical_node_profile), |
| 313 |
module_object=l3out_logical_node_profile, |
| 314 |
target_filter={"name": l3out_logical_node_profile}, |
| 315 |
), |
| 316 |
subclass_3=dict( |
| 317 |
aci_class="l3extLIfP", |
| 318 |
aci_rn="lifp-{0}".format(l3out_logical_interface_profile), |
| 319 |
module_object=l3out_logical_interface_profile, |
| 320 |
target_filter={"name": l3out_logical_interface_profile}, |
| 321 |
), |
| 322 |
subclass_4=dict( |
| 323 |
aci_class="bfdIfP", |
| 324 |
aci_rn="bfdIfP", |
| 325 |
module_object="bfdIfP", |
| 326 |
target_filter={"name": name}, |
| 327 |
), |
| 328 |
child_classes=["bfdRsIfPol"], |
| 329 |
) |
| 330 |
|
| 331 |
aci.get_existing() |
| 332 |
|
| 333 |
if state == "present": |
| 334 |
child_configs = [] |
| 335 |
class_config = dict( |
| 336 |
name=name, |
| 337 |
nameAlias=name_alias, |
| 338 |
descr=description, |
| 339 |
key=key, |
| 340 |
type=authentication_type, |
| 341 |
) |
| 342 |
|
| 343 |
if key_id and key_id not in range(1, 255): |
| 344 |
module.fail_json(msg='The "key_id" must be a value between 1 and 255') |
| 345 |
else: |
| 346 |
class_config["keyId"] = key_id |
| 347 |
|
| 348 |
if bfd_interface_policy is not None: |
| 349 |
child_configs.append(dict(bfdRsIfPol=dict(attributes=dict(tnBfdIfPolName=bfd_interface_policy)))) |
| 350 |
|
| 351 |
aci.payload( |
| 352 |
aci_class="bfdIfP", |
| 353 |
class_config=class_config, |
| 354 |
child_configs=child_configs, |
| 355 |
) |
| 356 |
|
| 357 |
aci.get_diff(aci_class="bfdIfP") |
| 358 |
|
| 359 |
aci.post_config() |
| 360 |
|
| 361 |
elif state == "absent": |
| 362 |
aci.delete_config() |
| 363 |
|
| 364 |
aci.exit_json() |
| 365 |
|
| 366 |
|
| 367 |
if __name__ == "__main__": |
| 368 |
main() |