| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_localnetworkgateway_info |
| 14 |
|
| 15 |
version_added: "2.4.0" |
| 16 |
|
| 17 |
short_description: Gets or list the specified local network gateway in a resource group |
| 18 |
|
| 19 |
description: |
| 20 |
- Gets or list the specified local network gateway in a resource group. |
| 21 |
|
| 22 |
options: |
| 23 |
resource_group: |
| 24 |
description: |
| 25 |
- The local network gateway's resource group. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
name: |
| 29 |
description: |
| 30 |
- The name of the local network gateway. |
| 31 |
type: str |
| 32 |
tags: |
| 33 |
description: |
| 34 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 35 |
type: list |
| 36 |
elements: str |
| 37 |
|
| 38 |
extends_documentation_fragment: |
| 39 |
- azure.azcollection.azure |
| 40 |
|
| 41 |
author: |
| 42 |
- xuzhang3 (@xuzhang3) |
| 43 |
- Fred Sun (@Fred-sun) |
| 44 |
''' |
| 45 |
|
| 46 |
EXAMPLES = ''' |
| 47 |
- name: Gets the specified local network gateway in a resource group |
| 48 |
azure_rm_localnetworkgateway_info: |
| 49 |
resource_group: "{{ resource_group }}" |
| 50 |
name: "{{ local_networkgateway_name }}" |
| 51 |
|
| 52 |
- name: Gets all the local network gateways in a resource group |
| 53 |
azure_rm_localnetworkgateway_info: |
| 54 |
resource_group: "{{ resource_group }}" |
| 55 |
|
| 56 |
- name: Gets all the local network gateways in a resource group and filter by tags |
| 57 |
azure_rm_localnetworkgateway_info: |
| 58 |
resource_group: "{{ resource_group }}" |
| 59 |
tags: |
| 60 |
- foo |
| 61 |
''' |
| 62 |
|
| 63 |
RETURN = ''' |
| 64 |
state: |
| 65 |
description: |
| 66 |
- Current state of the Azure Local Network Gateway resource. |
| 67 |
returned: always |
| 68 |
type: complex |
| 69 |
contains: |
| 70 |
id: |
| 71 |
description: |
| 72 |
- The resource ID. |
| 73 |
type: str |
| 74 |
returned: always |
| 75 |
sample: "/subscriptions/xxxx-xxxx/resourceGroups/testRG/providers/Microsoft.Network/localNetworkGateways/testgateway" |
| 76 |
bgp_settings: |
| 77 |
description: |
| 78 |
- Local network gateway's BGP speaker settings. |
| 79 |
type: complex |
| 80 |
contains: |
| 81 |
asn: |
| 82 |
description: |
| 83 |
- The BGP speaker's ASN. |
| 84 |
type: int |
| 85 |
returned: always |
| 86 |
sample: 10 |
| 87 |
bgp_peering_address: |
| 88 |
description: |
| 89 |
- The BGP peering address and BGP identifier of this BGP speaker. |
| 90 |
type: str |
| 91 |
returned: always |
| 92 |
sample: 10.0.0.3 |
| 93 |
peer_weight: |
| 94 |
description: |
| 95 |
- The weight added to routes learned from this BGP speaker. |
| 96 |
type: int |
| 97 |
returned: always |
| 98 |
sample: 0 |
| 99 |
fqdn: |
| 100 |
description: |
| 101 |
- FQDN of local network gateway. |
| 102 |
type: str |
| 103 |
returned: always |
| 104 |
sample: testfqdn.com |
| 105 |
gateway_ip_address: |
| 106 |
description: |
| 107 |
- IP address of local network gateway. |
| 108 |
type: str |
| 109 |
returned: always |
| 110 |
sample: 10.1.1.1 |
| 111 |
etag: |
| 112 |
description: |
| 113 |
- A unique read-only string that changes whenever the resource is updated. |
| 114 |
type: str |
| 115 |
returned: always |
| 116 |
sample: b5a32693-2e75-49e0-9137-ded19db658d6 |
| 117 |
local_network_address_space: |
| 118 |
description: |
| 119 |
- Local network site address space. |
| 120 |
type: complex |
| 121 |
contains: |
| 122 |
address_prefixes: |
| 123 |
description: |
| 124 |
- A list of address blocks reserved for this virtual network in CIDR notation. |
| 125 |
type: list |
| 126 |
returned: always |
| 127 |
sample: ["10.0.0.0/24", "20.0.0.0/24"] |
| 128 |
location: |
| 129 |
description: |
| 130 |
- The resource location. |
| 131 |
type: str |
| 132 |
returned: always |
| 133 |
sample: eastus |
| 134 |
name: |
| 135 |
description: |
| 136 |
- The resource name. |
| 137 |
type: str |
| 138 |
returned: always |
| 139 |
sample: testgateway |
| 140 |
provisioning_state: |
| 141 |
description: |
| 142 |
- The provisioning state of the local network gateway resource. |
| 143 |
type: str |
| 144 |
returned: always |
| 145 |
sample: Succeeded |
| 146 |
tags: |
| 147 |
description: |
| 148 |
- The resource tags. |
| 149 |
type: str |
| 150 |
returned: always |
| 151 |
sample: {'key1': 'value1', 'key2': 'value2'} |
| 152 |
type: |
| 153 |
description: |
| 154 |
- The resource type. |
| 155 |
type: str |
| 156 |
returned: always |
| 157 |
sample: Microsoft.Network/localNetworkGateways |
| 158 |
''' |
| 159 |
|
| 160 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 161 |
|
| 162 |
try: |
| 163 |
from azure.core.exceptions import HttpResponseError |
| 164 |
except Exception: |
| 165 |
|
| 166 |
pass |
| 167 |
|
| 168 |
|
| 169 |
class AzureRMNetworkGateWayInfo(AzureRMModuleBase): |
| 170 |
"""Utility class to get Azure Kubernetes Service Credentials facts""" |
| 171 |
|
| 172 |
def __init__(self): |
| 173 |
|
| 174 |
self.module_args = dict( |
| 175 |
name=dict(type='str'), |
| 176 |
resource_group=dict(type='str', required=True), |
| 177 |
tags=dict(type='list', elements='str'), |
| 178 |
) |
| 179 |
|
| 180 |
self.name = None |
| 181 |
self.tags = None |
| 182 |
|
| 183 |
self.results = dict( |
| 184 |
changed=False, |
| 185 |
state=[], |
| 186 |
) |
| 187 |
|
| 188 |
super(AzureRMNetworkGateWayInfo, self).__init__(derived_arg_spec=self.module_args, |
| 189 |
supports_check_mode=True, |
| 190 |
supports_tags=False, |
| 191 |
facts_module=True) |
| 192 |
|
| 193 |
def exec_module(self, **kwargs): |
| 194 |
|
| 195 |
for key in self.module_args: |
| 196 |
setattr(self, key, kwargs[key]) |
| 197 |
|
| 198 |
if self.name is not None: |
| 199 |
self.results['state'] = self.get_local_network_gateway() |
| 200 |
else: |
| 201 |
self.results['state'] = self.list_local_network_gateway() |
| 202 |
|
| 203 |
return self.results |
| 204 |
|
| 205 |
def get_local_network_gateway(self): |
| 206 |
"""Gets the specified local network gateway in a resource group""" |
| 207 |
response = None |
| 208 |
|
| 209 |
try: |
| 210 |
response = self.network_client.local_network_gateways.get(self.resource_group, self.name) |
| 211 |
except HttpResponseError as ec: |
| 212 |
self.log("Gets the specified local network gateway in a resource group Failed, Exception as {0}".format(ec)) |
| 213 |
if response and self.has_tags(response.tags, self.tags): |
| 214 |
return [self.format_response(response)] |
| 215 |
else: |
| 216 |
return [] |
| 217 |
|
| 218 |
def list_local_network_gateway(self): |
| 219 |
"""Gets all the local network gateways in a resource group""" |
| 220 |
response = None |
| 221 |
|
| 222 |
try: |
| 223 |
response = self.network_client.local_network_gateways.list(self.resource_group) |
| 224 |
except HttpResponseError as ec: |
| 225 |
self.log("Gets all the local network gateways in a resource group Failed, Exception as {0}".format(ec)) |
| 226 |
|
| 227 |
if response: |
| 228 |
results = [] |
| 229 |
for item in response: |
| 230 |
if self.has_tags(item.tags, self.tags): |
| 231 |
results.append(self.format_response(item)) |
| 232 |
return results |
| 233 |
else: |
| 234 |
return [] |
| 235 |
|
| 236 |
def format_response(self, item): |
| 237 |
result = dict( |
| 238 |
id=item.id, |
| 239 |
name=item.name, |
| 240 |
location=item.location, |
| 241 |
type=item.type, |
| 242 |
tags=item.tags, |
| 243 |
etag=item.etag, |
| 244 |
local_network_address_space=dict(), |
| 245 |
gateway_ip_address=item.gateway_ip_address, |
| 246 |
fqdn=item.fqdn, |
| 247 |
provisioning_state=item.provisioning_state, |
| 248 |
bgp_settings=dict(), |
| 249 |
) |
| 250 |
|
| 251 |
if item.local_network_address_space is not None: |
| 252 |
result['local_network_address_space']['address_prefixes'] = item.local_network_address_space.address_prefixes |
| 253 |
if item.bgp_settings is not None: |
| 254 |
result['bgp_settings']['asn'] = item.bgp_settings.asn |
| 255 |
result['bgp_settings']['bgp_peering_address'] = item.bgp_settings.bgp_peering_address |
| 256 |
result['bgp_settings']['peer_weight'] = item.bgp_settings.peer_weight |
| 257 |
return result |
| 258 |
|
| 259 |
|
| 260 |
def main(): |
| 261 |
"""Main module execution code path""" |
| 262 |
|
| 263 |
AzureRMNetworkGateWayInfo() |
| 264 |
|
| 265 |
|
| 266 |
if __name__ == '__main__': |
| 267 |
main() |