Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8
9 DOCUMENTATION = '''
10 ---
11 module: azure_rm_postgresqlflexiblevirtualendpoint_info
12 version_added: "3.6.0"
13 short_description: Get or list Azure PostgreSQL Flexible Virtual Endpoints facts
14 description:
15 - Get or list facts of PostgreSQL Flexible Virtual Endpoints.
16
17 options:
18 resource_group:
19 description:
20 - The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
21 type: str
22 required: True
23 server_name:
24 description:
25 - The name of the post gresql server.
26 type: str
27 required: True
28 virtual_endpoint_name:
29 description:
30 - The name of the post gresql virtual endpoint.
31 type: str
32
33 extends_documentation_fragment:
34 - azure.azcollection.azure
35
36 author:
37 - magodo (@magodo)
38 - xuzhang3 (@xuzhang3)
39 - Fred-sun (@Fred-sun)
40
41 '''
42
43 EXAMPLES = '''
44 - name: List instance of PostgreSQL Flexible Virtual Endpoints by server name
45 azure_rm_postgresqlflexiblevirtualendpoint_info:
46 resource_group: myResourceGroup
47 server_name: server_name
48
49 - name: Get instances of PostgreSQL Flexible Virtual Endpoints
50 azure_rm_postgresqlflexiblevirtualendpoint_info:
51 resource_group: myResourceGroup
52 server_name: server_name
53 virutal_endpoint_name: vendpoint
54 '''
55
56 RETURN = '''
57 virtual_endpoints:
58 description:
59 - A list of dictionaries containing facts for PostgreSQL Flexible Virtual Endpoints.
60 returned: always
61 type: complex
62 contains:
63 id:
64 description:
65 - Resource ID of the postgresql flexible virtual endpoints.
66 returned: always
67 type: str
68 sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/postsql01/virtualendpoints/vendpoint"
69 virtual_endpoint_name:
70 description:
71 - Resource name.
72 returned: always
73 type: str
74 sample: vendpoint
75 endpoint_type:
76 description:
77 - The endpoint type for the virtual endpoint.
78 returned: always
79 type: str
80 sample: ReadWrite
81 resource_group:
82 description:
83 - The resoure group name.
84 returned: always
85 type: str
86 sample: myResourceGroup
87 members:
88 description:
89 - List of members for a virtual endpoint.
90 returned: always
91 type: list
92 sample: ['postsqlrpfx01']
93 server_name:
94 description:
95 - The Post gresql flexibeserver name.
96 returned: always
97 type: str
98 sample: postsql01
99 virtual_endpoints:
100 description:
101 - List of virtual endpoints for a server.
102 returned: always
103 type: list
104 sample: ["vendpoint.writer.postgres.database.azure.com", "vendpoint.reader.postgres.database.azure.com"]
105 type:
106 description:
107 - The type of the resource.
108 returned: always
109 type: str
110 sample: Microsoft.DBforPostgreSQL/flexibleServers/virtualendpoints
111 '''
112
113
114 try:
115 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
116 from azure.core.exceptions import ResourceNotFoundError
117 except ImportError:
118 # This is handled in azure_rm_common
119 pass
120
121
122 class AzureRMPostgreSqlFlexibleVirtualEndpointInfo(AzureRMModuleBase):
123 def __init__(self):
124 # define user inputs into argument
125 self.module_arg_spec = dict(
126 resource_group=dict(
127 type='str',
128 required=True
129 ),
130 server_name=dict(
131 type='str',
132 required=True
133 ),
134 virtual_endpoint_name=dict(
135 type='str'
136 ),
137 )
138 # store the results of the module operation
139 self.results = dict(
140 changed=False
141 )
142 self.resource_group = None
143 self.virtual_endpoint_name = None
144 self.server_name = None
145 super(AzureRMPostgreSqlFlexibleVirtualEndpointInfo, self).__init__(self.module_arg_spec,
146 supports_check_mode=True,
147 supports_tags=False,
148 facts_module=True)
149
150 def exec_module(self, **kwargs):
151 for key in self.module_arg_spec:
152 setattr(self, key, kwargs[key])
153
154 if self.virtual_endpoint_name:
155 self.results['virtual_endpoints'] = self.get()
156 else:
157 self.results['virtual_endpoints'] = self.list_all()
158 return self.results
159
160 def get(self):
161 response = None
162 results = []
163 try:
164 response = self.postgresql_flexible_client.virtual_endpoints.get(resource_group_name=self.resource_group,
165 server_name=self.server_name,
166 virtual_endpoint_name=self.virtual_endpoint_name)
167 self.log("Response : {0}".format(response))
168 except ResourceNotFoundError:
169 self.log('Could not get virtual endpoint facts for PostgreSQL Flexible Server.')
170
171 if response:
172 results.append(self.format_item(response))
173
174 return results
175
176 def list_all(self):
177 response = None
178 results = []
179 try:
180 response = self.postgresql_flexible_client.virtual_endpoints.list_by_server(resource_group_name=self.resource_group,
181 server_name=self.server_name)
182 self.log("Response : {0}".format(response))
183 except Exception as ec:
184 self.log('Could not list virtual endpoints facts for PostgreSQL Flexible Servers.')
185
186 if response:
187 for item in response:
188 results.append(self.format_item(item))
189
190 return results
191
192 def format_item(self, item):
193 return dict(
194 resource_group=self.resource_group,
195 server_name=self.server_name,
196 id=item.id,
197 endpoint_type=item.endpoint_type,
198 members=item.members,
199 virtual_endpoint_name=item.name,
200 type=item.type,
201 virtual_endpoints=item.virtual_endpoints
202 )
203
204
205 def main():
206 AzureRMPostgreSqlFlexibleVirtualEndpointInfo()
207
208
209 if __name__ == '__main__':
210 main()