| 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_fibre_channel_qos_policy |
| 16 |
short_description: Manage Fibre Channel QoS Policies for Cisco Intersight |
| 17 |
description: |
| 18 |
- Create, update, and delete Fibre Channel QoS Policies on Cisco Intersight. |
| 19 |
- Fibre Channel QoS policies configure Quality of Service settings for Fibre Channel virtual interfaces. |
| 20 |
- These policies control bandwidth rate limits, maximum data field size, class of service, and burst traffic. |
| 21 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/FcQosPolicies/get/). |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
state: |
| 25 |
description: |
| 26 |
- If C(present), will verify the resource is present and will create if needed. |
| 27 |
- If C(absent), will verify the resource is absent and will delete if needed. |
| 28 |
type: str |
| 29 |
choices: [present, absent] |
| 30 |
default: present |
| 31 |
organization: |
| 32 |
description: |
| 33 |
- The name of the Organization this resource is assigned to. |
| 34 |
- Policies created within a Custom Organization are applicable only to devices in the same Organization. |
| 35 |
- Use 'default' for the default organization. |
| 36 |
type: str |
| 37 |
default: default |
| 38 |
name: |
| 39 |
description: |
| 40 |
- The name assigned to the Fibre Channel QoS Policy. |
| 41 |
- Must be unique within the organization. |
| 42 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 43 |
type: str |
| 44 |
required: true |
| 45 |
description: |
| 46 |
description: |
| 47 |
- The user-defined description for the Fibre Channel QoS Policy. |
| 48 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 49 |
type: str |
| 50 |
aliases: [descr] |
| 51 |
tags: |
| 52 |
description: |
| 53 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 54 |
type: list |
| 55 |
elements: dict |
| 56 |
rate_limit: |
| 57 |
description: |
| 58 |
- The value in Mbps to use for limiting the data rate on the virtual interface. |
| 59 |
- A value of 0 means no rate limiting. |
| 60 |
- Valid range is 0 to 100000 Mbps. |
| 61 |
type: int |
| 62 |
default: 0 |
| 63 |
max_data_field_size: |
| 64 |
description: |
| 65 |
- The maximum size of the Fibre Channel frame payload bytes that the virtual interface supports. |
| 66 |
- Valid range is 256 to 2112 bytes. |
| 67 |
type: int |
| 68 |
default: 2112 |
| 69 |
cos: |
| 70 |
description: |
| 71 |
- Class of Service to be associated to the traffic on the virtual interface. |
| 72 |
- Valid range is 0 to 6. |
| 73 |
type: int |
| 74 |
default: 3 |
| 75 |
burst: |
| 76 |
description: |
| 77 |
- The burst traffic, in bytes, allowed on the vHBA. |
| 78 |
- Valid range is 1 to 1000000 bytes. |
| 79 |
type: int |
| 80 |
default: 10240 |
| 81 |
author: |
| 82 |
- Ron Gershburg (@rgershbu) |
| 83 |
''' |
| 84 |
|
| 85 |
EXAMPLES = r''' |
| 86 |
- name: Create Fibre Channel QoS Policy with default settings |
| 87 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 88 |
api_private_key: "{{ api_private_key }}" |
| 89 |
api_key_id: "{{ api_key_id }}" |
| 90 |
organization: "default" |
| 91 |
name: "fc-qos-default" |
| 92 |
description: "Fibre Channel QoS policy with default values" |
| 93 |
state: present |
| 94 |
|
| 95 |
- name: Create Fibre Channel QoS Policy with custom settings |
| 96 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 97 |
api_private_key: "{{ api_private_key }}" |
| 98 |
api_key_id: "{{ api_key_id }}" |
| 99 |
organization: "default" |
| 100 |
name: "fc-qos-custom" |
| 101 |
description: "Fibre Channel QoS policy with custom values" |
| 102 |
rate_limit: 10000 |
| 103 |
max_data_field_size: 2048 |
| 104 |
cos: 5 |
| 105 |
burst: 20480 |
| 106 |
tags: |
| 107 |
- Key: Environment |
| 108 |
Value: Production |
| 109 |
state: present |
| 110 |
|
| 111 |
- name: Create Fibre Channel QoS Policy with maximum rate limit |
| 112 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 113 |
api_private_key: "{{ api_private_key }}" |
| 114 |
api_key_id: "{{ api_key_id }}" |
| 115 |
organization: "Engineering" |
| 116 |
name: "fc-qos-high-bandwidth" |
| 117 |
description: "Fibre Channel QoS policy with maximum bandwidth" |
| 118 |
rate_limit: 100000 |
| 119 |
max_data_field_size: 2112 |
| 120 |
cos: 6 |
| 121 |
burst: 1000000 |
| 122 |
state: present |
| 123 |
|
| 124 |
- name: Create Fibre Channel QoS Policy with minimal frame size |
| 125 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 126 |
api_private_key: "{{ api_private_key }}" |
| 127 |
api_key_id: "{{ api_key_id }}" |
| 128 |
organization: "default" |
| 129 |
name: "fc-qos-minimal" |
| 130 |
description: "Fibre Channel QoS policy with minimal frame size" |
| 131 |
rate_limit: 0 |
| 132 |
max_data_field_size: 256 |
| 133 |
cos: 0 |
| 134 |
burst: 1 |
| 135 |
state: present |
| 136 |
|
| 137 |
- name: Update Fibre Channel QoS Policy description |
| 138 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 139 |
api_private_key: "{{ api_private_key }}" |
| 140 |
api_key_id: "{{ api_key_id }}" |
| 141 |
organization: "default" |
| 142 |
name: "fc-qos-default" |
| 143 |
description: "Updated Fibre Channel QoS policy description" |
| 144 |
state: present |
| 145 |
|
| 146 |
- name: Delete Fibre Channel QoS Policy |
| 147 |
cisco.intersight.intersight_fibre_channel_qos_policy: |
| 148 |
api_private_key: "{{ api_private_key }}" |
| 149 |
api_key_id: "{{ api_key_id }}" |
| 150 |
organization: "default" |
| 151 |
name: "fc-qos-default" |
| 152 |
state: absent |
| 153 |
''' |
| 154 |
|
| 155 |
RETURN = r''' |
| 156 |
api_response: |
| 157 |
description: The API response output returned by the specified resource. |
| 158 |
returned: always |
| 159 |
type: dict |
| 160 |
sample: |
| 161 |
"api_response": { |
| 162 |
"Name": "fc-qos-custom", |
| 163 |
"ObjectType": "vnic.FcQosPolicy", |
| 164 |
"RateLimit": 10000, |
| 165 |
"MaxDataFieldSize": 2048, |
| 166 |
"Cos": 5, |
| 167 |
"Burst": 20480, |
| 168 |
"Moid": "1234567890abcdef12345678", |
| 169 |
"Description": "Fibre Channel QoS policy with custom values", |
| 170 |
"Organization": { |
| 171 |
"Moid": "abcdef1234567890abcdef12", |
| 172 |
"ObjectType": "organization.Organization" |
| 173 |
}, |
| 174 |
"Tags": [ |
| 175 |
{ |
| 176 |
"Key": "Environment", |
| 177 |
"Value": "Production" |
| 178 |
} |
| 179 |
] |
| 180 |
} |
| 181 |
''' |
| 182 |
|
| 183 |
|
| 184 |
from ansible.module_utils.basic import AnsibleModule |
| 185 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 186 |
|
| 187 |
|
| 188 |
def validate_parameters(module): |
| 189 |
""" |
| 190 |
Validate module parameters for Fibre Channel QoS policy configuration. |
| 191 |
""" |
| 192 |
if module.params['state'] != 'present': |
| 193 |
return |
| 194 |
# Validate rate_limit range (0-100000) |
| 195 |
rate_limit = module.params.get('rate_limit') |
| 196 |
if rate_limit is not None and (rate_limit < 0 or rate_limit > 100000): |
| 197 |
module.fail_json(msg="Parameter 'rate_limit' must be between 0 and 100000 Mbps") |
| 198 |
# Validate max_data_field_size range (256-2112) |
| 199 |
max_data_field_size = module.params.get('max_data_field_size') |
| 200 |
if max_data_field_size is not None and (max_data_field_size < 256 or max_data_field_size > 2112): |
| 201 |
module.fail_json(msg="Parameter 'max_data_field_size' must be between 256 and 2112 bytes") |
| 202 |
# Validate cos range (0-6) |
| 203 |
cos = module.params.get('cos') |
| 204 |
if cos is not None and (cos < 0 or cos > 6): |
| 205 |
module.fail_json(msg="Parameter 'cos' must be between 0 and 6") |
| 206 |
# Validate burst range (1-1000000) |
| 207 |
burst = module.params.get('burst') |
| 208 |
if burst is not None and (burst < 1 or burst > 1000000): |
| 209 |
module.fail_json(msg="Parameter 'burst' must be between 1 and 1000000 bytes") |
| 210 |
|
| 211 |
|
| 212 |
def main(): |
| 213 |
argument_spec = intersight_argument_spec.copy() |
| 214 |
argument_spec.update( |
| 215 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 216 |
organization=dict(type='str', default='default'), |
| 217 |
name=dict(type='str', required=True), |
| 218 |
description=dict(type='str', aliases=['descr']), |
| 219 |
tags=dict(type='list', elements='dict'), |
| 220 |
rate_limit=dict(type='int', default=0), |
| 221 |
max_data_field_size=dict(type='int', default=2112), |
| 222 |
cos=dict(type='int', default=3), |
| 223 |
burst=dict(type='int', default=10240), |
| 224 |
) |
| 225 |
module = AnsibleModule( |
| 226 |
argument_spec, |
| 227 |
supports_check_mode=True, |
| 228 |
) |
| 229 |
intersight = IntersightModule(module) |
| 230 |
intersight.result['api_response'] = {} |
| 231 |
intersight.result['trace_id'] = '' |
| 232 |
# Validate module parameters |
| 233 |
validate_parameters(module) |
| 234 |
# Resource path used to configure policy |
| 235 |
resource_path = '/vnic/FcQosPolicies' |
| 236 |
# Define API body used in compares or create |
| 237 |
intersight.api_body = { |
| 238 |
'Organization': { |
| 239 |
'Name': module.params['organization'], |
| 240 |
}, |
| 241 |
'Name': module.params['name'], |
| 242 |
} |
| 243 |
if module.params['state'] == 'present': |
| 244 |
intersight.api_body['RateLimit'] = module.params['rate_limit'] |
| 245 |
intersight.api_body['MaxDataFieldSize'] = module.params['max_data_field_size'] |
| 246 |
intersight.api_body['Cos'] = module.params['cos'] |
| 247 |
intersight.api_body['Burst'] = module.params['burst'] |
| 248 |
intersight.set_tags_and_description() |
| 249 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 250 |
module.exit_json(**intersight.result) |
| 251 |
|
| 252 |
|
| 253 |
if __name__ == '__main__': |
| 254 |
main() |