| 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_iqn_pool |
| 16 |
short_description: IQN Pool configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- IQN Pool configuration for Cisco Intersight. |
| 19 |
- Used to configure IQN pools settings on Cisco Intersight managed devices. |
| 20 |
- For more information see L(Cisco Intersight,https://intersight.com/apidocs). |
| 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 IQN Pool. |
| 39 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 40 |
type: str |
| 41 |
required: true |
| 42 |
tags: |
| 43 |
description: |
| 44 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 45 |
type: list |
| 46 |
elements: dict |
| 47 |
description: |
| 48 |
description: |
| 49 |
- The user-defined description of the IQN Pool. |
| 50 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 51 |
type: str |
| 52 |
aliases: [descr] |
| 53 |
assignment_order: |
| 54 |
description: |
| 55 |
- Assignment order decides the order in which the next identifier is allocated. |
| 56 |
- If C(sequential), identifiers are assigned in a sequential order. |
| 57 |
- If C(default), the system determines the assignment order. |
| 58 |
type: str |
| 59 |
choices: [default, sequential] |
| 60 |
default: default |
| 61 |
prefix: |
| 62 |
description: |
| 63 |
- The prefix for any IQN blocks created for this pool. |
| 64 |
- IQN Prefix must have the following format "iqn.yyyy-mm.naming-authority" |
| 65 |
- naming-authority is usually the reverse syntax of the Internet domain name of the naming authority. |
| 66 |
type: str |
| 67 |
required: false |
| 68 |
iqn_suffix_blocks: |
| 69 |
description: |
| 70 |
- List of the IQN blocks. |
| 71 |
- Should include the suffix, iqn_from and size per block. |
| 72 |
type: list |
| 73 |
elements: dict |
| 74 |
suboptions: |
| 75 |
suffix: |
| 76 |
description: |
| 77 |
- The suffix for this block of IQNs. |
| 78 |
type: str |
| 79 |
required: true |
| 80 |
iqn_from: |
| 81 |
description: |
| 82 |
- The first suffix number in the block >= 0. |
| 83 |
type: int |
| 84 |
required: true |
| 85 |
size: |
| 86 |
description: |
| 87 |
- Number of identifiers this block can hold. |
| 88 |
- This value must be an integer between 1 and 1024, inclusive. |
| 89 |
type: int |
| 90 |
required: true |
| 91 |
author: |
| 92 |
- Shahar Golshani (@sgolshan) |
| 93 |
''' |
| 94 |
|
| 95 |
EXAMPLES = r''' |
| 96 |
- name: Create iqn pool |
| 97 |
cisco.intersight.intersight_iqn_pool: |
| 98 |
api_private_key: "{{ api_private_key }}" |
| 99 |
api_key_id: "{{ api_key_id }}" |
| 100 |
name: iqn_pool_1 |
| 101 |
description: "Test iqn pool description" |
| 102 |
assignment_order: sequential |
| 103 |
tags: |
| 104 |
- "Key": "Site" |
| 105 |
"Value": "tag1" |
| 106 |
prefix: "iqn.2025-08.com.cisco" |
| 107 |
iqn_suffix_blocks: |
| 108 |
- "suffix": "iqn" |
| 109 |
"iqn_from": 1 |
| 110 |
"size": 20 |
| 111 |
- "suffix": "iscsi" |
| 112 |
"iqn_from": 21 |
| 113 |
"size": 40 |
| 114 |
- name: Delete iqn pool |
| 115 |
cisco.intersight.intersight_iqn_pool: |
| 116 |
api_private_key: "{{ api_private_key }}" |
| 117 |
api_key_id: "{{ api_key_id }}" |
| 118 |
name: iqn_pool_1 |
| 119 |
state: absent |
| 120 |
''' |
| 121 |
|
| 122 |
RETURN = r''' |
| 123 |
api_response: |
| 124 |
description: The API response output returned by the specified resource. |
| 125 |
returned: always |
| 126 |
type: dict |
| 127 |
sample: |
| 128 |
"api_response": { |
| 129 |
"Name": "iqn_pool_1", |
| 130 |
"ObjectType": "iqnpool.Pool", |
| 131 |
"Tags": [ |
| 132 |
{ |
| 133 |
"Key": "Site", |
| 134 |
"Value": "tag1" |
| 135 |
}, |
| 136 |
{ |
| 137 |
"Key": "Site2", |
| 138 |
"Value": "tag2" |
| 139 |
} |
| 140 |
] |
| 141 |
} |
| 142 |
''' |
| 143 |
|
| 144 |
|
| 145 |
from ansible.module_utils.basic import AnsibleModule |
| 146 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 147 |
|
| 148 |
|
| 149 |
def main(): |
| 150 |
argument_spec = intersight_argument_spec.copy() |
| 151 |
argument_spec.update( |
| 152 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 153 |
organization=dict(type='str', default='default'), |
| 154 |
name=dict(type='str', required=True), |
| 155 |
description=dict(type='str', aliases=['descr']), |
| 156 |
tags=dict(type='list', elements='dict'), |
| 157 |
assignment_order=dict(type='str', choices=['default', 'sequential'], default='default'), |
| 158 |
prefix=dict(type='str'), |
| 159 |
iqn_suffix_blocks=dict( |
| 160 |
type='list', |
| 161 |
elements='dict', |
| 162 |
options=dict( |
| 163 |
suffix=dict(type='str', required=True), |
| 164 |
iqn_from=dict(type='int', required=True), |
| 165 |
size=dict(type='int', required=True) |
| 166 |
) |
| 167 |
) |
| 168 |
) |
| 169 |
module = AnsibleModule( |
| 170 |
argument_spec, |
| 171 |
supports_check_mode=True, |
| 172 |
) |
| 173 |
|
| 174 |
intersight = IntersightModule(module) |
| 175 |
intersight.result['api_response'] = {} |
| 176 |
intersight.result['trace_id'] = '' |
| 177 |
# Resource path used to configure policy |
| 178 |
resource_path = '/iqnpool/Pools' |
| 179 |
intersight.api_body = { |
| 180 |
'Organization': { |
| 181 |
'Name': intersight.module.params['organization'], |
| 182 |
}, |
| 183 |
'Name': intersight.module.params['name'], |
| 184 |
} |
| 185 |
iqn_suffix_blocks_dict = [] |
| 186 |
if module.params['state'] == 'present': |
| 187 |
intersight.set_tags_and_description() |
| 188 |
intersight.api_body['AssignmentOrder'] = intersight.module.params['assignment_order'] |
| 189 |
# Validate that iqn_suffix_blocks was passed. We don't mark it as required in order to support absent. |
| 190 |
if not intersight.module.params['iqn_suffix_blocks']: |
| 191 |
module.fail_json(msg="iqn_suffix_blocks parameter must be provided and contain at least one block when state is 'present'.") |
| 192 |
if not intersight.module.params['prefix']: |
| 193 |
module.fail_json(msg="prefix parameter must be provided when state is 'present'.") |
| 194 |
for iqn_suffix_block in intersight.module.params['iqn_suffix_blocks']: |
| 195 |
iqn_suffix_blocks_dict.append({ |
| 196 |
"Suffix": iqn_suffix_block['suffix'], |
| 197 |
"From": iqn_suffix_block['iqn_from'], |
| 198 |
"Size": iqn_suffix_block['size'] |
| 199 |
}) |
| 200 |
intersight.api_body['IqnSuffixBlocks'] = iqn_suffix_blocks_dict |
| 201 |
intersight.api_body['Prefix'] = intersight.module.params['prefix'] |
| 202 |
|
| 203 |
intersight.configure_policy_or_profile(resource_path=resource_path) |
| 204 |
module.exit_json(**intersight.result) |
| 205 |
|
| 206 |
|
| 207 |
if __name__ == '__main__': |
| 208 |
main() |