Skip to content

Commit 419ed81

Browse files
Migrated region list (#564)
1 parent 4eca745 commit 419ed81

File tree

3 files changed

+19
-120
lines changed

3 files changed

+19
-120
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Name | Description |
104104
[linode.cloud.nodebalancer_list](./docs/modules/nodebalancer_list.md)|List and filter on Nodebalancers.|
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.|
107-
[linode.cloud.region_list](./docs/modules/region_list.md)|List and filter on Linode Regions.|
107+
[linode.cloud.region_list](./docs/modules/region_list.md)|List and filter on Regions.|
108108
[linode.cloud.ssh_key_list](./docs/modules/ssh_key_list.md)|List and filter on SSH keys in the Linode profile.|
109109
[linode.cloud.stackscript_list](./docs/modules/stackscript_list.md)|List and filter on Linode stackscripts.|
110110
[linode.cloud.token_list](./docs/modules/token_list.md)|List and filter on Linode Account tokens.|

docs/modules/region_list.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# region_list
22

3-
List and filter on Linode Regions.
3+
List and filter on Regions.
44

55
- [Minimum Required Fields](#minimum-required-fields)
66
- [Examples](#examples)
@@ -32,21 +32,21 @@ List and filter on Linode Regions.
3232
3333
| Field | Type | Required | Description |
3434
|-----------|------|----------|------------------------------------------------------------------------------|
35-
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list regions in. **(Choices: `desc`, `asc`; Default: `asc`)** |
36-
| `order_by` | <center>`str`</center> | <center>Optional</center> | The attribute to order regions by. |
37-
| [`filters` (sub-options)](#filters) | <center>`list`</center> | <center>Optional</center> | A list of filters to apply to the resulting regions. |
38-
| `count` | <center>`int`</center> | <center>Optional</center> | The number of results to return. If undefined, all results will be returned. |
35+
| `order` | <center>`str`</center> | <center>Optional</center> | The order to list Regions in. **(Choices: `desc`, `asc`; Default: `asc`)** |
36+
| `order_by` | <center>`str`</center> | <center>Optional</center> | The attribute to order Regions by. |
37+
| [`filters` (sub-options)](#filters) | <center>`list`</center> | <center>Optional</center> | A list of filters to apply to the resulting Regions. |
38+
| `count` | <center>`int`</center> | <center>Optional</center> | The number of Regions to return. If undefined, all results will be returned. |
3939

4040
### filters
4141

4242
| Field | Type | Required | Description |
4343
|-----------|------|----------|------------------------------------------------------------------------------|
44-
| `name` | <center>`str`</center> | <center>**Required**</center> | The name of the field to filter on. Valid filterable attributes can be found here: https://techdocs.akamai.com/linode-api/reference/get-regions |
44+
| `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-regions). |
4545
| `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. |
4646

4747
## Return Values
4848

49-
- `regions` - The returned regions.
49+
- `regions` - The returned Regions.
5050

5151
- Sample Response:
5252
```json

plugins/modules/region_list.py

+11-112
Original file line numberDiff line numberDiff line change
@@ -4,129 +4,28 @@
44
"""This module allows users to list Linode regions."""
55
from __future__ import absolute_import, division, print_function
66

7-
from typing import Any, Dict, Optional
8-
97
import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.region_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-
construct_api_filter,
19-
get_all_paginated,
8+
from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import (
9+
ListModule,
2010
)
21-
from ansible_specdoc.objects import (
22-
FieldType,
23-
SpecDocMeta,
24-
SpecField,
25-
SpecReturnValue,
26-
)
27-
28-
spec_filter = {
29-
"name": SpecField(
30-
type=FieldType.string,
31-
required=True,
32-
description=[
33-
"The name of the field to filter on.",
34-
"Valid filterable attributes can be found here: "
35-
"https://techdocs.akamai.com/linode-api/reference/get-regions",
36-
],
37-
),
38-
"values": SpecField(
39-
type=FieldType.list,
40-
element_type=FieldType.string,
41-
required=True,
42-
description=[
43-
"A list of values to allow for this field.",
44-
"Fields will pass this filter if at least one of these values matches.",
45-
],
46-
),
47-
}
4811

49-
spec = {
50-
# Disable the default values
51-
"state": SpecField(type=FieldType.string, required=False, doc_hide=True),
52-
"label": SpecField(type=FieldType.string, required=False, doc_hide=True),
53-
"order": SpecField(
54-
type=FieldType.string,
55-
description=["The order to list regions in."],
56-
default="asc",
57-
choices=["desc", "asc"],
58-
),
59-
"order_by": SpecField(
60-
type=FieldType.string,
61-
description=["The attribute to order regions by."],
62-
),
63-
"filters": SpecField(
64-
type=FieldType.list,
65-
element_type=FieldType.dict,
66-
suboptions=spec_filter,
67-
description=["A list of filters to apply to the resulting regions."],
68-
),
69-
"count": SpecField(
70-
type=FieldType.integer,
71-
description=[
72-
"The number of results to return.",
73-
"If undefined, all results will be returned.",
74-
],
75-
),
76-
}
77-
78-
SPECDOC_META = SpecDocMeta(
79-
description=["List and filter on Linode Regions."],
80-
requirements=global_requirements,
81-
author=global_authors,
82-
options=spec,
12+
module = ListModule(
13+
result_display_name="Regions",
14+
result_field_name="regions",
15+
endpoint_template="/regions",
16+
result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-regions",
8317
examples=docs.specdoc_examples,
84-
return_values={
85-
"regions": SpecReturnValue(
86-
description="The returned regions.",
87-
docs_url="https://techdocs.akamai.com/linode-api/reference/get-regions",
88-
type=FieldType.list,
89-
elements=FieldType.dict,
90-
sample=docs.result_regions_samples,
91-
)
92-
},
18+
result_samples=docs.result_regions_samples,
9319
)
9420

21+
SPECDOC_META = module.spec
22+
9523
DOCUMENTATION = r"""
9624
"""
9725
EXAMPLES = r"""
9826
"""
9927
RETURN = r"""
10028
"""
10129

102-
103-
class Module(LinodeModuleBase):
104-
"""Module for getting a list of Linode regions"""
105-
106-
def __init__(self) -> None:
107-
self.module_arg_spec = SPECDOC_META.ansible_spec
108-
self.results: Dict[str, Any] = {"regions": []}
109-
110-
super().__init__(module_arg_spec=self.module_arg_spec)
111-
112-
def exec_module(self, **kwargs: Any) -> Optional[dict]:
113-
"""Entrypoint for region list module"""
114-
115-
filter_dict = construct_api_filter(self.module.params)
116-
117-
self.results["regions"] = get_all_paginated(
118-
self.client,
119-
"/regions",
120-
filter_dict,
121-
num_results=self.module.params["count"],
122-
)
123-
return self.results
124-
125-
126-
def main() -> None:
127-
"""Constructs and calls the module"""
128-
Module()
129-
130-
13130
if __name__ == "__main__":
132-
main()
31+
module.run()

0 commit comments

Comments
 (0)