| 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_ethernet_qos_policy |
| 16 |
short_description: Ethernet QoS Policy configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- Manages Ethernet QoS Policy configuration on Cisco Intersight. |
| 19 |
- A policy to configure Quality of Service settings for Ethernet virtual interfaces on Cisco Intersight managed servers. |
| 20 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/EthQosPolicy/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 Ethernet QoS 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 Ethernet QoS 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 |
mtu: |
| 54 |
description: |
| 55 |
- The Maximum Transmission Unit (MTU) or packet size that the virtual interface accepts. |
| 56 |
- The acceptable range is 1500-9000. |
| 57 |
type: int |
| 58 |
default: 1500 |
| 59 |
cos: |
| 60 |
description: |
| 61 |
- Class of Service to be associated to the traffic on the virtual interface. |
| 62 |
- The acceptable range is 0-6. |
| 63 |
type: int |
| 64 |
default: 0 |
| 65 |
priority: |
| 66 |
description: |
| 67 |
- The priority matching the System QoS specified in the fabric profile. |
| 68 |
type: str |
| 69 |
choices: ['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'] |
| 70 |
default: 'Best Effort' |
| 71 |
trust_host_cos: |
| 72 |
description: |
| 73 |
- Enables usage of the Class of Service provided by the operating system. |
| 74 |
type: bool |
| 75 |
default: false |
| 76 |
rate_limit: |
| 77 |
description: |
| 78 |
- The value in Mbps (0-10G/40G/100G depending on Adapter Model) to use for limiting the data rate on the virtual interface. |
| 79 |
- The range is between 0 and 100000. |
| 80 |
type: int |
| 81 |
default: 0 |
| 82 |
burst: |
| 83 |
description: |
| 84 |
- The burst traffic, in bytes, allowed on the vNIC. |
| 85 |
- The range is between 1 to 1000000. |
| 86 |
type: int |
| 87 |
default: 10240 |
| 88 |
author: |
| 89 |
- Ron Gershburg (@rgershbu) |
| 90 |
''' |
| 91 |
|
| 92 |
EXAMPLES = r''' |
| 93 |
- name: Create an Ethernet QoS Policy with default settings |
| 94 |
cisco.intersight.intersight_ethernet_qos_policy: |
| 95 |
api_private_key: "{{ api_private_key }}" |
| 96 |
api_key_id: "{{ api_key_id }}" |
| 97 |
organization: "default" |
| 98 |
name: "default-qos-policy" |
| 99 |
description: "Default Ethernet QoS policy" |
| 100 |
state: present |
| 101 |
|
| 102 |
- name: Create an Ethernet QoS Policy with Platinum priority and trust host CoS |
| 103 |
cisco.intersight.intersight_ethernet_qos_policy: |
| 104 |
api_private_key: "{{ api_private_key }}" |
| 105 |
api_key_id: "{{ api_key_id }}" |
| 106 |
organization: "default" |
| 107 |
name: "platinum-qos-policy" |
| 108 |
description: "High priority Ethernet QoS policy" |
| 109 |
tags: |
| 110 |
- Key: "Environment" |
| 111 |
Value: "Production" |
| 112 |
mtu: 9000 |
| 113 |
cos: 5 |
| 114 |
priority: "Platinum" |
| 115 |
trust_host_cos: true |
| 116 |
rate_limit: 10000 |
| 117 |
burst: 100000 |
| 118 |
state: present |
| 119 |
|
| 120 |
- name: Create an Ethernet QoS Policy with custom settings |
| 121 |
cisco.intersight.intersight_ethernet_qos_policy: |
| 122 |
api_private_key: "{{ api_private_key }}" |
| 123 |
api_key_id: "{{ api_key_id }}" |
| 124 |
name: "custom-qos-policy" |
| 125 |
description: "Custom Ethernet QoS policy for specific workload" |
| 126 |
mtu: 1500 |
| 127 |
cos: 3 |
| 128 |
priority: "Gold" |
| 129 |
trust_host_cos: false |
| 130 |
rate_limit: 5000 |
| 131 |
burst: 50000 |
| 132 |
state: present |
| 133 |
|
| 134 |
- name: Delete an Ethernet QoS Policy |
| 135 |
cisco.intersight.intersight_ethernet_qos_policy: |
| 136 |
api_private_key: "{{ api_private_key }}" |
| 137 |
api_key_id: "{{ api_key_id }}" |
| 138 |
name: "custom-qos-policy" |
| 139 |
state: absent |
| 140 |
''' |
| 141 |
|
| 142 |
RETURN = r''' |
| 143 |
api_response: |
| 144 |
description: The API response output returned by the specified resource. |
| 145 |
returned: always |
| 146 |
type: dict |
| 147 |
sample: |
| 148 |
"api_response": { |
| 149 |
"Name": "platinum-qos-policy", |
| 150 |
"ObjectType": "vnic.EthQosPolicy", |
| 151 |
"Mtu": 9000, |
| 152 |
"Cos": 5, |
| 153 |
"Priority": "Platinum", |
| 154 |
"TrustHostCos": true, |
| 155 |
"RateLimit": 10000, |
| 156 |
"Burst": 100000, |
| 157 |
"Tags": [ |
| 158 |
{ |
| 159 |
"Key": "Environment", |
| 160 |
"Value": "Production" |
| 161 |
} |
| 162 |
] |
| 163 |
} |
| 164 |
''' |
| 165 |
|
| 166 |
|
| 167 |
from ansible.module_utils.basic import AnsibleModule |
| 168 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 169 |
|
| 170 |
|
| 171 |
def validate_input(module): |
| 172 |
"""Validate input parameters""" |
| 173 |
mtu = module.params.get('mtu') |
| 174 |
if mtu is not None and (mtu < 1500 or mtu > 9000): |
| 175 |
module.fail_json(msg='MTU must be between 1500 and 9000') |
| 176 |
|
| 177 |
cos = module.params.get('cos') |
| 178 |
if cos is not None and (cos < 0 or cos > 6): |
| 179 |
module.fail_json(msg='CoS must be between 0 and 6') |
| 180 |
|
| 181 |
rate_limit = module.params.get('rate_limit') |
| 182 |
if rate_limit is not None and (rate_limit < 0 or rate_limit > 100000): |
| 183 |
module.fail_json(msg='Rate limit must be between 0 and 100000') |
| 184 |
|
| 185 |
burst = module.params.get('burst') |
| 186 |
if burst is not None and (burst < 1 or burst > 1000000): |
| 187 |
module.fail_json(msg='Burst must be between 1 and 1000000') |
| 188 |
|
| 189 |
|
| 190 |
def main(): |
| 191 |
argument_spec = intersight_argument_spec.copy() |
| 192 |
argument_spec.update( |
| 193 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 194 |
organization=dict(type='str', default='default'), |
| 195 |
name=dict(type='str', required=True), |
| 196 |
description=dict(type='str', aliases=['descr']), |
| 197 |
tags=dict(type='list', elements='dict'), |
| 198 |
mtu=dict(type='int', default=1500), |
| 199 |
cos=dict(type='int', default=0), |
| 200 |
priority=dict( |
| 201 |
type='str', |
| 202 |
choices=['Best Effort', 'FC', 'Platinum', 'Gold', 'Silver', 'Bronze'], |
| 203 |
default='Best Effort' |
| 204 |
), |
| 205 |
trust_host_cos=dict(type='bool', default=False), |
| 206 |
rate_limit=dict(type='int', default=0), |
| 207 |
burst=dict(type='int', default=10240), |
| 208 |
) |
| 209 |
module = AnsibleModule( |
| 210 |
argument_spec, |
| 211 |
supports_check_mode=True, |
| 212 |
) |
| 213 |
|
| 214 |
validate_input(module) |
| 215 |
intersight = IntersightModule(module) |
| 216 |
intersight.result['api_response'] = {} |
| 217 |
intersight.result['trace_id'] = '' |
| 218 |
|
| 219 |
# Resource path used to configure policy |
| 220 |
resource_path = '/vnic/EthQosPolicies' |
| 221 |
|
| 222 |
# Define API body used in compares or create |
| 223 |
intersight.api_body = { |
| 224 |
'Organization': { |
| 225 |
'Name': intersight.module.params['organization'], |
| 226 |
}, |
| 227 |
'Name': intersight.module.params['name'] |
| 228 |
} |
| 229 |
|
| 230 |
if module.params['state'] == 'present': |
| 231 |
intersight.set_tags_and_description() |
| 232 |
|
| 233 |
intersight.api_body.update({ |
| 234 |
'Mtu': module.params['mtu'], |
| 235 |
'Cos': module.params['cos'], |
| 236 |
'Priority': module.params['priority'], |
| 237 |
'TrustHostCos': module.params['trust_host_cos'], |
| 238 |
'RateLimit': module.params['rate_limit'], |
| 239 |
'Burst': module.params['burst'] |
| 240 |
}) |
| 241 |
|
| 242 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 243 |
|
| 244 |
module.exit_json(**intersight.result) |
| 245 |
|
| 246 |
|
| 247 |
if __name__ == '__main__': |
| 248 |
main() |