Skip to content

Commit e5baef7

Browse files
[minor_change] Add aci_system_connectivity_preference module (#601)
1 parent ef1e466 commit e5baef7

File tree

3 files changed

+357
-0
lines changed

3 files changed

+357
-0
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# Copyright: (c) 2024, David Neilan (@dneilan-intel) <[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 = {
12+
"metadata_version": "1.1",
13+
"status": ["preview"],
14+
"supported_by": "certified",
15+
}
16+
17+
DOCUMENTATION = r"""
18+
---
19+
module: aci_system_connectivity_preference
20+
short_description: APIC Connectivity Preferences (mgmt:ConnectivityPrefs)
21+
description:
22+
- Manages APIC Connectivity Preferences on Cisco ACI fabrics.
23+
options:
24+
interface_preference:
25+
description:
26+
- Interface to use for external connection.
27+
type: str
28+
choices: [ inband, ooband ]
29+
aliases: [ interface_pref, int_pref, external_connection ]
30+
31+
state:
32+
description:
33+
- Use C(present) for updating.
34+
- Use C(query) for listing an object.
35+
type: str
36+
choices: [ present, query ]
37+
default: present
38+
39+
extends_documentation_fragment:
40+
- cisco.aci.aci
41+
- cisco.aci.annotation
42+
- cisco.aci.owner
43+
44+
seealso:
45+
- name: APIC Management Information Model reference
46+
description: More information about the internal APIC class B(mgmt:ConnectivityPrefs).
47+
link: https://developer.cisco.com/docs/apic-mim-ref/
48+
49+
author:
50+
- David Neilan (@dneilan-intel)
51+
"""
52+
53+
EXAMPLES = r"""
54+
- name: Configure Out-of-band Connectivity Preference
55+
cisco.aci.aci_system_connectivity_preference:
56+
host: apic
57+
username: admin
58+
password: SomeSecretPassword
59+
interface_preference: ooband
60+
state: present
61+
delegate_to: localhost
62+
63+
- name: Configure In-band Connectivity Preference
64+
cisco.aci.aci_system_connectivity_preference:
65+
host: apic
66+
username: admin
67+
password: SomeSecretPassword
68+
interface_preference: inband
69+
state: present
70+
delegate_to: localhost
71+
72+
- name: Query Management Connectivity Preference
73+
cisco.aci.aci_system_connectivity_preference:
74+
host: apic
75+
username: admin
76+
password: SomeSecretPassword
77+
state: query
78+
delegate_to: localhost
79+
"""
80+
81+
RETURN = r"""
82+
current:
83+
description: The existing configuration from the APIC after the module has finished
84+
returned: success
85+
type: list
86+
sample:
87+
[
88+
{
89+
"mgmtConnectivityPrefs": {
90+
"attributes": {
91+
"annotation": "",
92+
"childAction": "",
93+
"descr": "",
94+
"dn": "uni/fabric/connectivityPrefs",
95+
"extMngdBy": "",
96+
"interfacePref": "inband",
97+
"lcOwn": "local",
98+
"modTs": "2023-11-14T16:25:32.629+00:00",
99+
"name": "default",
100+
"nameAlias": "",
101+
"ownerKey": "",
102+
"ownerTag": "",
103+
"status": "",
104+
"uid": "0"
105+
}
106+
}
107+
}
108+
]
109+
error:
110+
description: The error information as returned from the APIC
111+
returned: failure
112+
type: dict
113+
sample:
114+
{
115+
"code": "120",
116+
"text": "unknown property value foo, name interfacePref, class mgmtConnectivityPrefs [(Dn0)] Dn0=, "
117+
}
118+
raw:
119+
description: The raw output returned by the APIC REST API (xml or json)
120+
returned: parse error
121+
type: str
122+
sample:
123+
{
124+
"totalCount": "1",
125+
"imdata": [
126+
{
127+
"error": {
128+
"attributes": {
129+
"code": "120",
130+
"text": "unknown property value foo, name interfacePref, class mgmtConnectivityPrefs [(Dn0)] Dn0=, "
131+
}
132+
}
133+
}
134+
]
135+
}
136+
sent:
137+
description: The actual/minimal configuration pushed to the APIC
138+
returned: info
139+
type: list
140+
sample:
141+
{
142+
"mgmtConnectivityPrefs": {
143+
"attributes": {
144+
"interfacePref": "inband"
145+
}
146+
}
147+
}
148+
previous:
149+
description: The original configuration from the APIC before the module has started
150+
returned: info
151+
type: list
152+
sample:
153+
[
154+
{
155+
"mgmtConnectivityPrefs": {
156+
"attributes": {
157+
"annotation": "",
158+
"descr": "",
159+
"dn": "uni/fabric/connectivityPrefs",
160+
"interfacePref": "ooband",
161+
"name": "default",
162+
"nameAlias": "",
163+
"ownerKey": "",
164+
"ownerTag": ""
165+
}
166+
}
167+
}
168+
]
169+
proposed:
170+
description: The assembled configuration from the user-provided parameters
171+
returned: info
172+
type: dict
173+
sample:
174+
{
175+
"mgmtConnectivityPrefs": {
176+
"attributes": {
177+
"interfacePref": "inband"
178+
}
179+
}
180+
}
181+
filter_string:
182+
description: The filter string used for the request
183+
returned: failure or debug
184+
type: str
185+
sample: ?rsp-prop-include=config-only
186+
method:
187+
description: The HTTP method used for the request to the APIC
188+
returned: failure or debug
189+
type: str
190+
sample: POST
191+
response:
192+
description: The HTTP response from the APIC
193+
returned: failure or debug
194+
type: str
195+
sample: OK (30 bytes)
196+
status:
197+
description: The HTTP status from the APIC
198+
returned: failure or debug
199+
type: int
200+
sample: 200
201+
url:
202+
description: The HTTP url used for the request to the APIC
203+
returned: failure or debug
204+
type: str
205+
sample: https://10.11.12.13/api/mo/uni/tn-production.json
206+
"""
207+
208+
from ansible.module_utils.basic import AnsibleModule
209+
from ansible_collections.cisco.aci.plugins.module_utils.aci import (
210+
ACIModule,
211+
aci_argument_spec,
212+
aci_annotation_spec,
213+
aci_owner_spec,
214+
)
215+
216+
217+
def main():
218+
argument_spec = aci_argument_spec()
219+
argument_spec.update(aci_annotation_spec())
220+
argument_spec.update(aci_owner_spec())
221+
argument_spec.update(
222+
interface_preference=dict(
223+
type="str",
224+
choices=["ooband", "inband"],
225+
aliases=["interface_pref", "int_pref", "external_connection"],
226+
),
227+
state=dict(type="str", default="present", choices=["present", "query"]),
228+
)
229+
230+
module = AnsibleModule(
231+
argument_spec=argument_spec,
232+
supports_check_mode=True,
233+
required_if=[
234+
["state", "present", ["interface_preference"]],
235+
],
236+
)
237+
aci = ACIModule(module)
238+
239+
interface_preference = module.params.get("interface_preference")
240+
state = module.params.get("state")
241+
242+
aci.construct_url(
243+
root_class=dict(
244+
aci_class="mgmtConnectivityPrefs",
245+
aci_rn="fabric/connectivityPrefs",
246+
),
247+
)
248+
aci.get_existing()
249+
250+
if state == "present":
251+
aci.payload(
252+
aci_class="mgmtConnectivityPrefs",
253+
class_config=dict(interfacePref=interface_preference),
254+
)
255+
256+
aci.get_diff(aci_class="mgmtConnectivityPrefs")
257+
258+
aci.post_config()
259+
260+
aci.exit_json()
261+
262+
263+
if __name__ == "__main__":
264+
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
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Test code for the ACI modules
2+
# Copyright: (c) 2024, David Neilan (@dneilan-intel) <[email protected]>
3+
4+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
- name: Test that we have an ACI APIC host, ACI username and ACI password
7+
ansible.builtin.fail:
8+
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
9+
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined
10+
11+
- name: Set vars
12+
ansible.builtin.set_fact:
13+
aci_info: &aci_info
14+
host: "{{ aci_hostname }}"
15+
username: "{{ aci_username }}"
16+
password: "{{ aci_password }}"
17+
validate_certs: '{{ aci_validate_certs | default(false) }}'
18+
use_ssl: '{{ aci_use_ssl | default(true) }}'
19+
use_proxy: '{{ aci_use_proxy | default(true) }}'
20+
output_level: '{{ aci_output_level | default("info") }}'
21+
22+
# CLEANUP ENVIRONMENT
23+
- name: Initialize system connectivity preference
24+
cisco.aci.aci_system_connectivity_preference: &aci_system_connectivity_preference_initial
25+
<<: *aci_info
26+
interface_preference: inband
27+
28+
# UPDATE SYSTEM CONNECTIVITY PREFERENCE
29+
- name: Update system connectivity preference (check mode)
30+
cisco.aci.aci_system_connectivity_preference: &aci_connectivity_preference
31+
<<: *aci_info
32+
interface_preference: ooband
33+
check_mode: true
34+
register: cm_update_connectivity_preference
35+
36+
- name: Update system connectivity preference
37+
cisco.aci.aci_system_connectivity_preference:
38+
<<: *aci_connectivity_preference
39+
register: nm_update_connectivity_preference
40+
41+
- name: Update system connectivity preference again
42+
cisco.aci.aci_system_connectivity_preference:
43+
<<: *aci_connectivity_preference
44+
register: nm_update_connectivity_preference_again
45+
46+
- name: Verify system connectivity preference
47+
ansible.builtin.assert:
48+
that:
49+
- cm_update_connectivity_preference is changed
50+
- cm_update_connectivity_preference.proposed.mgmtConnectivityPrefs.attributes.interfacePref == "ooband"
51+
- cm_update_connectivity_preference.current.0.mgmtConnectivityPrefs.attributes.interfacePref == "inband"
52+
- nm_update_connectivity_preference is changed
53+
- nm_update_connectivity_preference.current.0.mgmtConnectivityPrefs.attributes.interfacePref == "ooband"
54+
- nm_update_connectivity_preference.previous.0.mgmtConnectivityPrefs.attributes.interfacePref == "inband"
55+
- nm_update_connectivity_preference_again is not changed
56+
- nm_update_connectivity_preference_again.current.0.mgmtConnectivityPrefs.attributes.interfacePref == "ooband"
57+
- nm_update_connectivity_preference_again.previous.0.mgmtConnectivityPrefs.attributes.interfacePref == "ooband"
58+
59+
# QUERY SYSTEM CONNECTIVITY PREFERENCE
60+
- name: Query system connectivity preference
61+
cisco.aci.aci_system_connectivity_preference:
62+
<<: *aci_connectivity_preference
63+
state: query
64+
register: query
65+
66+
- name: Verify system connectivity preference query
67+
ansible.builtin.assert:
68+
that:
69+
- query is not changed
70+
- query.current.0.mgmtConnectivityPrefs.attributes.interfacePref == "ooband"
71+
72+
# ERROR SYSTEM CONNECTIVITY PREFERENCE
73+
- name: Update system connectivity preference (error)
74+
cisco.aci.aci_system_connectivity_preference:
75+
<<: *aci_info
76+
interface_preference: foo
77+
ignore_errors: true
78+
register: err_update_system_connectivity_preference
79+
80+
- name: Verify system connectivity preference error
81+
ansible.builtin.assert:
82+
that:
83+
- err_update_system_connectivity_preference is failed
84+
- err_update_system_connectivity_preference.msg == expected_failure_message
85+
vars:
86+
expected_failure_message: "value of interface_preference must be one of: ooband, inband, got: foo"
87+
88+
# CLEANUP ENVIRONMENT
89+
- name: Revert system connectivity preference
90+
cisco.aci.aci_system_connectivity_preference:
91+
<<: *aci_system_connectivity_preference_initial

0 commit comments

Comments
 (0)