| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2025, Dev Sinha (@DevSinha13) <[email protected]> |
| 5 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 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": "community"} |
| 11 |
|
| 12 |
DOCUMENTATION = r""" |
| 13 |
--- |
| 14 |
module: aci_vmm_enhanced_lag_policy |
| 15 |
version_added: "2.12.0" |
| 16 |
short_description: Manage Enhanced LACP Policy for Virtual Machine Manager (VMM) in Cisco ACI (lacp:EnhancedLagPol) |
| 17 |
description: |
| 18 |
- Manage Enhanced LACP Policy for VMM domains on Cisco ACI fabrics. |
| 19 |
- The Enhanced LACP Policy allows you to configure advanced Link Aggregation Control Protocol settings for virtual switches in VMM domains. |
| 20 |
|
| 21 |
options: |
| 22 |
name: |
| 23 |
description: |
| 24 |
- The name of the Enhanced LACP Policy. |
| 25 |
type: str |
| 26 |
domain: |
| 27 |
description: |
| 28 |
- The name of the virtual domain profile where the Enhanced LACP Policy is applied. |
| 29 |
type: str |
| 30 |
aliases: [ domain_name, domain_profile ] |
| 31 |
vm_provider: |
| 32 |
description: |
| 33 |
- The virtualization platform provider for the VMM domain. |
| 34 |
type: str |
| 35 |
choices: [ cloudfoundry, kubernetes, microsoft, openshift, openstack, redhat, vmware ] |
| 36 |
lacp_mode: |
| 37 |
description: |
| 38 |
- The LACP mode for the policy. |
| 39 |
- Determines whether the policy initiates or responds to LACP negotiations. |
| 40 |
- The APIC defaults to C(active) when unset during creation. |
| 41 |
type: str |
| 42 |
choices: [ active, passive ] |
| 43 |
load_balancing_mode: |
| 44 |
description: |
| 45 |
- The load balancing algorithm for distributing traffic across links in the port channel. |
| 46 |
- See the APIC Management Information Model reference for more details. |
| 47 |
- The APIC defaults to C(src-dst-ip) when unset during creation |
| 48 |
type: str |
| 49 |
choices: |
| 50 |
- dst-ip |
| 51 |
- dst-ip-l4port |
| 52 |
- dst-ip-vlan |
| 53 |
- dst-ip-l4port-vlan |
| 54 |
- dst-mac |
| 55 |
- dst-l4port |
| 56 |
- src-ip |
| 57 |
- src-ip-l4port |
| 58 |
- src-ip-vlan |
| 59 |
- src-ip-l4port-vlan |
| 60 |
- src-mac |
| 61 |
- src-l4port |
| 62 |
- src-dst-ip |
| 63 |
- src-dst-ip-l4port |
| 64 |
- src-dst-ip-vlan |
| 65 |
- src-dst-ip-l4port-vlan |
| 66 |
- src-dst-mac |
| 67 |
- src-dst-l4port |
| 68 |
- src-port-id |
| 69 |
- vlan |
| 70 |
number_uplinks: |
| 71 |
description: |
| 72 |
- The minimum number of uplinks required for the port channel. |
| 73 |
- Must be a value between 2 and 8. |
| 74 |
- The APIC defaults to 2 when unset during creation |
| 75 |
type: int |
| 76 |
state: |
| 77 |
description: |
| 78 |
- The desired state of the Enhanced LACP Policy. |
| 79 |
- Use C(present) to create or update the policy. |
| 80 |
- Use C(absent) to delete the policy. |
| 81 |
- Use C(query) to retrieve information about the policy. |
| 82 |
type: str |
| 83 |
choices: [ absent, present, query ] |
| 84 |
default: present |
| 85 |
extends_documentation_fragment: |
| 86 |
- cisco.aci.aci |
| 87 |
- cisco.aci.annotation |
| 88 |
- cisco.aci.owner |
| 89 |
|
| 90 |
notes: |
| 91 |
- The I(vmm_domain) and I(vSwitch_policy) must exist before using this module in a playbook. |
| 92 |
- The modules M(cisco.aci.aci_domain) and M(cisco.aci.aci_vmm_vswitch_policy) can be used for this. |
| 93 |
seealso: |
| 94 |
- module: cisco.aci.aci_domain |
| 95 |
- module: cisco.aci.aci_vmm_vswitch_policy |
| 96 |
- name: APIC Management Information Model reference |
| 97 |
description: More information about the internal APIC classes B(lacp:EnhancedLagPol). |
| 98 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 99 |
author: |
| 100 |
- Dev Sinha (@DevSinha13) |
| 101 |
""" |
| 102 |
|
| 103 |
EXAMPLES = r""" |
| 104 |
- name: Create an Enhanced LACP Policy |
| 105 |
cisco.aci.aci_vmm_enhanced_lag_policy: |
| 106 |
host: apic.example.com |
| 107 |
username: admin |
| 108 |
password: SomeSecretPassword |
| 109 |
name: my_enhanced_lag_policy |
| 110 |
domain: my_vmm_domain |
| 111 |
vm_provider: vmware |
| 112 |
lacp_mode: active |
| 113 |
load_balancing_mode: src-dst-ip |
| 114 |
number_uplinks: 4 |
| 115 |
state: present |
| 116 |
|
| 117 |
- name: Update an existing Enhanced LACP Policy |
| 118 |
cisco.aci.aci_vmm_enhanced_lag_policy: |
| 119 |
host: apic.example.com |
| 120 |
username: admin |
| 121 |
password: SomeSecretPassword |
| 122 |
name: my_enhanced_lag_policy |
| 123 |
domain: my_vmm_domain |
| 124 |
vm_provider: vmware |
| 125 |
lacp_mode: passive |
| 126 |
load_balancing_mode: src-dst-ip-l4port |
| 127 |
number_uplinks: 6 |
| 128 |
state: present |
| 129 |
|
| 130 |
- name: Query a specific Enhanced LACP Policy |
| 131 |
cisco.aci.aci_vmm_enhanced_lag_policy: |
| 132 |
host: apic.example.com |
| 133 |
username: admin |
| 134 |
password: SomeSecretPassword |
| 135 |
name: my_enhanced_lag_policy |
| 136 |
domain: my_vmm_domain |
| 137 |
vm_provider: vmware |
| 138 |
state: query |
| 139 |
register: query_result |
| 140 |
|
| 141 |
- name: Query all Enhanced LACP Policies in a VMM domain |
| 142 |
cisco.aci.aci_vmm_enhanced_lag_policy: |
| 143 |
host: apic.example.com |
| 144 |
username: admin |
| 145 |
password: SomeSecretPassword |
| 146 |
domain: my_vmm_domain |
| 147 |
vm_provider: vmware |
| 148 |
state: query |
| 149 |
register: query_all_result |
| 150 |
|
| 151 |
- name: Delete an Enhanced LACP Policy |
| 152 |
cisco.aci.aci_vmm_enhanced_lag_policy: |
| 153 |
host: apic.example.com |
| 154 |
username: admin |
| 155 |
password: SomeSecretPassword |
| 156 |
name: my_enhanced_lag_policy |
| 157 |
domain: my_vmm_domain |
| 158 |
vm_provider: vmware |
| 159 |
state: absent |
| 160 |
""" |
| 161 |
RETURN = r""" |
| 162 |
current: |
| 163 |
description: The existing configuration of the Enhanced LACP Policy from the APIC after the module has finished. |
| 164 |
returned: success |
| 165 |
type: list |
| 166 |
sample: |
| 167 |
[ |
| 168 |
{ |
| 169 |
"lacpEnhancedLagPol": { |
| 170 |
"attributes": { |
| 171 |
"name": "test_enhanced_lag_policy", |
| 172 |
"mode": "active", |
| 173 |
"lbmode": "src-dst-ip", |
| 174 |
"numLinks": "4", |
| 175 |
"dn": "uni/vmmp-VMware/dom-test_vmm_dom/vswitchpolcont/enlacplagp-test_enhanced_lag_policy" |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
] |
| 180 |
error: |
| 181 |
description: The error information as returned from the APIC. |
| 182 |
returned: failure |
| 183 |
type: dict |
| 184 |
sample: |
| 185 |
{ |
| 186 |
"code": "801", |
| 187 |
"text": "property name of enlacplagp-test_enhanced_lag_policy failed validation" |
| 188 |
} |
| 189 |
proposed: |
| 190 |
description: The configuration sent to the APIC. |
| 191 |
returned: info |
| 192 |
type: dict |
| 193 |
sample: |
| 194 |
{ |
| 195 |
"lacpEnhancedLagPol": { |
| 196 |
"attributes": { |
| 197 |
"name": "test_enhanced_lag_policy", |
| 198 |
"mode": "active", |
| 199 |
"lbmode": "src-dst-ip", |
| 200 |
"numLinks": "4" |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
""" |
| 205 |
|
| 206 |
from ansible.module_utils.basic import AnsibleModule |
| 207 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ( |
| 208 |
ACIModule, |
| 209 |
aci_argument_spec, |
| 210 |
enhanced_lag_spec, |
| 211 |
aci_annotation_spec, |
| 212 |
aci_owner_spec, |
| 213 |
) |
| 214 |
from ansible_collections.cisco.aci.plugins.module_utils.constants import ( |
| 215 |
VM_PROVIDER_MAPPING, |
| 216 |
) |
| 217 |
|
| 218 |
|
| 219 |
def main(): |
| 220 |
|
| 221 |
# Remove nutanix from VM_PROVIDER_MAPPING as it is not supported |
| 222 |
CLEAN_VM_PROVIDER_MAPPING = VM_PROVIDER_MAPPING.copy() |
| 223 |
CLEAN_VM_PROVIDER_MAPPING.pop("nutanix") |
| 224 |
|
| 225 |
argument_spec = aci_argument_spec() |
| 226 |
argument_spec.update(aci_annotation_spec()) |
| 227 |
argument_spec.update(aci_owner_spec()) |
| 228 |
argument_spec.update(enhanced_lag_spec(name_is_required=False)) |
| 229 |
argument_spec.update( |
| 230 |
domain=dict(type="str", aliases=["domain_name", "domain_profile"]), |
| 231 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 232 |
vm_provider=dict(type="str", choices=list(CLEAN_VM_PROVIDER_MAPPING)), |
| 233 |
) |
| 234 |
|
| 235 |
module = AnsibleModule( |
| 236 |
argument_spec=argument_spec, |
| 237 |
supports_check_mode=True, |
| 238 |
required_if=[ |
| 239 |
["state", "absent", ["name", "domain", "vm_provider"]], |
| 240 |
["state", "present", ["name", "domain", "vm_provider"]], |
| 241 |
], |
| 242 |
) |
| 243 |
|
| 244 |
name = module.params.get("name") |
| 245 |
lacp_mode = module.params.get("lacp_mode") |
| 246 |
load_balancing_mode = module.params.get("load_balancing_mode") |
| 247 |
number_uplinks = module.params.get("number_uplinks") |
| 248 |
domain = module.params.get("domain") |
| 249 |
state = module.params.get("state") |
| 250 |
vm_provider = module.params.get("vm_provider") |
| 251 |
|
| 252 |
aci = ACIModule(module) |
| 253 |
|
| 254 |
aci.construct_url( |
| 255 |
root_class=dict( |
| 256 |
aci_class="vmmProvP", |
| 257 |
aci_rn="vmmp-{0}".format(CLEAN_VM_PROVIDER_MAPPING.get(vm_provider)), |
| 258 |
module_object=vm_provider, |
| 259 |
target_filter={"vendor": vm_provider}, |
| 260 |
), |
| 261 |
subclass_1=dict( |
| 262 |
aci_class="vmmDomP", |
| 263 |
aci_rn="dom-{0}".format(domain), |
| 264 |
module_object=domain, |
| 265 |
target_filter={"name": domain}, |
| 266 |
), |
| 267 |
subclass_2=dict( |
| 268 |
aci_class="vmmVSwitchPolicyCont", |
| 269 |
aci_rn="vswitchpolcont", |
| 270 |
module_object="vswitchpolcont", |
| 271 |
), |
| 272 |
subclass_3=dict( |
| 273 |
aci_class="lacpEnhancedLagPol", |
| 274 |
aci_rn="enlacplagp-{0}".format(name), |
| 275 |
module_object=name, |
| 276 |
target_filter={"name": name}, |
| 277 |
), |
| 278 |
) |
| 279 |
|
| 280 |
aci.get_existing() |
| 281 |
|
| 282 |
if state == "present": |
| 283 |
aci.payload( |
| 284 |
aci_class="lacpEnhancedLagPol", |
| 285 |
class_config=dict( |
| 286 |
name=name, |
| 287 |
mode=lacp_mode, |
| 288 |
lbmode=load_balancing_mode, |
| 289 |
numLinks=number_uplinks, |
| 290 |
), |
| 291 |
) |
| 292 |
|
| 293 |
aci.get_diff(aci_class="lacpEnhancedLagPol") |
| 294 |
|
| 295 |
aci.post_config() |
| 296 |
|
| 297 |
elif state == "absent": |
| 298 |
aci.delete_config() |
| 299 |
|
| 300 |
aci.exit_json() |
| 301 |
|
| 302 |
|
| 303 |
if __name__ == "__main__": |
| 304 |
main() |