Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2018 Yuwei Zhou, <[email protected]>
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_aksversion_info
14
15 version_added: "0.1.2"
16
17 short_description: Get available kubernetes versions supported by Azure Kubernetes Service
18
19 description:
20 - Get available kubernetes versions supported by Azure Kubernetes Service.
21
22 options:
23 location:
24 description:
25 - Get the versions available for creating a managed Kubernetes cluster.
26 required: true
27 type: str
28 version:
29 description:
30 - Get the upgrade versions available for a managed Kubernetes cluster version.
31 type: str
32 allow_preview:
33 description:
34 - Whether Kubernetes version is currently in preview.
35 - If I(allow_preview=True), returns the current preview status of the current Kubernetes version.
36 - If I(allow_preview=False), returns the Kubernetes version in a non-current preview state.
37 - If no set C(allow_preview), returns all the avaiable Kubernetes version.
38 type: bool
39
40 extends_documentation_fragment:
41 - azure.azcollection.azure
42
43 author:
44 - Yuwei Zhou (@yuwzho)
45 '''
46
47 EXAMPLES = '''
48 - name: Get current preview versions for AKS in location eastus
49 azure_rm_aksversion_info:
50 location: eastus
51 allow_preview: true
52 - name: Get available versions for AKS in location eastus
53 azure_rm_aksversion_info:
54 location: eastus
55 - name: Get available versions an AKS can be upgrade to
56 azure_rm_aksversion_info:
57 location: eastis
58 version: 1.11.6
59 '''
60
61 RETURN = '''
62 azure_aks_versions:
63 description: List of supported kubernetes versions.
64 returned: always
65 type: list
66 '''
67
68 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase
69
70
71 class AzureRMAKSVersion(AzureRMModuleBase):
72
73 def __init__(self):
74
75 self.module_args = dict(
76 location=dict(type='str', required=True),
77 version=dict(type='str'),
78 allow_preview=dict(type='bool')
79 )
80
81 self.results = dict(
82 changed=False,
83 azure_aks_versions=[]
84 )
85
86 self.location = None
87 self.version = None
88 self.allow_preview = None
89
90 super(AzureRMAKSVersion, self).__init__(
91 derived_arg_spec=self.module_args,
92 supports_check_mode=True,
93 supports_tags=False,
94 facts_module=True
95 )
96
97 def exec_module(self, **kwargs):
98
99 for key in self.module_args:
100 setattr(self, key, kwargs[key])
101
102 self.results['azure_aks_versions'] = self.get_all_versions(self.location, self.version)
103
104 return self.results
105
106 def get_all_versions(self, location, version):
107 '''
108 Get all kubernetes version supported by AKS
109 :return: ordered version list
110 '''
111 try:
112 result = dict()
113 response = self.containerservice_client.container_services.list_orchestrators(self.location, resource_type='managedClusters')
114 orchestrators = response.orchestrators
115 for item in orchestrators:
116 if self.allow_preview is None:
117 result[item.orchestrator_version] = [x.orchestrator_version for x in item.upgrades] if item.upgrades else []
118 elif self.allow_preview:
119 if item.is_preview:
120 result[item.orchestrator_version] = [x.orchestrator_version for x in item.upgrades] if item.upgrades else []
121 else:
122 if not item.is_preview:
123 result[item.orchestrator_version] = [x.orchestrator_version for x in item.upgrades] if item.upgrades else []
124 if version:
125 return result.get(version) or []
126 else:
127 keys = list(result.keys())
128 keys.sort()
129 return keys
130 except Exception as exc:
131 self.fail('Error when getting AKS supported kubernetes version list for location {0} - {1}'.format(self.location, exc.message or str(exc)))
132
133
134 def main():
135 """Main module execution code path"""
136
137 AzureRMAKSVersion()
138
139
140 if __name__ == '__main__':
141 main()