Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_webappvnetconnection_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2021 Ross Bender (@l3ender)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_webappvnetconnection_info
14
15 version_added: "1.8.0"
16
17 short_description: Get Azure web app virtual network connection facts
18
19 description:
20 - Get facts for a web app's virtual network connection.
21
22 options:
23 name:
24 description:
25 - Name of the web app.
26 required: true
27 type: str
28 resource_group:
29 description:
30 - Resource group of the web app.
31 required: true
32 type: str
33
34 extends_documentation_fragment:
35 - azure.azcollection.azure
36
37 author:
38 - Ross Bender (@l3ender)
39 '''
40
41 EXAMPLES = '''
42 - name: Get web app virtual network connection
43 azure_rm_webappvnetconnection_info:
44 name: "MyWebapp"
45 resource_group: "MyResourceGroup"
46 '''
47
48 RETURN = '''
49 connection:
50 description:
51 - The web app's virtual network connection.
52 returned: always
53 type: complex
54 contains:
55 id:
56 description:
57 - ID of the web app virtual network connection.
58 returned: always
59 type: str
60 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Web/sites/myWebApp/virtualNetworkConnections/yyy-yyy_subnet
61 name:
62 description:
63 - Name of the web app virtual network connection.
64 returned: always
65 type: str
66 sample: yyy-yyy_subnet
67 subnet_name:
68 description:
69 - Name of the subnet connected to the web app.
70 returned: always
71 type: str
72 sample: mySubnet
73 vnet_name:
74 description:
75 - Name of the virtual network connected to the web app.
76 returned: always
77 type: str
78 sample: myVnet
79 vnet_resource_group:
80 description:
81 - Name of the resource group the virtual network is in.
82 returned: always
83 type: str
84 sample: myResourceGroup
85 vnet_resource_id:
86 description:
87 - ID of the virtual network/subnet connected to the web app.
88 returned: always
89 type: str
90 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet
91 '''
92
93 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
94
95
96 class AzureRMWebAppVnetConnectionInfo(AzureRMModuleBase):
97
98 def __init__(self):
99
100 self.module_arg_spec = dict(
101 name=dict(type='str', required=True),
102 resource_group=dict(type='str', required=True),
103 )
104
105 self.results = dict(
106 changed=False,
107 connection=dict(),
108 )
109
110 self.name = None
111 self.resource_group = None
112
113 super(AzureRMWebAppVnetConnectionInfo, self).__init__(self.module_arg_spec,
114 supports_check_mode=True,
115 supports_tags=False,
116 facts_module=True)
117
118 def exec_module(self, **kwargs):
119 for key in self.module_arg_spec:
120 setattr(self, key, kwargs[key])
121
122 vnet = self.get_vnet_connection()
123
124 if vnet:
125 self.results['connection'] = self.set_results(vnet)
126
127 return self.results
128
129 def get_vnet_connection(self):
130 connections = self.list_vnet_connections()
131 for connection in connections:
132 if connection.is_swift:
133 return connection
134
135 return None
136
137 def list_vnet_connections(self):
138 try:
139 return self.web_client.web_apps.list_vnet_connections(resource_group_name=self.resource_group, name=self.name)
140 except Exception as exc:
141 self.fail("Error getting webapp vnet connections {0} (rg={1}) - {2}".format(self.name, self.resource_group, str(exc)))
142
143 def set_results(self, vnet):
144 vnet_dict = vnet.as_dict()
145
146 output = dict()
147 output['id'] = vnet_dict['id']
148 output['name'] = vnet_dict['name']
149 subnet_id = vnet_dict['vnet_resource_id']
150 output['vnet_resource_id'] = subnet_id
151 subnet_detail = self.get_subnet_detail(subnet_id)
152 output['vnet_resource_group'] = subnet_detail['resource_group']
153 output['vnet_name'] = subnet_detail['vnet_name']
154 output['subnet_name'] = subnet_detail['subnet_name']
155
156 return output
157
158
159 def main():
160 AzureRMWebAppVnetConnectionInfo()
161
162
163 if __name__ == '__main__':
164 main()