|
4 | 4 | """This module allows users to list Users."""
|
5 | 5 | from __future__ import absolute_import, division, print_function
|
6 | 6 |
|
7 |
| -from typing import Any, Dict, Optional |
8 |
| - |
9 | 7 | import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.user_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, |
19 |
| -) |
20 |
| -from ansible_specdoc.objects import ( |
21 |
| - FieldType, |
22 |
| - SpecDocMeta, |
23 |
| - SpecField, |
24 |
| - SpecReturnValue, |
| 8 | +from ansible_collections.linode.cloud.plugins.module_utils.linode_common_list import ( |
| 9 | + ListModule, |
25 | 10 | )
|
26 | 11 |
|
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 users 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=["List Users."], |
48 |
| - requirements=global_requirements, |
49 |
| - author=global_authors, |
50 |
| - options=spec, |
| 12 | +module = ListModule( |
| 13 | + result_display_name="Users", |
| 14 | + result_field_name="users", |
| 15 | + endpoint_template="/account/users", |
| 16 | + result_docs_url="https://techdocs.akamai.com/linode-api/reference/get-users", |
51 | 17 | examples=docs.specdoc_examples,
|
52 |
| - return_values={ |
53 |
| - "users": SpecReturnValue( |
54 |
| - description="The returned users.", |
55 |
| - docs_url=( |
56 |
| - "https://techdocs.akamai.com/linode-api/reference/get-account" |
57 |
| - ), |
58 |
| - type=FieldType.list, |
59 |
| - elements=FieldType.dict, |
60 |
| - sample=docs.result_users_samples, |
61 |
| - ) |
62 |
| - }, |
| 18 | + result_samples=docs.result_users_samples, |
63 | 19 | )
|
64 | 20 |
|
| 21 | +SPECDOC_META = module.spec |
| 22 | + |
65 | 23 | DOCUMENTATION = r"""
|
66 | 24 | """
|
67 | 25 | EXAMPLES = r"""
|
68 | 26 | """
|
69 | 27 | RETURN = r"""
|
70 | 28 | """
|
71 | 29 |
|
72 |
| - |
73 |
| -class Module(LinodeModuleBase): |
74 |
| - """Module for getting a list of Users""" |
75 |
| - |
76 |
| - def __init__(self) -> None: |
77 |
| - self.module_arg_spec = SPECDOC_META.ansible_spec |
78 |
| - self.results: Dict[str, Any] = {"users": []} |
79 |
| - |
80 |
| - super().__init__(module_arg_spec=self.module_arg_spec) |
81 |
| - |
82 |
| - def exec_module(self, **kwargs: Any) -> Optional[dict]: |
83 |
| - """Entrypoint for user module""" |
84 |
| - |
85 |
| - self.results["users"] = get_all_paginated( |
86 |
| - self.client, |
87 |
| - "/account/users", |
88 |
| - None, |
89 |
| - num_results=self.module.params["count"], |
90 |
| - ) |
91 |
| - return self.results |
92 |
| - |
93 |
| - |
94 |
| -def main() -> None: |
95 |
| - """Constructs and calls the module""" |
96 |
| - Module() |
97 |
| - |
98 |
| - |
99 | 30 | if __name__ == "__main__":
|
100 |
| - main() |
| 31 | + module.run() |
0 commit comments