| 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_iscsi_adapter_policy |
| 16 |
short_description: Manage iSCSI Adapter Policies for Cisco Intersight |
| 17 |
description: |
| 18 |
- Create, update, and delete iSCSI Adapter Policies on Cisco Intersight. |
| 19 |
- iSCSI adapter policies configure timeout and retry settings for iSCSI adapters. |
| 20 |
- These policies control TCP connection timeout, DHCP timeout, and LUN busy retry behavior. |
| 21 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs/vnic/IscsiAdapterPolicies/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 iSCSI Adapter 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 iSCSI Adapter 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 |
connection_time_out: |
| 57 |
description: |
| 58 |
- The number of seconds to wait until Cisco UCS assumes that the initial login has failed and the iSCSI adapter is unavailable. |
| 59 |
- TCP connection timeout value. |
| 60 |
- Valid range is 0 to 255 seconds. |
| 61 |
type: int |
| 62 |
default: 15 |
| 63 |
dhcp_timeout: |
| 64 |
description: |
| 65 |
- The number of seconds to wait before the initiator assumes that the DHCP server is unavailable. |
| 66 |
- Valid range is 60 to 300 seconds. |
| 67 |
type: int |
| 68 |
default: 60 |
| 69 |
lun_busy_retry_count: |
| 70 |
description: |
| 71 |
- The number of times to retry the connection in case of a failure during iSCSI LUN discovery. |
| 72 |
- Valid range is 0 to 60 retries. |
| 73 |
type: int |
| 74 |
default: 15 |
| 75 |
author: |
| 76 |
- Ron Gershburg (@rgershbu) |
| 77 |
''' |
| 78 |
|
| 79 |
EXAMPLES = r''' |
| 80 |
- name: Create iSCSI Adapter Policy with default settings |
| 81 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 82 |
api_private_key: "{{ api_private_key }}" |
| 83 |
api_key_id: "{{ api_key_id }}" |
| 84 |
organization: "default" |
| 85 |
name: "iscsi-adapter-default" |
| 86 |
description: "iSCSI adapter policy with default timeout values" |
| 87 |
state: present |
| 88 |
|
| 89 |
- name: Create iSCSI Adapter Policy with custom timeout settings |
| 90 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 91 |
api_private_key: "{{ api_private_key }}" |
| 92 |
api_key_id: "{{ api_key_id }}" |
| 93 |
organization: "default" |
| 94 |
name: "iscsi-adapter-custom" |
| 95 |
description: "iSCSI adapter policy with custom timeouts" |
| 96 |
connection_time_out: 30 |
| 97 |
dhcp_timeout: 120 |
| 98 |
lun_busy_retry_count: 30 |
| 99 |
tags: |
| 100 |
- Key: Environment |
| 101 |
Value: Production |
| 102 |
state: present |
| 103 |
|
| 104 |
- name: Create iSCSI Adapter Policy with extended timeouts |
| 105 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 106 |
api_private_key: "{{ api_private_key }}" |
| 107 |
api_key_id: "{{ api_key_id }}" |
| 108 |
organization: "Engineering" |
| 109 |
name: "iscsi-adapter-extended" |
| 110 |
description: "iSCSI adapter policy with extended timeout values" |
| 111 |
connection_time_out: 60 |
| 112 |
dhcp_timeout: 300 |
| 113 |
lun_busy_retry_count: 60 |
| 114 |
state: present |
| 115 |
|
| 116 |
- name: Create iSCSI Adapter Policy with minimal timeouts |
| 117 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 118 |
api_private_key: "{{ api_private_key }}" |
| 119 |
api_key_id: "{{ api_key_id }}" |
| 120 |
organization: "default" |
| 121 |
name: "iscsi-adapter-minimal" |
| 122 |
description: "iSCSI adapter policy with minimal timeout values" |
| 123 |
connection_time_out: 0 |
| 124 |
dhcp_timeout: 60 |
| 125 |
lun_busy_retry_count: 0 |
| 126 |
state: present |
| 127 |
|
| 128 |
- name: Update iSCSI Adapter Policy description |
| 129 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 130 |
api_private_key: "{{ api_private_key }}" |
| 131 |
api_key_id: "{{ api_key_id }}" |
| 132 |
organization: "default" |
| 133 |
name: "iscsi-adapter-default" |
| 134 |
description: "Updated iSCSI adapter policy description" |
| 135 |
state: present |
| 136 |
|
| 137 |
- name: Delete iSCSI Adapter Policy |
| 138 |
cisco.intersight.intersight_iscsi_adapter_policy: |
| 139 |
api_private_key: "{{ api_private_key }}" |
| 140 |
api_key_id: "{{ api_key_id }}" |
| 141 |
organization: "default" |
| 142 |
name: "iscsi-adapter-default" |
| 143 |
state: absent |
| 144 |
''' |
| 145 |
|
| 146 |
RETURN = r''' |
| 147 |
api_response: |
| 148 |
description: The API response output returned by the specified resource. |
| 149 |
returned: always |
| 150 |
type: dict |
| 151 |
sample: |
| 152 |
"api_response": { |
| 153 |
"Name": "iscsi-adapter-custom", |
| 154 |
"ObjectType": "vnic.IscsiAdapterPolicy", |
| 155 |
"ConnectionTimeOut": 30, |
| 156 |
"DhcpTimeout": 120, |
| 157 |
"LunBusyRetryCount": 30, |
| 158 |
"Moid": "1234567890abcdef12345678", |
| 159 |
"Description": "iSCSI adapter policy with custom timeouts", |
| 160 |
"Organization": { |
| 161 |
"Moid": "abcdef1234567890abcdef12", |
| 162 |
"ObjectType": "organization.Organization" |
| 163 |
}, |
| 164 |
"Tags": [ |
| 165 |
{ |
| 166 |
"Key": "Environment", |
| 167 |
"Value": "Production" |
| 168 |
} |
| 169 |
] |
| 170 |
} |
| 171 |
''' |
| 172 |
|
| 173 |
|
| 174 |
from ansible.module_utils.basic import AnsibleModule |
| 175 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 176 |
|
| 177 |
|
| 178 |
def validate_parameters(module): |
| 179 |
""" |
| 180 |
Validate module parameters for iSCSI adapter policy configuration. |
| 181 |
""" |
| 182 |
if module.params['state'] != 'present': |
| 183 |
return |
| 184 |
# Validate connection_time_out range (0-255) |
| 185 |
connection_time_out = module.params.get('connection_time_out') |
| 186 |
if connection_time_out is not None and (connection_time_out < 0 or connection_time_out > 255): |
| 187 |
module.fail_json(msg="Parameter 'connection_time_out' must be between 0 and 255 seconds") |
| 188 |
# Validate dhcp_timeout range (60-300) |
| 189 |
dhcp_timeout = module.params.get('dhcp_timeout') |
| 190 |
if dhcp_timeout is not None and (dhcp_timeout < 60 or dhcp_timeout > 300): |
| 191 |
module.fail_json(msg="Parameter 'dhcp_timeout' must be between 60 and 300 seconds") |
| 192 |
# Validate lun_busy_retry_count range (0-60) |
| 193 |
lun_busy_retry_count = module.params.get('lun_busy_retry_count') |
| 194 |
if lun_busy_retry_count is not None and (lun_busy_retry_count < 0 or lun_busy_retry_count > 60): |
| 195 |
module.fail_json(msg="Parameter 'lun_busy_retry_count' must be between 0 and 60 retries") |
| 196 |
|
| 197 |
|
| 198 |
def main(): |
| 199 |
argument_spec = intersight_argument_spec.copy() |
| 200 |
argument_spec.update( |
| 201 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 202 |
organization=dict(type='str', default='default'), |
| 203 |
name=dict(type='str', required=True), |
| 204 |
description=dict(type='str', aliases=['descr']), |
| 205 |
tags=dict(type='list', elements='dict'), |
| 206 |
connection_time_out=dict(type='int', default=15), |
| 207 |
dhcp_timeout=dict(type='int', default=60), |
| 208 |
lun_busy_retry_count=dict(type='int', default=15), |
| 209 |
) |
| 210 |
module = AnsibleModule( |
| 211 |
argument_spec, |
| 212 |
supports_check_mode=True, |
| 213 |
) |
| 214 |
intersight = IntersightModule(module) |
| 215 |
intersight.result['api_response'] = {} |
| 216 |
intersight.result['trace_id'] = '' |
| 217 |
# Validate module parameters |
| 218 |
validate_parameters(module) |
| 219 |
# Resource path used to configure policy |
| 220 |
resource_path = '/vnic/IscsiAdapterPolicies' |
| 221 |
# Define API body used in compares or create |
| 222 |
intersight.api_body = { |
| 223 |
'Organization': { |
| 224 |
'Name': module.params['organization'], |
| 225 |
}, |
| 226 |
'Name': module.params['name'], |
| 227 |
} |
| 228 |
if module.params['state'] == 'present': |
| 229 |
intersight.api_body['ConnectionTimeOut'] = module.params['connection_time_out'] |
| 230 |
intersight.api_body['DhcpTimeout'] = module.params['dhcp_timeout'] |
| 231 |
intersight.api_body['LunBusyRetryCount'] = module.params['lun_busy_retry_count'] |
| 232 |
intersight.set_tags_and_description() |
| 233 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 234 |
module.exit_json(**intersight.result) |
| 235 |
|
| 236 |
|
| 237 |
if __name__ == '__main__': |
| 238 |
main() |