| 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_vpnsite_info |
| 14 |
version_added: '1.5.0' |
| 15 |
short_description: Get VpnSite info |
| 16 |
description: |
| 17 |
- Get info of VpnSite. |
| 18 |
options: |
| 19 |
resource_group: |
| 20 |
description: |
| 21 |
- The resource group name of the VpnSite. |
| 22 |
type: str |
| 23 |
name: |
| 24 |
description: |
| 25 |
- The name of the VpnSite being retrieved. |
| 26 |
type: str |
| 27 |
extends_documentation_fragment: |
| 28 |
- azure.azcollection.azure |
| 29 |
- azure.azcollection.azure_tags |
| 30 |
author: |
| 31 |
- Fred-Sun (@Fred-Sun) |
| 32 |
|
| 33 |
''' |
| 34 |
|
| 35 |
EXAMPLES = ''' |
| 36 |
- name: Get Vpn Site Info by name |
| 37 |
azure_rm_vpnsite_info: |
| 38 |
resource_group: myResourceGroup |
| 39 |
name: vwan_site_name |
| 40 |
|
| 41 |
- name: Get Vpn Site List By ResourceGroup |
| 42 |
azure_rm_vpnsite_info: |
| 43 |
resource_group: myResourceGroup |
| 44 |
|
| 45 |
- name: Get Vpn Site List By Subscription |
| 46 |
azure_rm_vpnsite_info: |
| 47 |
''' |
| 48 |
|
| 49 |
RETURN = ''' |
| 50 |
vpn_sites: |
| 51 |
description: |
| 52 |
- A list of dict results where the key is the name of the VpnSite and the values are the facts for that VpnSite. |
| 53 |
returned: always |
| 54 |
type: complex |
| 55 |
contains: |
| 56 |
id: |
| 57 |
description: |
| 58 |
- Resource ID. |
| 59 |
returned: always |
| 60 |
type: str |
| 61 |
sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/vpnSites/vwam_site_name |
| 62 |
name: |
| 63 |
description: |
| 64 |
- Resource name. |
| 65 |
returned: always |
| 66 |
type: str |
| 67 |
sample: vwan_site_name |
| 68 |
type: |
| 69 |
description: |
| 70 |
- Resource type. |
| 71 |
returned: always |
| 72 |
type: str |
| 73 |
sample: Microsoft.Network/vpnSites |
| 74 |
location: |
| 75 |
description: |
| 76 |
- Resource location. |
| 77 |
returned: always |
| 78 |
type: str |
| 79 |
sample: eastus |
| 80 |
tags: |
| 81 |
description: |
| 82 |
- Resource tags. |
| 83 |
returned: always |
| 84 |
type: dict |
| 85 |
sample: { "key1":"value1"} |
| 86 |
etag: |
| 87 |
description: |
| 88 |
- A unique read-only string that changes whenever the resource is updated. |
| 89 |
returned: always |
| 90 |
type: str |
| 91 |
sample: 1d8c0731-adc6-4022-9c70-3c389cd73e2a |
| 92 |
virtual_wan: |
| 93 |
description: |
| 94 |
- The VirtualWAN to which the vpnSite belongs. |
| 95 |
returned: always |
| 96 |
type: dict |
| 97 |
sample: {"id": "/subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualWans/vwan_name"} |
| 98 |
device_properties: |
| 99 |
description: |
| 100 |
- The device properties. |
| 101 |
returned: always |
| 102 |
type: dict |
| 103 |
sample: {"device_vendor": "myVM", "link_speed_in_mbps": 0} |
| 104 |
address_space: |
| 105 |
description: |
| 106 |
- The AddressSpace that contains an array of IP address ranges. |
| 107 |
returned: always |
| 108 |
type: dict |
| 109 |
sample: {"address_prefixes": ["10.0.0.0/24",]} |
| 110 |
provisioning_state: |
| 111 |
description: |
| 112 |
- The provisioning state of the VPN site resource. |
| 113 |
returned: always |
| 114 |
type: str |
| 115 |
sample: "succeeded" |
| 116 |
is_security_site: |
| 117 |
description: |
| 118 |
- IsSecuritySite flag. |
| 119 |
returned: always |
| 120 |
type: bool |
| 121 |
sample: false |
| 122 |
vpn_site_links: |
| 123 |
description: |
| 124 |
- List of all vpn site links. |
| 125 |
returned: always |
| 126 |
type: complex |
| 127 |
contains: |
| 128 |
name: |
| 129 |
description: |
| 130 |
- The name of the resource that is unique within a resource group. |
| 131 |
- This name can be used to access the resource. |
| 132 |
returned: always |
| 133 |
type: str |
| 134 |
sample: azureuser |
| 135 |
link_properties: |
| 136 |
description: |
| 137 |
- The link provider properties. |
| 138 |
returned: always |
| 139 |
type: dict |
| 140 |
sample: {"link_provider_name": "azureuser", "link_speed_in_mbps": 100} |
| 141 |
ip_address: |
| 142 |
description: |
| 143 |
- The ip-address for the vpn-site-link. |
| 144 |
returned: always |
| 145 |
type: str |
| 146 |
sample: 192.168.33.223 |
| 147 |
etag: |
| 148 |
description: |
| 149 |
- A unique read-only string that changes whenever the resource is updated. |
| 150 |
returned: always |
| 151 |
type: str |
| 152 |
sample: 1d8c0731-adc6-4022-9c70-3c389cd73e2a |
| 153 |
id: |
| 154 |
description: |
| 155 |
- Resource ID. |
| 156 |
returned: always |
| 157 |
type: str |
| 158 |
sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/vpnSites/vwam_site_name |
| 159 |
type: |
| 160 |
description: |
| 161 |
- Resource type. |
| 162 |
returned: always |
| 163 |
type: str |
| 164 |
sample: Microsoft.Network/vpnSites |
| 165 |
o365_policy: |
| 166 |
description: |
| 167 |
- Office365 Policy. |
| 168 |
returned: always |
| 169 |
type: dict |
| 170 |
sample: {"break_out_categories": {"allow": false,"default": false,"optimize": false}} |
| 171 |
|
| 172 |
''' |
| 173 |
|
| 174 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 175 |
try: |
| 176 |
from azure.core.exceptions import ResourceNotFoundError |
| 177 |
except ImportError: |
| 178 |
|
| 179 |
pass |
| 180 |
|
| 181 |
|
| 182 |
class AzureRMVpnSiteInfo(AzureRMModuleBase): |
| 183 |
def __init__(self): |
| 184 |
self.module_arg_spec = dict( |
| 185 |
resource_group=dict( |
| 186 |
type='str' |
| 187 |
), |
| 188 |
name=dict( |
| 189 |
type='str' |
| 190 |
) |
| 191 |
) |
| 192 |
|
| 193 |
self.resource_group = None |
| 194 |
self.name = None |
| 195 |
|
| 196 |
self.results = dict(changed=False) |
| 197 |
|
| 198 |
super(AzureRMVpnSiteInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True) |
| 199 |
|
| 200 |
def exec_module(self, **kwargs): |
| 201 |
|
| 202 |
for key in self.module_arg_spec: |
| 203 |
setattr(self, key, kwargs[key]) |
| 204 |
|
| 205 |
if (self.resource_group is not None and self.name is not None): |
| 206 |
self.results['vpn_sites'] = self.format_item(self.get()) |
| 207 |
elif (self.resource_group is not None): |
| 208 |
self.results['vpn_sites'] = self.format_item(self.list_by_resource_group()) |
| 209 |
else: |
| 210 |
self.results['vpn_sites'] = self.format_item(self.list()) |
| 211 |
return self.results |
| 212 |
|
| 213 |
def get(self): |
| 214 |
response = None |
| 215 |
|
| 216 |
try: |
| 217 |
response = self.network_client.vpn_sites.get(resource_group_name=self.resource_group, |
| 218 |
vpn_site_name=self.name) |
| 219 |
except ResourceNotFoundError as e: |
| 220 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 221 |
|
| 222 |
return response |
| 223 |
|
| 224 |
def list_by_resource_group(self): |
| 225 |
response = None |
| 226 |
|
| 227 |
try: |
| 228 |
response = self.network_client.vpn_sites.list_by_resource_group(resource_group_name=self.resource_group) |
| 229 |
except ResourceNotFoundError as e: |
| 230 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 231 |
|
| 232 |
return response |
| 233 |
|
| 234 |
def list(self): |
| 235 |
response = None |
| 236 |
|
| 237 |
try: |
| 238 |
response = self.network_client.vpn_sites.list() |
| 239 |
except ResourceNotFoundError as e: |
| 240 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 241 |
|
| 242 |
return response |
| 243 |
|
| 244 |
def format_item(self, item): |
| 245 |
if hasattr(item, 'as_dict'): |
| 246 |
return [item.as_dict()] |
| 247 |
elif item is not None: |
| 248 |
result = [] |
| 249 |
items = list(item) |
| 250 |
for tmp in items: |
| 251 |
result.append(tmp.as_dict()) |
| 252 |
return result |
| 253 |
else: |
| 254 |
return None |
| 255 |
|
| 256 |
|
| 257 |
def main(): |
| 258 |
AzureRMVpnSiteInfo() |
| 259 |
|
| 260 |
|
| 261 |
if __name__ == '__main__': |
| 262 |
main() |