Skip to content

Commit 0ce1e79

Browse files
authored
ref: Migrate lke_version_list to use common list info (#573)
1 parent 73cbd64 commit 0ce1e79

File tree

3 files changed

+29
-87
lines changed

3 files changed

+29
-87
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Name | Description |
100100
[linode.cloud.image_list](./docs/modules/image_list.md)|List and filter on Images.|
101101
[linode.cloud.instance_list](./docs/modules/instance_list.md)|List and filter on Instances.|
102102
[linode.cloud.instance_type_list](./docs/modules/instance_type_list.md)|**NOTE: This module has been deprecated in favor of `type_list`.|
103-
[linode.cloud.lke_version_list](./docs/modules/lke_version_list.md)|List Kubernetes versions available for deployment to a Kubernetes cluster.|
103+
[linode.cloud.lke_version_list](./docs/modules/lke_version_list.md)|List and filter on LKE Versions.|
104104
[linode.cloud.nodebalancer_list](./docs/modules/nodebalancer_list.md)|List and filter on Node Balancers.|
105105
[linode.cloud.object_cluster_list](./docs/modules/object_cluster_list.md)|**NOTE: This module has been deprecated because it relies on deprecated API endpoints. Going forward, `region` will be the preferred way to designate where Object Storage resources should be created.**|
106106
[linode.cloud.placement_group_list](./docs/modules/placement_group_list.md)|List and filter on Placement Groups.|

docs/modules/lke_version_list.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# lke_version_list
22

3-
List Kubernetes versions available for deployment to a Kubernetes cluster.
3+
List and filter on LKE Versions.
44

55
- [Minimum Required Fields](#minimum-required-fields)
66
- [Examples](#examples)
@@ -24,12 +24,21 @@ List Kubernetes versions available for deployment to a Kubernetes cluster.
2424
2525
| Field | Type | Required | Description |
2626
|-----------|------|----------|------------------------------------------------------------------------------|
27-
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list lke versions in. **(Choices: `desc`, `asc`; Default: `asc`)** |
28-
| `count` | <center>`int`</center> | <center>Optional</center> | The number of results to return. If undefined, all results will be returned. |
27+
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list LKE Versions in. **(Choices: `desc`, `asc`; Default: `asc`)** |
28+
| `order_by` | <center>`str`</center> | <center>Optional</center> | The attribute to order LKE Versions by. |
29+
| [`filters` (sub-options)](#filters) | <center>`list`</center> | <center>Optional</center> | A list of filters to apply to the resulting LKE Versions. |
30+
| `count` | <center>`int`</center> | <center>Optional</center> | The number of LKE Versions to return. If undefined, all results will be returned. |
31+
32+
### filters
33+
34+
| Field | Type | Required | Description |
35+
|-----------|------|----------|------------------------------------------------------------------------------|
36+
| `name` | <center>`str`</center> | <center>**Required**</center> | The name of the field to filter on. Valid filterable fields can be found [here](https://techdocs.akamai.com/linode-api/reference/get-lke-versions). |
37+
| `values` | <center>`list`</center> | <center>**Required**</center> | A list of values to allow for this field. Fields will pass this filter if at least one of these values matches. |
2938

3039
## Return Values
3140

32-
- `lke_versions` - The returned LKE versions.
41+
- `lke_versions` - The returned LKE Versions.
3342

3443
- Sample Response:
3544
```json

plugins/modules/lke_version_list.py

+15-82
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,34 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33

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."""
65

7-
from typing import Any, Dict, Optional
6+
from __future__ import absolute_import, division, print_function
87

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,
1910
)
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,
2513
)
2614

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,
5321
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-
},
6322
)
6423

24+
SPECDOC_META = module.spec
25+
6526
DOCUMENTATION = r"""
6627
"""
6728
EXAMPLES = r"""
6829
"""
6930
RETURN = r"""
7031
"""
7132

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-
10033
if __name__ == "__main__":
101-
main()
34+
module.run()

0 commit comments

Comments
 (0)