Skip to content

Commit cea8f5d

Browse files
committed
[minor_change] Add module aci_port_channel_member_policy to manage port channel member policies
1 parent 9170e00 commit cea8f5d

File tree

3 files changed

+510
-0
lines changed

3 files changed

+510
-0
lines changed
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# Copyright: (c) 2025, Akini Ross (@akinross)
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 = {
12+
"metadata_version": "1.1",
13+
"status": ["preview"],
14+
"supported_by": "community",
15+
}
16+
17+
DOCUMENTATION = r"""
18+
---
19+
module: aci_port_channel_member_policy
20+
short_description: Manage Port Channel Member policies (lacp:IfPol)
21+
description:
22+
- Manage Port Channel Member policy configuration on Cisco ACI fabrics.
23+
options:
24+
name:
25+
description:
26+
- The name of the Port Channel Member policy.
27+
type: str
28+
aliases: [ port_channel_member_policy ]
29+
description:
30+
description:
31+
- The description of the Port Channel Member policy.
32+
type: str
33+
priority:
34+
description:
35+
- The priority of the Port Channel Member policy.
36+
- The APIC defaults to C(32768) when not provided.
37+
- The allowed minimum is C(1) and the allowed maximum is C(65535).
38+
type: int
39+
transmit_rate:
40+
description:
41+
- The transmit rate of the Port Channel Member policy.
42+
- The APIC defaults to C(normal) when not provided.
43+
type: str
44+
choices: [ normal, fast ]
45+
name_alias:
46+
description:
47+
- The alias for the current object.
48+
- This relates to the nameAlias field in ACI.
49+
type: str
50+
state:
51+
description:
52+
- Use C(present) or C(absent) for adding or removing.
53+
- Use C(query) for listing an object or multiple objects.
54+
type: str
55+
choices: [ absent, present, query ]
56+
default: present
57+
extends_documentation_fragment:
58+
- cisco.aci.aci
59+
- cisco.aci.annotation
60+
- cisco.aci.owner
61+
62+
seealso:
63+
- name: APIC Management Information Model reference
64+
description: More information about the internal APIC class B(lacp:IfPol).
65+
link: https://developer.cisco.com/docs/apic-mim-ref/
66+
author:
67+
- Akini Ross (@akinross)
68+
"""
69+
70+
EXAMPLES = r"""
71+
- name: Add a new Port Channel Member policy
72+
cisco.aci.aci_port_channel_member_policy:
73+
host: apic
74+
username: admin
75+
password: SomeSecretPassword
76+
name: ansible_port_channel_member_policy
77+
description: Ansible Port Channel Member policy
78+
priority: 32700
79+
transmit_rate: fast
80+
state: present
81+
delegate_to: localhost
82+
83+
- name: Query a Port Channel Member policy
84+
cisco.aci.aci_port_channel_member_policy:
85+
host: apic
86+
username: admin
87+
password: SomeSecretPassword
88+
name: ansible_port_channel_member_policy
89+
state: query
90+
delegate_to: localhost
91+
register: query_result
92+
93+
- name: Query all Port Channel Member policies
94+
cisco.aci.aci_port_channel_member_policy:
95+
host: apic
96+
username: admin
97+
password: SomeSecretPassword
98+
state: query
99+
delegate_to: localhost
100+
register: query_result
101+
102+
- name: Remove a Port Channel Member policy
103+
cisco.aci.aci_port_channel_member_policy:
104+
host: apic
105+
username: admin
106+
password: SomeSecretPassword
107+
name: my_ntp_policy
108+
state: absent
109+
delegate_to: localhost
110+
"""
111+
112+
RETURN = r"""
113+
current:
114+
description: The existing configuration from the APIC after the module has finished
115+
returned: success
116+
type: list
117+
sample:
118+
[
119+
{
120+
"fvTenant": {
121+
"attributes": {
122+
"descr": "Production environment",
123+
"dn": "uni/tn-production",
124+
"name": "production",
125+
"nameAlias": "",
126+
"ownerKey": "",
127+
"ownerTag": ""
128+
}
129+
}
130+
}
131+
]
132+
error:
133+
description: The error information as returned from the APIC
134+
returned: failure
135+
type: dict
136+
sample:
137+
{
138+
"code": "122",
139+
"text": "unknown managed object class foo"
140+
}
141+
raw:
142+
description: The raw output returned by the APIC REST API (xml or json)
143+
returned: parse error
144+
type: str
145+
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
146+
sent:
147+
description: The actual/minimal configuration pushed to the APIC
148+
returned: info
149+
type: list
150+
sample:
151+
{
152+
"fvTenant": {
153+
"attributes": {
154+
"descr": "Production environment"
155+
}
156+
}
157+
}
158+
previous:
159+
description: The original configuration from the APIC before the module has started
160+
returned: info
161+
type: list
162+
sample:
163+
[
164+
{
165+
"fvTenant": {
166+
"attributes": {
167+
"descr": "Production",
168+
"dn": "uni/tn-production",
169+
"name": "production",
170+
"nameAlias": "",
171+
"ownerKey": "",
172+
"ownerTag": ""
173+
}
174+
}
175+
}
176+
]
177+
proposed:
178+
description: The assembled configuration from the user-provided parameters
179+
returned: info
180+
type: dict
181+
sample:
182+
{
183+
"fvTenant": {
184+
"attributes": {
185+
"descr": "Production environment",
186+
"name": "production"
187+
}
188+
}
189+
}
190+
filter_string:
191+
description: The filter string used for the request
192+
returned: failure or debug
193+
type: str
194+
sample: ?rsp-prop-include=config-only
195+
method:
196+
description: The HTTP method used for the request to the APIC
197+
returned: failure or debug
198+
type: str
199+
sample: POST
200+
response:
201+
description: The HTTP response from the APIC
202+
returned: failure or debug
203+
type: str
204+
sample: OK (30 bytes)
205+
status:
206+
description: The HTTP status from the APIC
207+
returned: failure or debug
208+
type: int
209+
sample: 200
210+
url:
211+
description: The HTTP url used for the request to the APIC
212+
returned: failure or debug
213+
type: str
214+
sample: https://10.11.12.13/api/mo/uni/tn-production.json
215+
"""
216+
217+
from ansible.module_utils.basic import AnsibleModule
218+
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
219+
220+
221+
def main():
222+
argument_spec = aci_argument_spec()
223+
argument_spec.update(aci_annotation_spec())
224+
argument_spec.update(aci_owner_spec())
225+
argument_spec.update(
226+
name=dict(type="str", aliases=["port_channel_member_policy"]),
227+
description=dict(type="str"),
228+
priority=dict(type="int"),
229+
transmit_rate=dict(type="str", choices=["normal", "fast"]),
230+
name_alias=dict(type="str"),
231+
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
232+
)
233+
234+
module = AnsibleModule(
235+
argument_spec=argument_spec,
236+
supports_check_mode=True,
237+
required_if=[
238+
["state", "absent", ["name"]],
239+
["state", "present", ["name"]],
240+
],
241+
)
242+
243+
name = module.params.get("name")
244+
description = module.params.get("description")
245+
priority = module.params.get("priority")
246+
transmit_rate = module.params.get("transmit_rate")
247+
name_alias = module.params.get("name_alias")
248+
state = module.params.get("state")
249+
250+
aci = ACIModule(module)
251+
aci.construct_url(
252+
root_class=dict(
253+
aci_class="lacpIfPol",
254+
aci_rn="infra/lacpifp-{0}".format(name),
255+
module_object=name,
256+
target_filter={"name": name},
257+
),
258+
)
259+
260+
aci.get_existing()
261+
262+
if state == "present":
263+
aci.payload(
264+
aci_class="lacpIfPol",
265+
class_config=dict(
266+
name=name,
267+
descr=description,
268+
prio=priority,
269+
txRate=transmit_rate,
270+
nameAlias=name_alias,
271+
),
272+
)
273+
274+
aci.get_diff(aci_class="lacpIfPol")
275+
276+
aci.post_config()
277+
278+
elif state == "absent":
279+
aci.delete_config()
280+
281+
aci.exit_json()
282+
283+
284+
if __name__ == "__main__":
285+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# No ACI simulator yet, so not enabled
2+
# unsupported

0 commit comments

Comments
 (0)