| 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_lan_connectivity_policy_info |
| 16 |
short_description: Gather information about LAN Connectivity Policies in Cisco Intersight |
| 17 |
description: |
| 18 |
- Gather information about LAN Connectivity Policies in L(Cisco Intersight,https://intersight.com). |
| 19 |
- Information can be filtered by O(organization) and O(name). |
| 20 |
- If no filters are passed, all LAN Connectivity Policies will be returned. |
| 21 |
- Each policy includes its associated vNICs as part of the response. |
| 22 |
extends_documentation_fragment: intersight |
| 23 |
options: |
| 24 |
organization: |
| 25 |
description: |
| 26 |
- The name of the organization the LAN Connectivity Policy belongs to. |
| 27 |
type: str |
| 28 |
name: |
| 29 |
description: |
| 30 |
- The name of the LAN Connectivity Policy to gather information from. |
| 31 |
type: str |
| 32 |
author: |
| 33 |
- Ron Gershburg (@rgershbu) |
| 34 |
''' |
| 35 |
|
| 36 |
EXAMPLES = r''' |
| 37 |
- name: Fetch a specific LAN Connectivity Policy by name |
| 38 |
cisco.intersight.intersight_lan_connectivity_policy_info: |
| 39 |
api_private_key: "{{ api_private_key }}" |
| 40 |
api_key_id: "{{ api_key_id }}" |
| 41 |
name: "datacenter-lan-policy" |
| 42 |
|
| 43 |
- name: Fetch all LAN Connectivity Policies in a specific Organization |
| 44 |
cisco.intersight.intersight_lan_connectivity_policy_info: |
| 45 |
api_private_key: "{{ api_private_key }}" |
| 46 |
api_key_id: "{{ api_key_id }}" |
| 47 |
organization: "default" |
| 48 |
|
| 49 |
- name: Fetch all LAN Connectivity Policies |
| 50 |
cisco.intersight.intersight_lan_connectivity_policy_info: |
| 51 |
api_private_key: "{{ api_private_key }}" |
| 52 |
api_key_id: "{{ api_key_id }}" |
| 53 |
''' |
| 54 |
|
| 55 |
RETURN = r''' |
| 56 |
api_response: |
| 57 |
description: The API response output returned by the specified resource. |
| 58 |
returned: always |
| 59 |
type: dict |
| 60 |
sample: |
| 61 |
"api_response": [ |
| 62 |
{ |
| 63 |
"Name": "datacenter-lan-policy", |
| 64 |
"ObjectType": "vnic.LanConnectivityPolicy", |
| 65 |
"TargetPlatform": "Standalone", |
| 66 |
"AzureQosEnabled": false, |
| 67 |
"IqnAllocationType": "None", |
| 68 |
"PlacementMode": "custom", |
| 69 |
"StaticIqnName": "", |
| 70 |
"vNICs": [ |
| 71 |
{ |
| 72 |
"Name": "eth0", |
| 73 |
"ObjectType": "vnic.EthIf", |
| 74 |
"Order": 0, |
| 75 |
"Placement": { |
| 76 |
"Id": "1", |
| 77 |
"Uplink": 0, |
| 78 |
"PciLink": 0 |
| 79 |
}, |
| 80 |
"Cdn": { |
| 81 |
"Source": "vnic" |
| 82 |
}, |
| 83 |
"EthNetworkPolicy": "6898934a010c5abf01f88125", |
| 84 |
"EthQosPolicy": "6898934a010c5abf01f88126", |
| 85 |
"EthAdapterPolicy": "68989358010c5abf01f89569" |
| 86 |
}, |
| 87 |
{ |
| 88 |
"Name": "eth1-usnic", |
| 89 |
"ObjectType": "vnic.EthIf", |
| 90 |
"Order": 1, |
| 91 |
"Placement": { |
| 92 |
"Id": "2", |
| 93 |
"Uplink": 0, |
| 94 |
"PciLink": 0 |
| 95 |
}, |
| 96 |
"Cdn": { |
| 97 |
"Source": "user", |
| 98 |
"Value": "custom-eth1" |
| 99 |
}, |
| 100 |
"UsnicSettings": { |
| 101 |
"Count": 15, |
| 102 |
"Cos": 3, |
| 103 |
"UsnicAdapterPolicy": "68989358010c5abf01f89569" |
| 104 |
}, |
| 105 |
"EthNetworkPolicy": "6898934a010c5abf01f88125", |
| 106 |
"EthQosPolicy": "6898934a010c5abf01f88126", |
| 107 |
"EthAdapterPolicy": "68989358010c5abf01f89569" |
| 108 |
} |
| 109 |
], |
| 110 |
"Tags": [ |
| 111 |
{ |
| 112 |
"Key": "Environment", |
| 113 |
"Value": "Production" |
| 114 |
} |
| 115 |
] |
| 116 |
}, |
| 117 |
{ |
| 118 |
"Name": "fi-attached-policy", |
| 119 |
"ObjectType": "vnic.LanConnectivityPolicy", |
| 120 |
"TargetPlatform": "FIAttached", |
| 121 |
"AzureQosEnabled": true, |
| 122 |
"IqnAllocationType": "Pool", |
| 123 |
"PlacementMode": "auto", |
| 124 |
"IqnPool": "6898a32d6f62693301a90d5c", |
| 125 |
"vNICs": [ |
| 126 |
{ |
| 127 |
"Name": "vnic-fi-attached", |
| 128 |
"ObjectType": "vnic.EthIf", |
| 129 |
"MacAddressType": "POOL", |
| 130 |
"MacPool": "6898a2fc6962753101f5bb41", |
| 131 |
"Order": 0, |
| 132 |
"Placement": { |
| 133 |
"SwitchId": "A", |
| 134 |
"AutoSlotId": true, |
| 135 |
"AutoPciLink": true |
| 136 |
}, |
| 137 |
"Cdn": { |
| 138 |
"Source": "vnic" |
| 139 |
}, |
| 140 |
"FailoverEnabled": false, |
| 141 |
"FabricEthNetworkGroupPolicy": [ |
| 142 |
"6898a32d6f62693301a90d5c" |
| 143 |
], |
| 144 |
"FabricEthNetworkControlPolicy": "6898a3426f62693301a92527", |
| 145 |
"EthQosPolicy": "6898934a010c5abf01f88126", |
| 146 |
"EthAdapterPolicy": "68989358010c5abf01f89569" |
| 147 |
} |
| 148 |
], |
| 149 |
"Tags": [ |
| 150 |
{ |
| 151 |
"Key": "Site", |
| 152 |
"Value": "Datacenter1" |
| 153 |
} |
| 154 |
] |
| 155 |
} |
| 156 |
] |
| 157 |
''' |
| 158 |
|
| 159 |
|
| 160 |
from ansible.module_utils.basic import AnsibleModule |
| 161 |
from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec |
| 162 |
|
| 163 |
|
| 164 |
def main(): |
| 165 |
argument_spec = intersight_argument_spec.copy() |
| 166 |
argument_spec.update( |
| 167 |
organization=dict(type='str'), |
| 168 |
name=dict(type='str') |
| 169 |
) |
| 170 |
module = AnsibleModule( |
| 171 |
argument_spec, |
| 172 |
supports_check_mode=True, |
| 173 |
) |
| 174 |
|
| 175 |
intersight = IntersightModule(module) |
| 176 |
intersight.result['api_response'] = {} |
| 177 |
intersight.result['trace_id'] = '' |
| 178 |
|
| 179 |
resource_path = '/vnic/LanConnectivityPolicies' |
| 180 |
|
| 181 |
query_params = intersight.set_query_params() |
| 182 |
|
| 183 |
intersight.get_resource( |
| 184 |
resource_path=resource_path, |
| 185 |
query_params=query_params, |
| 186 |
return_list=True |
| 187 |
) |
| 188 |
|
| 189 |
# Fetch vNICs for each LAN connectivity policy |
| 190 |
lan_policies = intersight.result['api_response'] |
| 191 |
if isinstance(lan_policies, list): |
| 192 |
for policy in lan_policies: |
| 193 |
if policy.get('Moid'): |
| 194 |
# Fetch vNICs for this policy using LanConnectivityPolicy.Moid filter |
| 195 |
vnics_query_params = { |
| 196 |
'$filter': f"LanConnectivityPolicy.Moid eq '{policy['Moid']}'" |
| 197 |
} |
| 198 |
|
| 199 |
# Create a temporary intersight instance for vNICs query |
| 200 |
temp_intersight = IntersightModule(module) |
| 201 |
temp_intersight.get_resource( |
| 202 |
resource_path='/vnic/EthIfs', |
| 203 |
query_params=vnics_query_params, |
| 204 |
return_list=True |
| 205 |
) |
| 206 |
|
| 207 |
# Add vNICs to the policy |
| 208 |
policy['vNICs'] = temp_intersight.result.get('api_response', []) |
| 209 |
elif isinstance(lan_policies, dict) and lan_policies.get('Moid'): |
| 210 |
# Single policy case |
| 211 |
vnics_query_params = { |
| 212 |
'$filter': f"LanConnectivityPolicy.Moid eq '{lan_policies['Moid']}'" |
| 213 |
} |
| 214 |
|
| 215 |
# Create a temporary intersight instance for vNICs query |
| 216 |
temp_intersight = IntersightModule(module) |
| 217 |
temp_intersight.get_resource( |
| 218 |
resource_path='/vnic/EthIfs', |
| 219 |
query_params=vnics_query_params, |
| 220 |
return_list=True |
| 221 |
) |
| 222 |
|
| 223 |
# Add vNICs to the policy |
| 224 |
lan_policies['vNICs'] = temp_intersight.result.get('api_response', []) |
| 225 |
|
| 226 |
module.exit_json(**intersight.result) |
| 227 |
|
| 228 |
|
| 229 |
if __name__ == '__main__': |
| 230 |
main() |