|
1 | 1 | #!/usr/bin/python
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 |
| -"""This module allows users to list Linode instances.""" |
5 |
| -from __future__ import absolute_import, division, print_function |
| 4 | +"""This module allows users to list Linode LKE Versions.""" |
6 | 5 |
|
7 |
| -from typing import Any, Dict, Optional |
| 6 | +from __future__ import absolute_import, division, print_function |
8 | 7 |
|
9 |
| -import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.lke_version_list as docs |
10 |
| -from ansible_collections.linode.cloud.plugins.module_utils.linode_common import ( |
11 |
| - LinodeModuleBase, |
12 |
| -) |
13 |
| -from ansible_collections.linode.cloud.plugins.module_utils.linode_docs import ( |
14 |
| - global_authors, |
15 |
| - global_requirements, |
16 |
| -) |
17 |
| -from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import ( |
18 |
| - get_all_paginated, |
| 8 | +from ansible_collections.linode.cloud.plugins.module_utils.doc_fragments import ( |
| 9 | + lke_version_list as docs, |
19 | 10 | )
|
20 |
| -from ansible_specdoc.objects import ( |
21 |
| - FieldType, |
22 |
| - SpecDocMeta, |
23 |
| - SpecField, |
24 |
| - SpecReturnValue, |
| 11 | +from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import ( |
| 12 | + ListModule, |
25 | 13 | )
|
26 | 14 |
|
27 |
| -spec = { |
28 |
| - # Disable the default values |
29 |
| - "state": SpecField(type=FieldType.string, required=False, doc_hide=True), |
30 |
| - "label": SpecField(type=FieldType.string, required=False, doc_hide=True), |
31 |
| - "order": SpecField( |
32 |
| - type=FieldType.string, |
33 |
| - description=["The order to list lke versions in."], |
34 |
| - default="asc", |
35 |
| - choices=["desc", "asc"], |
36 |
| - ), |
37 |
| - "count": SpecField( |
38 |
| - type=FieldType.integer, |
39 |
| - description=[ |
40 |
| - "The number of results to return.", |
41 |
| - "If undefined, all results will be returned.", |
42 |
| - ], |
43 |
| - ), |
44 |
| -} |
45 |
| - |
46 |
| -SPECDOC_META = SpecDocMeta( |
47 |
| - description=[ |
48 |
| - "List Kubernetes versions available for deployment to a Kubernetes cluster." |
49 |
| - ], |
50 |
| - requirements=global_requirements, |
51 |
| - author=global_authors, |
52 |
| - options=spec, |
| 15 | +module = ListModule( |
| 16 | + result_display_name="LKE Versions", |
| 17 | + result_field_name="lke_versions", |
| 18 | + endpoint_template="/lke/versions", |
| 19 | + result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-lke-versions", |
| 20 | + result_samples=docs.result_lke_versions_samples, |
53 | 21 | examples=docs.specdoc_examples,
|
54 |
| - return_values={ |
55 |
| - "lke_versions": SpecReturnValue( |
56 |
| - description="The returned LKE versions.", |
57 |
| - docs_url="https://techdocs.akamai.com/linode-api/reference/get-lke-versions", |
58 |
| - type=FieldType.list, |
59 |
| - elements=FieldType.dict, |
60 |
| - sample=docs.result_lke_versions_samples, |
61 |
| - ) |
62 |
| - }, |
63 | 22 | )
|
64 | 23 |
|
| 24 | +SPECDOC_META = module.spec |
| 25 | + |
65 | 26 | DOCUMENTATION = r"""
|
66 | 27 | """
|
67 | 28 | EXAMPLES = r"""
|
68 | 29 | """
|
69 | 30 | RETURN = r"""
|
70 | 31 | """
|
71 | 32 |
|
72 |
| - |
73 |
| -class Module(LinodeModuleBase): |
74 |
| - """Module for getting a list of Kubernetes versions""" |
75 |
| - |
76 |
| - def __init__(self) -> None: |
77 |
| - self.module_arg_spec = SPECDOC_META.ansible_spec |
78 |
| - self.results: Dict[str, Any] = {"lke_versions": []} |
79 |
| - |
80 |
| - super().__init__(module_arg_spec=self.module_arg_spec) |
81 |
| - |
82 |
| - def exec_module(self, **kwargs: Any) -> Optional[dict]: |
83 |
| - """Entrypoint for lke version list module""" |
84 |
| - |
85 |
| - self.results["lke_versions"] = get_all_paginated( |
86 |
| - self.client, |
87 |
| - "/lke/versions", |
88 |
| - None, |
89 |
| - num_results=self.module.params["count"], |
90 |
| - ) |
91 |
| - |
92 |
| - return self.results |
93 |
| - |
94 |
| - |
95 |
| -def main() -> None: |
96 |
| - """Constructs and calls the module""" |
97 |
| - Module() |
98 |
| - |
99 |
| - |
100 | 33 | if __name__ == "__main__":
|
101 |
| - main() |
| 34 | + module.run() |
0 commit comments