| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: azure_rm_virtualhubconnection_info |
| 15 |
version_added: '1.14.0' |
| 16 |
short_description: Get VirtualHub info |
| 17 |
description: |
| 18 |
- Get info of VirtualHub. |
| 19 |
options: |
| 20 |
resource_group: |
| 21 |
description: |
| 22 |
- The resource group name of the VirtualHub. |
| 23 |
type: str |
| 24 |
required: True |
| 25 |
virtual_hub_name: |
| 26 |
description: |
| 27 |
- The resource name of the VirtualHub. |
| 28 |
type: str |
| 29 |
required: True |
| 30 |
name: |
| 31 |
description: |
| 32 |
- The name of the VirtualHub connection. |
| 33 |
type: str |
| 34 |
extends_documentation_fragment: |
| 35 |
- azure.azcollection.azure |
| 36 |
author: |
| 37 |
- Fred-Sun (@Fred-Sun) |
| 38 |
- Xu Zhang (@xuzhang3) |
| 39 |
|
| 40 |
''' |
| 41 |
|
| 42 |
EXAMPLES = ''' |
| 43 |
- name: Get virtual hub connection info by name |
| 44 |
azure_rm_virtualhubconnection_info: |
| 45 |
resource_group: myResourceGroup |
| 46 |
virtual_hub_name: virtualHub |
| 47 |
name: vhubname |
| 48 |
|
| 49 |
- name: Get virtual hub connection info by resource group |
| 50 |
azure_rm_virtualhubconnection_info: |
| 51 |
resource_group: myResourceGroup |
| 52 |
virtual_hub_name: virtualHub |
| 53 |
''' |
| 54 |
|
| 55 |
RETURN = ''' |
| 56 |
virtual_hub_connection: |
| 57 |
description: |
| 58 |
- A list of dict results for the virtual hub connection info. |
| 59 |
returned: always |
| 60 |
type: complex |
| 61 |
contains: |
| 62 |
id: |
| 63 |
description: |
| 64 |
- Resource ID. |
| 65 |
returned: always |
| 66 |
type: str |
| 67 |
sample: "/subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Network/virtualHubs/vhub/hubVirtualNetworkConnections/MyConnection" |
| 68 |
name: |
| 69 |
description: |
| 70 |
- Resource name. |
| 71 |
returned: always |
| 72 |
type: str |
| 73 |
sample: MyConnection |
| 74 |
etag: |
| 75 |
description: |
| 76 |
- A unique read-only string that changes whenever the resource is updated. |
| 77 |
returned: always |
| 78 |
type: str |
| 79 |
sample: 31102041-49e7-4cac-8573-aac1e1a16793 |
| 80 |
remote_virtual_network: |
| 81 |
description: |
| 82 |
- Name of ID of the remote VNet to connect to. |
| 83 |
returned: always |
| 84 |
type: complex |
| 85 |
contains: |
| 86 |
id: |
| 87 |
description: |
| 88 |
- The ID of the remote VNet to connect to. |
| 89 |
returned: always |
| 90 |
type: str |
| 91 |
sample: /subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Network/virtualNetworks/testvnet |
| 92 |
routing_configuration: |
| 93 |
description: |
| 94 |
- The routing configuration information |
| 95 |
returned: always |
| 96 |
type: complex |
| 97 |
contains: |
| 98 |
associated_route_table: |
| 99 |
description: |
| 100 |
- The resource ID of route table associated with this routing configuration. |
| 101 |
type: complex |
| 102 |
returned: always |
| 103 |
contains: |
| 104 |
id: |
| 105 |
description: |
| 106 |
- The ID of the routetable. |
| 107 |
type: str |
| 108 |
returned: always |
| 109 |
sample: /subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Network/virtualHubs/testhub/hubRouteTables/rt_name |
| 110 |
propagated_route_tables: |
| 111 |
description: |
| 112 |
- Space-separated list of resource id of propagated route tables. |
| 113 |
type: complex |
| 114 |
returned: always |
| 115 |
contains: |
| 116 |
ids: |
| 117 |
description: |
| 118 |
- The list resource ID of propagated route tables. |
| 119 |
type: list |
| 120 |
returned: always |
| 121 |
sample: [{id: '/subscriptions/xxx-xxx/resourceGroups/myRG/providers/Microsoft.Network/virtualHubs/testhub/hubRouteTables/rt_name'}] |
| 122 |
labels: |
| 123 |
description: |
| 124 |
- Space-separated list of labels for propagated route tables. |
| 125 |
type: list |
| 126 |
returned: always |
| 127 |
sample: ['labels1', 'labels2'] |
| 128 |
vnet_routes: |
| 129 |
description: |
| 130 |
- The name of the Static Route that is unique within a Vnet Route. |
| 131 |
returned: always |
| 132 |
type: complex |
| 133 |
contains: |
| 134 |
static_routes: |
| 135 |
description: |
| 136 |
- The name of the Static Route. |
| 137 |
type: list |
| 138 |
returned: always |
| 139 |
contains: |
| 140 |
address_prefixes: |
| 141 |
description: |
| 142 |
- Space-separated list of all address prefixes. |
| 143 |
type: list |
| 144 |
returned: always |
| 145 |
sample: ["10.1.0.0/16", "10.2.0.0/16"] |
| 146 |
name: |
| 147 |
description: |
| 148 |
- The name of static router. |
| 149 |
type: str |
| 150 |
returned: always |
| 151 |
sample: route1 |
| 152 |
next_hop_ip_address: |
| 153 |
description: |
| 154 |
- The next hop ip address. |
| 155 |
type: str |
| 156 |
returned: always |
| 157 |
sample: 10.0.0.65 |
| 158 |
provisioning_state: |
| 159 |
description: |
| 160 |
- The provisioning state of the virtual hub connection resource. |
| 161 |
returned: always |
| 162 |
type: str |
| 163 |
sample: Succeeded |
| 164 |
allow_hub_to_remote_vnet_transit: |
| 165 |
description: |
| 166 |
- (Deprecated) Enable hub to remote VNet transit. |
| 167 |
- This field has been deprecated and will be removed in next major version release. |
| 168 |
returned: always |
| 169 |
type: bool |
| 170 |
sample: true |
| 171 |
allow_remote_vnet_to_use_hub_vnet_gateways: |
| 172 |
description: |
| 173 |
- (Deprecated) Allow remote VNet to use hub's VNet gateways. |
| 174 |
- This field has been deprecated and will be removed in next major version release. |
| 175 |
returned: always |
| 176 |
type: bool |
| 177 |
sample: true |
| 178 |
enable_internet_security: |
| 179 |
description: |
| 180 |
- Enable internet security and default is enabled. |
| 181 |
type: bool |
| 182 |
returned: always |
| 183 |
sample: true |
| 184 |
''' |
| 185 |
|
| 186 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 187 |
try: |
| 188 |
from azure.core.exceptions import ResourceNotFoundError |
| 189 |
except ImportError: |
| 190 |
|
| 191 |
pass |
| 192 |
|
| 193 |
|
| 194 |
class AzureRMVirtualHubConnectionInfo(AzureRMModuleBase): |
| 195 |
def __init__(self): |
| 196 |
self.module_arg_spec = dict( |
| 197 |
resource_group=dict( |
| 198 |
type='str', |
| 199 |
required=True |
| 200 |
), |
| 201 |
name=dict( |
| 202 |
type='str' |
| 203 |
), |
| 204 |
virtual_hub_name=dict( |
| 205 |
type='str', |
| 206 |
required=True |
| 207 |
) |
| 208 |
) |
| 209 |
|
| 210 |
self.resource_group = None |
| 211 |
self.name = None |
| 212 |
self.virtual_hub_name = None |
| 213 |
|
| 214 |
self.results = dict(changed=False) |
| 215 |
self.state = None |
| 216 |
self.status_code = [200] |
| 217 |
|
| 218 |
super(AzureRMVirtualHubConnectionInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False) |
| 219 |
|
| 220 |
def exec_module(self, **kwargs): |
| 221 |
|
| 222 |
for key in self.module_arg_spec: |
| 223 |
setattr(self, key, kwargs[key]) |
| 224 |
|
| 225 |
if self.name is not None: |
| 226 |
self.results['virtual_hub_connection'] = self.format_item(self.get()) |
| 227 |
else: |
| 228 |
self.results['virtual_hub_connection'] = self.format_item(self.list()) |
| 229 |
return self.results |
| 230 |
|
| 231 |
def get(self): |
| 232 |
response = None |
| 233 |
|
| 234 |
try: |
| 235 |
response = self.network_client.hub_virtual_network_connections.get(resource_group_name=self.resource_group, |
| 236 |
virtual_hub_name=self.virtual_hub_name, |
| 237 |
connection_name=self.name) |
| 238 |
except ResourceNotFoundError: |
| 239 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 240 |
|
| 241 |
return response |
| 242 |
|
| 243 |
def list(self): |
| 244 |
response = None |
| 245 |
|
| 246 |
try: |
| 247 |
response = self.network_client.hub_virtual_network_connections.list(resource_group_name=self.resource_group, |
| 248 |
virtual_hub_name=self.virtual_hub_name) |
| 249 |
except Exception: |
| 250 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 251 |
|
| 252 |
return response |
| 253 |
|
| 254 |
def format_item(self, item): |
| 255 |
if item is None: |
| 256 |
return None |
| 257 |
elif hasattr(item, 'as_dict'): |
| 258 |
return [item.as_dict()] |
| 259 |
else: |
| 260 |
result = [] |
| 261 |
items = list(item) |
| 262 |
for tmp in items: |
| 263 |
result.append(tmp.as_dict()) |
| 264 |
return result |
| 265 |
|
| 266 |
|
| 267 |
def main(): |
| 268 |
AzureRMVirtualHubConnectionInfo() |
| 269 |
|
| 270 |
|
| 271 |
if __name__ == '__main__': |
| 272 |
main() |