| 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_vpnsitelink_info |
| 14 |
version_added: '1.5.0' |
| 15 |
short_description: Get VpnSiteLink info |
| 16 |
description: |
| 17 |
- Get info of Vpn Site Link relate infomation. |
| 18 |
options: |
| 19 |
resource_group: |
| 20 |
description: |
| 21 |
- The resource group name of the VpnSite. |
| 22 |
required: true |
| 23 |
type: str |
| 24 |
vpn_site_name: |
| 25 |
description: |
| 26 |
- The name of the Vpn Site. |
| 27 |
required: true |
| 28 |
type: str |
| 29 |
name: |
| 30 |
description: |
| 31 |
- The name of the VpnSiteLink being retrieved. |
| 32 |
type: str |
| 33 |
extends_documentation_fragment: |
| 34 |
- azure.azcollection.azure |
| 35 |
- azure.azcollection.azure_tags |
| 36 |
author: |
| 37 |
- Fred-Sun (@Fred-Sun) |
| 38 |
- Haiyuan Zhang (@haiyuazhang) |
| 39 |
|
| 40 |
''' |
| 41 |
|
| 42 |
EXAMPLES = ''' |
| 43 |
- name: Get Vpn Site Link info by the name |
| 44 |
azure_rm_vpnsitelink_info: |
| 45 |
resource_group: myResourceGroup |
| 46 |
name: vpnSiteLink1 |
| 47 |
vpn_site_name: vpnSite1 |
| 48 |
|
| 49 |
|
| 50 |
- name: Get Vpn Site Links by the Vpn Site |
| 51 |
azure_rm_vpnsitelink_info: |
| 52 |
resource_group: myResourceGroup |
| 53 |
vpn_site_name: vpnSite1 |
| 54 |
''' |
| 55 |
|
| 56 |
RETURN = ''' |
| 57 |
vpn_site_links: |
| 58 |
description: |
| 59 |
- A list of dict results where the key is the name of the VpnSiteLink and the values are the facts for that VpnSiteLink. |
| 60 |
returned: always |
| 61 |
type: complex |
| 62 |
contains: |
| 63 |
id: |
| 64 |
description: |
| 65 |
- Resource ID. |
| 66 |
returned: always |
| 67 |
type: str |
| 68 |
sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/vpnSites/fred/vpnSiteLinks/azureuser |
| 69 |
etag: |
| 70 |
description: |
| 71 |
- A unique read-only string that changes whenever the resource is updated. |
| 72 |
returned: always |
| 73 |
type: str |
| 74 |
sample: 1ec5c61b-d66f-4b1c-b7b5-f27d0a9ad9d3 |
| 75 |
name: |
| 76 |
description: |
| 77 |
- The name of the resource that is unique within a resource group. |
| 78 |
- This name can be used to access the resource. |
| 79 |
returned: always |
| 80 |
type: str |
| 81 |
sample: azureuser |
| 82 |
type: |
| 83 |
description: |
| 84 |
- Resource type. |
| 85 |
returned: always |
| 86 |
type: str |
| 87 |
sample: Microsoft.Network/vpnSites/vpnSiteLinks |
| 88 |
link_properties: |
| 89 |
description: |
| 90 |
- The link provider properties. |
| 91 |
returned: always |
| 92 |
type: complex |
| 93 |
contains: |
| 94 |
link_provider_name: |
| 95 |
description: |
| 96 |
- Name of the link provider. |
| 97 |
returned: always |
| 98 |
type: str |
| 99 |
sample: azureuser |
| 100 |
link_speed_in_mbps: |
| 101 |
description: |
| 102 |
- Link speed. |
| 103 |
returned: always |
| 104 |
type: int |
| 105 |
sample: 100 |
| 106 |
ip_address: |
| 107 |
description: |
| 108 |
- The ip-address for the vpn-site-link. |
| 109 |
returned: always |
| 110 |
type: str |
| 111 |
sample: 192.168.33.223 |
| 112 |
provisioning_state: |
| 113 |
description: |
| 114 |
- The provisioning state of the VPN site link resource. |
| 115 |
returned: always |
| 116 |
type: str |
| 117 |
sample: Succeeded |
| 118 |
''' |
| 119 |
|
| 120 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 121 |
try: |
| 122 |
from azure.core.exceptions import ResourceNotFoundError |
| 123 |
except ImportError: |
| 124 |
|
| 125 |
pass |
| 126 |
|
| 127 |
|
| 128 |
class AzureRMVpnSiteLinkInfo(AzureRMModuleBase): |
| 129 |
def __init__(self): |
| 130 |
self.module_arg_spec = dict( |
| 131 |
resource_group=dict( |
| 132 |
type='str', |
| 133 |
required=True |
| 134 |
), |
| 135 |
vpn_site_name=dict( |
| 136 |
type='str', |
| 137 |
required=True |
| 138 |
), |
| 139 |
name=dict( |
| 140 |
type='str' |
| 141 |
) |
| 142 |
) |
| 143 |
|
| 144 |
self.resource_group = None |
| 145 |
self.vpn_site_name = None |
| 146 |
name = None |
| 147 |
|
| 148 |
self.results = dict(changed=False) |
| 149 |
self.state = None |
| 150 |
|
| 151 |
super(AzureRMVpnSiteLinkInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True) |
| 152 |
|
| 153 |
def exec_module(self, **kwargs): |
| 154 |
|
| 155 |
for key in self.module_arg_spec: |
| 156 |
setattr(self, key, kwargs[key]) |
| 157 |
|
| 158 |
if (self.resource_group is not None and self.vpn_site_name is not None and self.name is not None): |
| 159 |
self.results['vpn_site_links'] = self.format_item(self.get()) |
| 160 |
elif (self.resource_group is not None and self.vpn_site_name is not None): |
| 161 |
self.results['vpn_site_links'] = self.format_item(self.list_by_vpn_site()) |
| 162 |
return self.results |
| 163 |
|
| 164 |
def get(self): |
| 165 |
response = None |
| 166 |
|
| 167 |
try: |
| 168 |
response = self.network_client.vpn_site_links.get(resource_group_name=self.resource_group, |
| 169 |
vpn_site_name=self.vpn_site_name, |
| 170 |
vpn_site_link_name=self.name) |
| 171 |
except ResourceNotFoundError as e: |
| 172 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 173 |
|
| 174 |
return response |
| 175 |
|
| 176 |
def list_by_vpn_site(self): |
| 177 |
response = None |
| 178 |
|
| 179 |
try: |
| 180 |
response = self.network_client.vpn_site_links.list_by_vpn_site(resource_group_name=self.resource_group, |
| 181 |
vpn_site_name=self.vpn_site_name) |
| 182 |
except ResourceNotFoundError as e: |
| 183 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 184 |
|
| 185 |
return response |
| 186 |
|
| 187 |
def format_item(self, item): |
| 188 |
if hasattr(item, 'as_dict'): |
| 189 |
return [item.as_dict()] |
| 190 |
elif item is not None: |
| 191 |
result = [] |
| 192 |
items = list(item) |
| 193 |
for tmp in items: |
| 194 |
result.append(tmp.as_dict()) |
| 195 |
return result |
| 196 |
else: |
| 197 |
return None |
| 198 |
|
| 199 |
|
| 200 |
def main(): |
| 201 |
AzureRMVpnSiteLinkInfo() |
| 202 |
|
| 203 |
|
| 204 |
if __name__ == '__main__': |
| 205 |
main() |