| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 10 |
'status': ['preview'], |
| 11 |
'supported_by': 'community'} |
| 12 |
|
| 13 |
DOCUMENTATION = r''' |
| 14 |
--- |
| 15 |
module: intersight_link_aggregation_policy |
| 16 |
short_description: Link Aggregation Policy configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- Manages Link Aggregation Policy configuration on Cisco Intersight. |
| 19 |
- A policy to configure LACP (Link Aggregation Control Protocol) settings for link aggregation on Cisco Intersight managed fabric interconnects. |
| 20 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/LinkAggregationPolicies/get/). |
| 21 |
extends_documentation_fragment: intersight |
| 22 |
options: |
| 23 |
state: |
| 24 |
description: |
| 25 |
- If C(present), will verify the resource is present and will create if needed. |
| 26 |
- If C(absent), will verify the resource is absent and will delete if needed. |
| 27 |
type: str |
| 28 |
choices: [present, absent] |
| 29 |
default: present |
| 30 |
organization: |
| 31 |
description: |
| 32 |
- The name of the Organization this resource is assigned to. |
| 33 |
- Profiles, Policies, and Pools that are created within a Custom Organization are applicable only to devices in the same Organization. |
| 34 |
type: str |
| 35 |
default: default |
| 36 |
name: |
| 37 |
description: |
| 38 |
- The name assigned to the Link Aggregation Policy. |
| 39 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 40 |
type: str |
| 41 |
required: true |
| 42 |
description: |
| 43 |
description: |
| 44 |
- The user-defined description for the Link Aggregation Policy. |
| 45 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 46 |
type: str |
| 47 |
aliases: [descr] |
| 48 |
tags: |
| 49 |
description: |
| 50 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 51 |
type: list |
| 52 |
elements: dict |
| 53 |
suspend_individual: |
| 54 |
description: |
| 55 |
- Flag tells the switch whether to suspend the port if it didn't receive LACP PDU. |
| 56 |
- If enabled, the switch will suspend the port in the port channel if LACP PDUs are not received. |
| 57 |
type: bool |
| 58 |
default: false |
| 59 |
lacp_rate: |
| 60 |
description: |
| 61 |
- Flag used to indicate whether LACP PDUs are to be sent 'fast', i.e., every 1 second. |
| 62 |
- C(normal) - LACP PDUs are sent every 30 seconds. |
| 63 |
- C(fast) - LACP PDUs are sent every 1 second. |
| 64 |
type: str |
| 65 |
choices: [normal, fast] |
| 66 |
default: normal |
| 67 |
author: |
| 68 |
- Ron Gershburg (@rgershbu) |
| 69 |
''' |
| 70 |
|
| 71 |
EXAMPLES = r''' |
| 72 |
- name: Create a Link Aggregation Policy with default settings |
| 73 |
cisco.intersight.intersight_link_aggregation_policy: |
| 74 |
api_private_key: "{{ api_private_key }}" |
| 75 |
api_key_id: "{{ api_key_id }}" |
| 76 |
organization: "default" |
| 77 |
name: "LinkAgg-Policy-01" |
| 78 |
description: "Link aggregation policy with default LACP settings" |
| 79 |
tags: |
| 80 |
- Key: "Site" |
| 81 |
Value: "DataCenter-A" |
| 82 |
state: present |
| 83 |
|
| 84 |
- name: Create a Link Aggregation Policy with fast LACP rate |
| 85 |
cisco.intersight.intersight_link_aggregation_policy: |
| 86 |
api_private_key: "{{ api_private_key }}" |
| 87 |
api_key_id: "{{ api_key_id }}" |
| 88 |
name: "LinkAgg-Fast-Policy" |
| 89 |
description: "Link aggregation policy with fast LACP rate" |
| 90 |
lacp_rate: fast |
| 91 |
suspend_individual: true |
| 92 |
state: present |
| 93 |
|
| 94 |
- name: Create a Link Aggregation Policy with normal LACP rate and suspend individual disabled |
| 95 |
cisco.intersight.intersight_link_aggregation_policy: |
| 96 |
api_private_key: "{{ api_private_key }}" |
| 97 |
api_key_id: "{{ api_key_id }}" |
| 98 |
name: "LinkAgg-Normal-Policy" |
| 99 |
lacp_rate: normal |
| 100 |
suspend_individual: false |
| 101 |
state: present |
| 102 |
|
| 103 |
- name: Update a Link Aggregation Policy |
| 104 |
cisco.intersight.intersight_link_aggregation_policy: |
| 105 |
api_private_key: "{{ api_private_key }}" |
| 106 |
api_key_id: "{{ api_key_id }}" |
| 107 |
name: "LinkAgg-Policy-01" |
| 108 |
description: "Updated link aggregation policy" |
| 109 |
lacp_rate: fast |
| 110 |
suspend_individual: true |
| 111 |
state: present |
| 112 |
|
| 113 |
- name: Delete a Link Aggregation Policy |
| 114 |
cisco.intersight.intersight_link_aggregation_policy: |
| 115 |
api_private_key: "{{ api_private_key }}" |
| 116 |
api_key_id: "{{ api_key_id }}" |
| 117 |
name: "LinkAgg-Policy-01" |
| 118 |
state: absent |
| 119 |
''' |
| 120 |
|
| 121 |
RETURN = r''' |
| 122 |
api_response: |
| 123 |
description: The API response output returned by the specified resource. |
| 124 |
returned: always |
| 125 |
type: dict |
| 126 |
sample: |
| 127 |
"api_response": { |
| 128 |
"Name": "LinkAgg-Policy-01", |
| 129 |
"ObjectType": "fabric.LinkAggregationPolicy", |
| 130 |
"SuspendIndividual": false, |
| 131 |
"LacpRate": "normal", |
| 132 |
"Tags": [ |
| 133 |
{ |
| 134 |
"Key": "Site", |
| 135 |
"Value": "DataCenter-A" |
| 136 |
} |
| 137 |
] |
| 138 |
} |
| 139 |
''' |
| 140 |
|
| 141 |
from ansible.module_utils.basic import AnsibleModule |
| 142 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 143 |
|
| 144 |
|
| 145 |
def main(): |
| 146 |
argument_spec = intersight_argument_spec.copy() |
| 147 |
argument_spec.update( |
| 148 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 149 |
organization=dict(type='str', default='default'), |
| 150 |
name=dict(type='str', required=True), |
| 151 |
description=dict(type='str', aliases=['descr']), |
| 152 |
tags=dict(type='list', elements='dict'), |
| 153 |
suspend_individual=dict(type='bool', default=False), |
| 154 |
lacp_rate=dict(type='str', choices=['normal', 'fast'], default='normal') |
| 155 |
) |
| 156 |
module = AnsibleModule( |
| 157 |
argument_spec, |
| 158 |
supports_check_mode=True |
| 159 |
) |
| 160 |
|
| 161 |
intersight = IntersightModule(module) |
| 162 |
intersight.result['api_response'] = {} |
| 163 |
intersight.result['trace_id'] = '' |
| 164 |
|
| 165 |
# Resource path used to configure policy |
| 166 |
resource_path = '/fabric/LinkAggregationPolicies' |
| 167 |
|
| 168 |
# Define API body used in compares or create |
| 169 |
intersight.api_body = { |
| 170 |
'Organization': { |
| 171 |
'Name': intersight.module.params['organization'], |
| 172 |
}, |
| 173 |
'Name': intersight.module.params['name'], |
| 174 |
} |
| 175 |
|
| 176 |
if intersight.module.params['state'] == 'present': |
| 177 |
intersight.set_tags_and_description() |
| 178 |
intersight.api_body['SuspendIndividual'] = intersight.module.params['suspend_individual'] |
| 179 |
intersight.api_body['LacpRate'] = intersight.module.params['lacp_rate'] |
| 180 |
|
| 181 |
# Configure the policy |
| 182 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 183 |
|
| 184 |
module.exit_json(**intersight.result) |
| 185 |
|
| 186 |
|
| 187 |
if __name__ == '__main__': |
| 188 |
main() |