Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2020 Fred-Sun, (@Fred-Sun)
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_virtualwan_info
14 version_added: '1.5.0'
15 short_description: Get VirtualWan info
16 description:
17 - Get info of VirtualWan.
18 options:
19 resource_group:
20 description:
21 - The resource group name of the VirtualWan.
22 type: str
23 name:
24 description:
25 - The name of the VirtualWAN 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 EXAMPLES = '''
35 - name: Get Virtual WAN by name
36 azure_rm_virtualwan_info:
37 resource_group: myResouceGroup
38 name: testwan
39
40 - name: List all Virtual WANLs by resource group
41 azure_rm_virtualwan_info:
42 resource_group: myResourceGroup
43
44 - name: List all Virtual WANs by subscription_id
45 azure_rm_virtualwan_info:
46 '''
47
48 RETURN = '''
49 virtual_wans:
50 description:
51 - A list of dict results where the key is the name of the VirtualWan and the values are the facts for that VirtualWan.
52 returned: always
53 type: complex
54 contains:
55 id:
56 description:
57 - Resource ID.
58 returned: always
59 type: str
60 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualWans/testwan
61 name:
62 description:
63 - Resource name.
64 returned: always
65 type: str
66 sample: testwan
67 type:
68 description:
69 - Resource type.
70 returned: always
71 type: str
72 sample: Microsoft.Network/virtualWans
73 location:
74 description:
75 - Resource location.
76 returned: always
77 type: str
78 sample: eastus
79 tags:
80 description:
81 - Resource tags.
82 returned: always
83 type: dict
84 sample: { 'key1': 'value1'}
85 etag:
86 description:
87 - A unique read-only string that changes whenever the resource is updated.
88 returned: always
89 type: str
90 sample: "86df6f3d-19f2-4cc8-8574-47921de4a6f1"
91 disable_vpn_encryption:
92 description:
93 - Vpn encryption to be disabled or not.
94 returned: always
95 type: bool
96 sample: false
97 virtual_hubs:
98 description:
99 - List of VirtualHubs in the VirtualWAN.
100 type: complex
101 contains:
102 id:
103 description:
104 - The virtual hubs list of the virtual wan.
105 returned: always
106 type: str
107 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualHubs/test
108 vpn_sites:
109 description:
110 - List of VpnSites in the VirtualWAN.
111 returned: always
112 type: complex
113 contains:
114 id:
115 description:
116 - The vpn site resource ID.
117 returned: always
118 type: str
119 sample: /subscriptions/xxx-xxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/vpnSites/test1
120 allow_branch_to_branch_traffic:
121 description:
122 - True if branch to branch traffic is allowed.
123 returned: always
124 type: bool
125 sample: true
126 allow_vnet_to_vnet_traffic:
127 description:
128 - True if Vnet to Vnet traffic is allowed.
129 returned: always
130 type: bool
131 sample: True
132 office365_local_breakout_category:
133 description:
134 - The office local breakout category.
135 returned: always
136 type: str
137 sample: None
138 provisioning_state:
139 description:
140 - The provisioning state of the virtual WAN resource.
141 returned: always
142 type: str
143 sample: Succeeded
144 virtual_wan_type:
145 description:
146 - The type of virtual wan.
147 returned: always
148 type: str
149 sample: Standard
150 '''
151
152 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
153 try:
154 from azure.core.exceptions import ResourceNotFoundError
155 except ImportError:
156 # This is handled in azure_rm_common
157 pass
158
159
160 class AzureRMVirtualWanInfo(AzureRMModuleBase):
161 def __init__(self):
162 self.module_arg_spec = dict(
163 resource_group=dict(
164 type='str'
165 ),
166 name=dict(
167 type='str'
168 )
169 )
170
171 self.resource_group = None
172 self.name = None
173
174 self.results = dict(changed=False)
175
176 super(AzureRMVirtualWanInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True)
177
178 def exec_module(self, **kwargs):
179
180 for key in self.module_arg_spec:
181 setattr(self, key, kwargs[key])
182
183 if (self.resource_group is not None and self.name is not None):
184 self.results['virtual_wans'] = self.format_item(self.get())
185 elif (self.resource_group is not None):
186 self.results['virtual_wans'] = self.format_item(self.list_by_resource_group())
187 else:
188 self.results['virtual_wans'] = self.format_item(self.list())
189 return self.results
190
191 def get(self):
192 response = None
193
194 try:
195 response = self.network_client.virtual_wans.get(resource_group_name=self.resource_group,
196 virtual_wan_name=self.name)
197 except ResourceNotFoundError as e:
198 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
199
200 return response
201
202 def list_by_resource_group(self):
203 response = None
204
205 try:
206 response = self.network_client.virtual_wans.list_by_resource_group(resource_group_name=self.resource_group)
207 except ResourceNotFoundError as e:
208 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
209
210 return response
211
212 def list(self):
213 response = None
214
215 try:
216 response = self.network_client.virtual_wans.list()
217 except ResourceNotFoundError as e:
218 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
219
220 return response
221
222 def format_item(self, item):
223 if hasattr(item, 'as_dict'):
224 return [item.as_dict()]
225 else:
226 result = []
227 items = list(item)
228 for tmp in items:
229 result.append(tmp.as_dict())
230 return result
231
232
233 def main():
234 AzureRMVirtualWanInfo()
235
236
237 if __name__ == '__main__':
238 main()