Skip to content

Commit

Permalink
Migrate account_info (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezilber-akamai authored Aug 16, 2024
1 parent 217b05f commit 3172934
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 63 deletions.
2 changes: 1 addition & 1 deletion docs/modules/account_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Get info about a Linode Account.
## Return Values
- `account` - The account info in JSON serialized form.
- `account` - The returned Account.

- Sample Response:
```json
Expand Down
78 changes: 16 additions & 62 deletions plugins/modules/account_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,33 @@

from __future__ import absolute_import, division, print_function

from typing import Any, List, Optional

import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.account_info as docs
from ansible_collections.linode.cloud.plugins.module_utils.linode_common import (
LinodeModuleBase,
)
from ansible_collections.linode.cloud.plugins.module_utils.linode_docs import (
global_authors,
global_requirements,
from ansible_collections.linode.cloud.plugins.module_utils.linode_common_info import (
InfoModule,
InfoModuleResult,
)
from ansible_specdoc.objects import (
FieldType,
SpecDocMeta,
SpecField,
SpecReturnValue,
)

spec = {
# Disable the default values
"label": SpecField(type=FieldType.string, required=False, doc_hide=True),
"state": SpecField(type=FieldType.string, required=False, doc_hide=True),
}
from ansible_specdoc.objects import FieldType

SPECDOC_META = SpecDocMeta(
description=["Get info about a Linode Account."],
requirements=global_requirements,
author=global_authors,
options=spec,
module = InfoModule(
examples=docs.specdoc_examples,
return_values={
"account": SpecReturnValue(
description="The account info in JSON serialized form.",
docs_url="https://techdocs.akamai.com/linode-api/reference/get-account",
type=FieldType.dict,
sample=docs.result_account_samples,
)
},
primary_result=InfoModuleResult(
display_name="Account",
field_name="account",
field_type=FieldType.dict,
docs_url="https://techdocs.akamai.com/linode-api/reference/get-account",
samples=docs.result_account_samples,
get=lambda client, params: client.account()._raw_json,
),
)

SPECDOC_META = module.spec

DOCUMENTATION = r"""
"""
EXAMPLES = r"""
"""
RETURN = r"""
"""


class Module(LinodeModuleBase):
"""Module for getting info about a Linode Account"""

def __init__(self) -> None:
self.required_one_of: List[str] = []
self.results = {"account": None}

self.module_arg_spec = SPECDOC_META.ansible_spec

super().__init__(
module_arg_spec=self.module_arg_spec,
required_one_of=self.required_one_of,
)

def exec_module(self, **kwargs: Any) -> Optional[dict]:
"""Entrypoint for volume info module"""

self.results["account"] = self.client.account()._raw_json

return self.results


def main() -> None:
"""Constructs and calls the account_info module"""
Module()


if __name__ == "__main__":
main()
module.run()

0 comments on commit 3172934

Please sign in to comment.