| 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_wwn_pool |
| 16 |
short_description: WWNN/WWPN Pool configuration for Cisco Intersight |
| 17 |
description: |
| 18 |
- WWNN/WWPN Pool configuration for Cisco Intersight. |
| 19 |
- Used to configure WWN 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 WWNN/WWPN Pool. |
| 39 |
- The name must be between 1 and 62 alphanumeric characters, allowing special characters :-_. |
| 40 |
- Two pools WWNN and WWNP can have the same name. |
| 41 |
type: str |
| 42 |
required: true |
| 43 |
tags: |
| 44 |
description: |
| 45 |
- List of tags in Key:<user-defined key> Value:<user-defined value> format. |
| 46 |
type: list |
| 47 |
elements: dict |
| 48 |
description: |
| 49 |
description: |
| 50 |
- The user-defined description of the WWNN/WWPN Pool. |
| 51 |
- Description can contain letters(a-z, A-Z), numbers(0-9), hyphen(-), period(.), colon(:), or an underscore(_). |
| 52 |
type: str |
| 53 |
aliases: [descr] |
| 54 |
assignment_order: |
| 55 |
description: |
| 56 |
- Assignment order decides the order in which the next identifier is allocated. |
| 57 |
- If C(sequential), identifiers are assigned in a sequential order. |
| 58 |
- If C(default), the system determines the assignment order. |
| 59 |
type: str |
| 60 |
choices: [default, sequential] |
| 61 |
default: default |
| 62 |
pool_purpose: |
| 63 |
description: |
| 64 |
- The pool type WWNN or WWPN. |
| 65 |
- Required also for C(absent) - Two pools WWNN and WWNP can have the same name. |
| 66 |
type: str |
| 67 |
required: true |
| 68 |
id_blocks: |
| 69 |
description: |
| 70 |
- WWN Blocks |
| 71 |
- Block of WWNN/WWPN Identifiers. |
| 72 |
type: list |
| 73 |
elements: dict |
| 74 |
suboptions: |
| 75 |
wwn_from: |
| 76 |
description: |
| 77 |
- Starting WWN identifier of the block must be in hexadecimal format xx:xx:xx:xx:xx:xx:xx:xx. |
| 78 |
- Allowed ranges are 20:00:00:00:00:00:00:00 to 20:FF:FF:FF:FF:FF:FF:FF |
| 79 |
- Or from 50:00:00:00:00:00:00:00 to 5F:FF:FF:FF:FF:FF:FF:FF. |
| 80 |
- To ensure uniqueness of WWN's in the SAN fabric, you are strongly encouraged to use the following WWN prefix; 20:00:00:25:B5:xx:xx:xx. |
| 81 |
type: str |
| 82 |
required: true |
| 83 |
size: |
| 84 |
description: |
| 85 |
- Number of identifiers this block can hold. |
| 86 |
- This value must be an integer between 1 and 1024, inclusive. |
| 87 |
type: int |
| 88 |
required: true |
| 89 |
author: |
| 90 |
- Shahar Golshani (@sgolshan) |
| 91 |
''' |
| 92 |
|
| 93 |
EXAMPLES = r''' |
| 94 |
- name: Create WWNN pool |
| 95 |
cisco.intersight.intersight_wwn_pool: |
| 96 |
api_private_key: "{{ api_private_key }}" |
| 97 |
api_key_id: "{{ api_key_id }}" |
| 98 |
name: wwn_pool_1 |
| 99 |
description: "Test WWNN pool description" |
| 100 |
assignment_order: sequential |
| 101 |
tags: |
| 102 |
- "Key": "Site" |
| 103 |
"Value": "tag1" |
| 104 |
pool_purpose: "WWNN" |
| 105 |
id_blocks: |
| 106 |
- "wwn_from": "20:00:00:25:B5:00:00:00" |
| 107 |
"size": 100 |
| 108 |
- "wwn_from": "20:00:00:25:B5:FF:00:00" |
| 109 |
"size": 100 |
| 110 |
|
| 111 |
- name: Create WWPN pool |
| 112 |
cisco.intersight.intersight_wwn_pool: |
| 113 |
api_private_key: "{{ api_private_key }}" |
| 114 |
api_key_id: "{{ api_key_id }}" |
| 115 |
name: wwn_pool_2 |
| 116 |
description: "Test WWPN pool description" |
| 117 |
tags: |
| 118 |
- "Key": "Site" |
| 119 |
"Value": "tag2" |
| 120 |
pool_purpose: "WWPN" |
| 121 |
id_blocks: |
| 122 |
- "wwn_from": "20:00:00:25:B5:00:FF:00" |
| 123 |
"size": 200 |
| 124 |
- "wwn_from": "20:00:00:25:B5:FF:FF:00" |
| 125 |
"size": 200 |
| 126 |
|
| 127 |
- name: Delete WWN pool |
| 128 |
cisco.intersight.intersight_wwn_pool: |
| 129 |
api_private_key: "{{ api_private_key }}" |
| 130 |
api_key_id: "{{ api_key_id }}" |
| 131 |
name: wwn_pool_1 |
| 132 |
pool_purpose: "WWPN" |
| 133 |
state: absent |
| 134 |
''' |
| 135 |
|
| 136 |
RETURN = r''' |
| 137 |
api_response: |
| 138 |
description: The API response output returned by the specified resource. |
| 139 |
returned: always |
| 140 |
type: dict |
| 141 |
sample: |
| 142 |
"api_response": { |
| 143 |
"Name": "wwn_pool_1", |
| 144 |
"ObjectType": "fcpool.Pool", |
| 145 |
"Tags": [ |
| 146 |
{ |
| 147 |
"Key": "Site", |
| 148 |
"Value": "tag1" |
| 149 |
}, |
| 150 |
{ |
| 151 |
"Key": "Site2", |
| 152 |
"Value": "tag2" |
| 153 |
} |
| 154 |
], |
| 155 |
"IdBlocks": [ |
| 156 |
{ |
| 157 |
"ClassId": "fcpool.Block", |
| 158 |
"ObjectType": "fcpool.Block", |
| 159 |
"Size": 100, |
| 160 |
"From": "20:00:00:25:B5:00:00:00", |
| 161 |
"To": "20:00:00:25:B5:00:00:63" |
| 162 |
}, |
| 163 |
{ |
| 164 |
"ClassId": "fcpool.Block", |
| 165 |
"ObjectType": "fcpool.Block", |
| 166 |
"Size": 100, |
| 167 |
"From": "20:00:00:25:B5:FF:00:00", |
| 168 |
"To": "20:00:00:25:B5:FF:00:63" |
| 169 |
} |
| 170 |
], |
| 171 |
"PoolPurpose": "WWNN ", |
| 172 |
} |
| 173 |
''' |
| 174 |
|
| 175 |
|
| 176 |
from ansible.module_utils.basic import AnsibleModule |
| 177 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 178 |
|
| 179 |
|
| 180 |
def main(): |
| 181 |
argument_spec = intersight_argument_spec.copy() |
| 182 |
argument_spec.update( |
| 183 |
state=dict(type='str', choices=['present', 'absent'], default='present'), |
| 184 |
organization=dict(type='str', default='default'), |
| 185 |
name=dict(type='str', required=True), |
| 186 |
description=dict(type='str', aliases=['descr']), |
| 187 |
tags=dict(type='list', elements='dict'), |
| 188 |
assignment_order=dict(type='str', choices=['default', 'sequential'], default='default'), |
| 189 |
pool_purpose=dict(type='str', required=True), |
| 190 |
id_blocks=dict( |
| 191 |
type='list', |
| 192 |
elements='dict', |
| 193 |
options=dict( |
| 194 |
wwn_from=dict(type='str', required=True), |
| 195 |
size=dict(type='int', required=True) |
| 196 |
) |
| 197 |
) |
| 198 |
) |
| 199 |
module = AnsibleModule( |
| 200 |
argument_spec, |
| 201 |
supports_check_mode=True, |
| 202 |
) |
| 203 |
|
| 204 |
intersight = IntersightModule(module) |
| 205 |
intersight.result['api_response'] = {} |
| 206 |
intersight.result['trace_id'] = '' |
| 207 |
# Resource path used to configure policy |
| 208 |
resource_path = '/fcpool/Pools' |
| 209 |
intersight.api_body = { |
| 210 |
'Organization': { |
| 211 |
'Name': intersight.module.params['organization'], |
| 212 |
}, |
| 213 |
'Name': intersight.module.params['name'], |
| 214 |
} |
| 215 |
id_blocks_dict = [] |
| 216 |
if module.params['state'] == 'present': |
| 217 |
intersight.set_tags_and_description() |
| 218 |
intersight.api_body['AssignmentOrder'] = intersight.module.params['assignment_order'] |
| 219 |
# Validate that required parameters were passed. We don't mark it as required in order to support absent. |
| 220 |
if not intersight.module.params['id_blocks']: |
| 221 |
module.fail_json(msg="wwn id_blocks parameter must be provided and contain at least one block when state is 'present'.") |
| 222 |
for id_block in intersight.module.params['id_blocks']: |
| 223 |
id_blocks_dict.append({ |
| 224 |
"From": id_block['wwn_from'], |
| 225 |
"Size": id_block['size'] |
| 226 |
}) |
| 227 |
intersight.api_body['IdBlocks'] = id_blocks_dict |
| 228 |
intersight.api_body['PoolPurpose'] = intersight.module.params['pool_purpose'] |
| 229 |
|
| 230 |
intersight.configure_policy_or_profile(resource_path=resource_path, filter_key="PoolPurpose", filter_value=intersight.module.params['pool_purpose']) |
| 231 |
module.exit_json(**intersight.result) |
| 232 |
|
| 233 |
|
| 234 |
if __name__ == '__main__': |
| 235 |
main() |