| 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_info |
| 16 |
short_description: Gather information about iSCSI Adapter Policies in Cisco Intersight |
| 17 |
description: |
| 18 |
- Retrieve information about iSCSI Adapter Policies from L(Cisco Intersight,https://intersight.com). |
| 19 |
- Query policies by organization or policy name. |
| 20 |
- Returns structured data with policy metadata and iSCSI adapter configuration details. |
| 21 |
- If no filters are provided, all iSCSI Adapter Policies will be returned. |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
organization: |
| 25 |
description: |
| 26 |
- The name of the organization to filter iSCSI Adapter Policies by. |
| 27 |
- Use 'default' for the default organization. |
| 28 |
- When specified, only policies from this organization will be returned. |
| 29 |
type: str |
| 30 |
name: |
| 31 |
description: |
| 32 |
- The exact name of the iSCSI Adapter Policy to retrieve information from. |
| 33 |
- When specified, only the matching policy will be returned. |
| 34 |
type: str |
| 35 |
author: |
| 36 |
- Ron Gershburg (@rgershbu) |
| 37 |
''' |
| 38 |
|
| 39 |
EXAMPLES = r''' |
| 40 |
# Basic Usage Examples |
| 41 |
- name: Fetch all iSCSI Adapter Policies from all organizations |
| 42 |
cisco.intersight.intersight_iscsi_adapter_policy_info: |
| 43 |
api_private_key: "{{ api_private_key }}" |
| 44 |
api_key_id: "{{ api_key_id }}" |
| 45 |
register: all_iscsi_adapter_policies |
| 46 |
|
| 47 |
# Organization-specific Examples |
| 48 |
- name: Fetch all iSCSI Adapter Policies from the default organization |
| 49 |
cisco.intersight.intersight_iscsi_adapter_policy_info: |
| 50 |
api_private_key: "{{ api_private_key }}" |
| 51 |
api_key_id: "{{ api_key_id }}" |
| 52 |
organization: "default" |
| 53 |
register: default_org_policies |
| 54 |
|
| 55 |
- name: Fetch all iSCSI Adapter Policies from a custom organization |
| 56 |
cisco.intersight.intersight_iscsi_adapter_policy_info: |
| 57 |
api_private_key: "{{ api_private_key }}" |
| 58 |
api_key_id: "{{ api_key_id }}" |
| 59 |
organization: "Engineering" |
| 60 |
register: engineering_policies |
| 61 |
|
| 62 |
# Specific Policy Examples |
| 63 |
- name: Fetch a specific iSCSI Adapter Policy by name |
| 64 |
cisco.intersight.intersight_iscsi_adapter_policy_info: |
| 65 |
api_private_key: "{{ api_private_key }}" |
| 66 |
api_key_id: "{{ api_key_id }}" |
| 67 |
name: "iscsi-adapter-policy-01" |
| 68 |
register: specific_policy |
| 69 |
|
| 70 |
- name: Fetch a specific policy from a specific organization |
| 71 |
cisco.intersight.intersight_iscsi_adapter_policy_info: |
| 72 |
api_private_key: "{{ api_private_key }}" |
| 73 |
api_key_id: "{{ api_key_id }}" |
| 74 |
organization: "Production" |
| 75 |
name: "iscsi-adapter-policy-prod" |
| 76 |
register: specific_org_policy |
| 77 |
''' |
| 78 |
|
| 79 |
RETURN = r''' |
| 80 |
api_response: |
| 81 |
description: |
| 82 |
- The API response containing iSCSI Adapter Policy information. |
| 83 |
- Returns a list. |
| 84 |
returned: always |
| 85 |
type: list |
| 86 |
sample: |
| 87 |
[ |
| 88 |
{ |
| 89 |
"Name": "iscsi-adapter-policy-01", |
| 90 |
"ObjectType": "vnic.IscsiAdapterPolicy", |
| 91 |
"Moid": "1234567890abcdef12345678", |
| 92 |
"Description": "iSCSI adapter policy for production servers", |
| 93 |
"ConnectionTimeOut": 30, |
| 94 |
"DhcpTimeout": 120, |
| 95 |
"LunBusyRetryCount": 30, |
| 96 |
"Organization": { |
| 97 |
"Name": "default", |
| 98 |
"ObjectType": "organization.Organization", |
| 99 |
"Moid": "abcdef1234567890abcdef12" |
| 100 |
}, |
| 101 |
"Tags": [ |
| 102 |
{ |
| 103 |
"Key": "Environment", |
| 104 |
"Value": "Production" |
| 105 |
}, |
| 106 |
{ |
| 107 |
"Key": "Owner", |
| 108 |
"Value": "Storage-Team" |
| 109 |
} |
| 110 |
] |
| 111 |
} |
| 112 |
] |
| 113 |
''' |
| 114 |
|
| 115 |
|
| 116 |
from ansible.module_utils.basic import AnsibleModule |
| 117 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 118 |
|
| 119 |
|
| 120 |
def main(): |
| 121 |
argument_spec = intersight_argument_spec.copy() |
| 122 |
argument_spec.update( |
| 123 |
organization=dict(type='str'), |
| 124 |
name=dict(type='str') |
| 125 |
) |
| 126 |
module = AnsibleModule( |
| 127 |
argument_spec, |
| 128 |
supports_check_mode=True, |
| 129 |
) |
| 130 |
intersight = IntersightModule(module) |
| 131 |
intersight.result['api_response'] = {} |
| 132 |
intersight.result['trace_id'] = '' |
| 133 |
# Resource path used to fetch policy info |
| 134 |
resource_path = '/vnic/IscsiAdapterPolicies' |
| 135 |
# Get query parameters for policies |
| 136 |
query_params = intersight.set_query_params() |
| 137 |
# Get iSCSI Adapter policies |
| 138 |
intersight.get_resource( |
| 139 |
resource_path=resource_path, |
| 140 |
query_params=query_params, |
| 141 |
return_list=True |
| 142 |
) |
| 143 |
module.exit_json(**intersight.result) |
| 144 |
|
| 145 |
|
| 146 |
if __name__ == '__main__': |
| 147 |
main() |