|
| 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() |
0 commit comments