| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: (c) 2017, Bruno Calogero <[email protected]> |
| 5 |
# Copyright: (c) 2020, Shreyas Srish <[email protected]> |
| 6 |
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"} |
| 13 |
|
| 14 |
DOCUMENTATION = r""" |
| 15 |
--- |
| 16 |
module: aci_interface_policy_leaf_profile |
| 17 |
short_description: Manage fabric interface policy leaf profiles (infra:AccPortP) |
| 18 |
description: |
| 19 |
- Manage fabric interface policy leaf profiles on Cisco ACI fabrics. |
| 20 |
options: |
| 21 |
interface_profile: |
| 22 |
description: |
| 23 |
- The name of the Fabric access policy leaf interface profile. |
| 24 |
type: str |
| 25 |
aliases: [ name, leaf_interface_profile_name, leaf_interface_profile, interface_profile_name ] |
| 26 |
description: |
| 27 |
description: |
| 28 |
- Description for the Fabric access policy leaf interface profile. |
| 29 |
type: str |
| 30 |
aliases: [ descr ] |
| 31 |
state: |
| 32 |
description: |
| 33 |
- Use C(present) or C(absent) for adding or removing. |
| 34 |
- Use C(query) for listing an object or multiple objects. |
| 35 |
type: str |
| 36 |
choices: [ absent, present, query ] |
| 37 |
default: present |
| 38 |
name_alias: |
| 39 |
description: |
| 40 |
- The alias for the current object. This relates to the nameAlias field in ACI. |
| 41 |
type: str |
| 42 |
type: |
| 43 |
description: |
| 44 |
- The type of profile to be created. |
| 45 |
type: str |
| 46 |
choices: [ fex, leaf ] |
| 47 |
default: leaf |
| 48 |
extends_documentation_fragment: |
| 49 |
- cisco.aci.aci |
| 50 |
- cisco.aci.annotation |
| 51 |
- cisco.aci.owner |
| 52 |
|
| 53 |
seealso: |
| 54 |
- name: APIC Management Information Model reference |
| 55 |
description: More information about the internal APIC class B(infra:AccPortP). |
| 56 |
link: https://developer.cisco.com/docs/apic-mim-ref/ |
| 57 |
author: |
| 58 |
- Bruno Calogero (@brunocalogero) |
| 59 |
- Shreyas Srish (@shrsr) |
| 60 |
""" |
| 61 |
|
| 62 |
EXAMPLES = r""" |
| 63 |
- name: Add a new leaf_interface_profile |
| 64 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 65 |
host: apic |
| 66 |
username: admin |
| 67 |
password: SomeSecretPassword |
| 68 |
interface_profile: leafintprfname |
| 69 |
description: leafintprfname description |
| 70 |
state: present |
| 71 |
delegate_to: localhost |
| 72 |
|
| 73 |
- name: Add a new leaf_interface_profile of type fex |
| 74 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 75 |
host: apic |
| 76 |
username: admin |
| 77 |
password: SomeSecretPassword |
| 78 |
interface_profile: leafintprfname_fex |
| 79 |
type: fex |
| 80 |
description: leafintprfname description |
| 81 |
state: present |
| 82 |
delegate_to: localhost |
| 83 |
|
| 84 |
- name: Remove a leaf_interface_profile |
| 85 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 86 |
host: apic |
| 87 |
username: admin |
| 88 |
password: SomeSecretPassword |
| 89 |
interface_profile: leafintprfname |
| 90 |
state: absent |
| 91 |
delegate_to: localhost |
| 92 |
|
| 93 |
- name: Remove a leaf_interface_profile of type fex |
| 94 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 95 |
host: apic |
| 96 |
username: admin |
| 97 |
password: SomeSecretPassword |
| 98 |
interface_profile: leafintprfname_fex |
| 99 |
type: fex |
| 100 |
state: absent |
| 101 |
delegate_to: localhost |
| 102 |
|
| 103 |
- name: Query a leaf_interface_profile |
| 104 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 105 |
host: apic |
| 106 |
username: admin |
| 107 |
password: SomeSecretPassword |
| 108 |
interface_profile: leafintprfname |
| 109 |
state: query |
| 110 |
delegate_to: localhost |
| 111 |
register: query_result |
| 112 |
|
| 113 |
- name: Query a leaf_interface_profile of type fex |
| 114 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 115 |
host: apic |
| 116 |
username: admin |
| 117 |
password: SomeSecretPassword |
| 118 |
interface_profile: leafintprfname_fex |
| 119 |
type: fex |
| 120 |
state: query |
| 121 |
delegate_to: localhost |
| 122 |
register: query_result |
| 123 |
|
| 124 |
- name: Query all leaf_interface_profiles |
| 125 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 126 |
host: apic |
| 127 |
username: admin |
| 128 |
password: SomeSecretPassword |
| 129 |
state: query |
| 130 |
delegate_to: localhost |
| 131 |
|
| 132 |
- name: Query all leaf_interface_profiles of type fex |
| 133 |
cisco.aci.aci_interface_policy_leaf_profile: |
| 134 |
host: apic |
| 135 |
username: admin |
| 136 |
password: SomeSecretPassword |
| 137 |
type: fex |
| 138 |
state: query |
| 139 |
delegate_to: localhost |
| 140 |
""" |
| 141 |
|
| 142 |
RETURN = r""" |
| 143 |
current: |
| 144 |
description: The existing configuration from the APIC after the module has finished |
| 145 |
returned: success |
| 146 |
type: list |
| 147 |
sample: |
| 148 |
[ |
| 149 |
{ |
| 150 |
"fvTenant": { |
| 151 |
"attributes": { |
| 152 |
"descr": "Production environment", |
| 153 |
"dn": "uni/tn-production", |
| 154 |
"name": "production", |
| 155 |
"nameAlias": "", |
| 156 |
"ownerKey": "", |
| 157 |
"ownerTag": "" |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
] |
| 162 |
error: |
| 163 |
description: The error information as returned from the APIC |
| 164 |
returned: failure |
| 165 |
type: dict |
| 166 |
sample: |
| 167 |
{ |
| 168 |
"code": "122", |
| 169 |
"text": "unknown managed object class foo" |
| 170 |
} |
| 171 |
raw: |
| 172 |
description: The raw output returned by the APIC REST API (xml or json) |
| 173 |
returned: parse error |
| 174 |
type: str |
| 175 |
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>' |
| 176 |
sent: |
| 177 |
description: The actual/minimal configuration pushed to the APIC |
| 178 |
returned: info |
| 179 |
type: list |
| 180 |
sample: |
| 181 |
{ |
| 182 |
"fvTenant": { |
| 183 |
"attributes": { |
| 184 |
"descr": "Production environment" |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
previous: |
| 189 |
description: The original configuration from the APIC before the module has started |
| 190 |
returned: info |
| 191 |
type: list |
| 192 |
sample: |
| 193 |
[ |
| 194 |
{ |
| 195 |
"fvTenant": { |
| 196 |
"attributes": { |
| 197 |
"descr": "Production", |
| 198 |
"dn": "uni/tn-production", |
| 199 |
"name": "production", |
| 200 |
"nameAlias": "", |
| 201 |
"ownerKey": "", |
| 202 |
"ownerTag": "" |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
] |
| 207 |
proposed: |
| 208 |
description: The assembled configuration from the user-provided parameters |
| 209 |
returned: info |
| 210 |
type: dict |
| 211 |
sample: |
| 212 |
{ |
| 213 |
"fvTenant": { |
| 214 |
"attributes": { |
| 215 |
"descr": "Production environment", |
| 216 |
"name": "production" |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
filter_string: |
| 221 |
description: The filter string used for the request |
| 222 |
returned: failure or debug |
| 223 |
type: str |
| 224 |
sample: ?rsp-prop-include=config-only |
| 225 |
method: |
| 226 |
description: The HTTP method used for the request to the APIC |
| 227 |
returned: failure or debug |
| 228 |
type: str |
| 229 |
sample: POST |
| 230 |
response: |
| 231 |
description: The HTTP response from the APIC |
| 232 |
returned: failure or debug |
| 233 |
type: str |
| 234 |
sample: OK (30 bytes) |
| 235 |
status: |
| 236 |
description: The HTTP status from the APIC |
| 237 |
returned: failure or debug |
| 238 |
type: int |
| 239 |
sample: 200 |
| 240 |
url: |
| 241 |
description: The HTTP url used for the request to the APIC |
| 242 |
returned: failure or debug |
| 243 |
type: str |
| 244 |
sample: https://10.11.12.13/api/mo/uni/tn-production.json |
| 245 |
""" |
| 246 |
|
| 247 |
from ansible.module_utils.basic import AnsibleModule |
| 248 |
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec |
| 249 |
|
| 250 |
|
| 251 |
def main(): |
| 252 |
argument_spec = aci_argument_spec() |
| 253 |
argument_spec.update(aci_annotation_spec()) |
| 254 |
argument_spec.update(aci_owner_spec()) |
| 255 |
argument_spec.update( |
| 256 |
interface_profile=dict(type="str", aliases=["name", "leaf_interface_profile_name", "leaf_interface_profile", "interface_profile_name"]), |
| 257 |
description=dict(type="str", aliases=["descr"]), |
| 258 |
state=dict(type="str", default="present", choices=["absent", "present", "query"]), |
| 259 |
name_alias=dict(type="str"), |
| 260 |
type=dict(type="str", default="leaf", choices=["fex", "leaf"]), |
| 261 |
) |
| 262 |
|
| 263 |
module = AnsibleModule( |
| 264 |
argument_spec=argument_spec, |
| 265 |
supports_check_mode=True, |
| 266 |
required_if=[ |
| 267 |
["state", "absent", ["interface_profile"]], |
| 268 |
["state", "present", ["interface_profile"]], |
| 269 |
], |
| 270 |
) |
| 271 |
|
| 272 |
interface_profile = module.params.get("interface_profile") |
| 273 |
description = module.params.get("description") |
| 274 |
state = module.params.get("state") |
| 275 |
name_alias = module.params.get("name_alias") |
| 276 |
type_profile = module.params.get("type") |
| 277 |
|
| 278 |
aci = ACIModule(module) |
| 279 |
aci_class = "infraAccPortP" |
| 280 |
aci_rn = "accportprof" |
| 281 |
if type_profile == "fex": |
| 282 |
aci_class = "infraFexP" |
| 283 |
aci_rn = "fexprof" |
| 284 |
aci.construct_url( |
| 285 |
root_class=dict( |
| 286 |
aci_class=aci_class, |
| 287 |
aci_rn="infra/" + aci_rn + "-{0}".format(interface_profile), |
| 288 |
module_object=interface_profile, |
| 289 |
target_filter={"name": interface_profile}, |
| 290 |
), |
| 291 |
) |
| 292 |
|
| 293 |
aci.get_existing() |
| 294 |
|
| 295 |
if state == "present": |
| 296 |
aci.payload( |
| 297 |
aci_class=aci_class, |
| 298 |
class_config=dict( |
| 299 |
name=interface_profile, |
| 300 |
descr=description, |
| 301 |
nameAlias=name_alias, |
| 302 |
), |
| 303 |
) |
| 304 |
|
| 305 |
aci.get_diff(aci_class=aci_class) |
| 306 |
|
| 307 |
aci.post_config() |
| 308 |
|
| 309 |
elif state == "absent": |
| 310 |
aci.delete_config() |
| 311 |
|
| 312 |
aci.exit_json() |
| 313 |
|
| 314 |
|
| 315 |
if __name__ == "__main__": |
| 316 |
main() |