Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai committed Aug 15, 2024
2 parents 584f648 + 217b05f commit a700d08
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/modules/profile_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Get info about a Linode Profile.
## Return Values
- `profile` - The profile info in JSON serialized form.
- `profile` - The returned Profile.

- Sample Response:
```json
Expand Down
24 changes: 20 additions & 4 deletions plugins/module_utils/linode_common_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class InfoModuleResult:
samples (Optional[List[str]]): A list of sample results for this field.
get (Optional[Callable]): A function to call out to the API and return the data
for this field.
NOTE: This is only relevant for secondary results.
NOTE: This is only relevant for secondary results
or primary result without any attributes.
"""

field_name: str
Expand All @@ -105,7 +106,7 @@ class InfoModuleResult:
docs_url: Optional[str] = None
samples: Optional[List[str]] = None
get: Optional[
Callable[[LinodeClient, Dict[str, Any], Dict[str, Any]], Any]
Callable[[LinodeClient, Dict[str, Any], Optional[Dict[str, Any]]], Any]
] = None


Expand All @@ -116,7 +117,9 @@ def __init__(
self,
primary_result: InfoModuleResult,
secondary_results: List[InfoModuleResult] = None,
params: Optional[List[Union[InfoModuleParam, InfoModuleParamGroup]]] = None,
params: Optional[
List[Union[InfoModuleParam, InfoModuleParamGroup]]
] = None,
attributes: List[InfoModuleAttr] = None,
examples: List[str] = None,
description: List[str] = None,
Expand Down Expand Up @@ -170,6 +173,16 @@ def exec_module(self, **kwargs: Any) -> Optional[dict]:
)
break

if primary_result is None:
# Get the primary result using the result get function
try:
primary_result = self.primary_result.get(self.client, kwargs)
except Exception as exception:
self.fail(
msg="Failed to get result for "
f"{self.primary_result.display_name}: {exception}"
)

if primary_result is None:
raise ValueError("Expected a result; got None")

Expand Down Expand Up @@ -261,7 +274,6 @@ def run(self) -> None:
"""
Initializes and runs the info module.
"""

attribute_names = [v.name for v in self.attributes]

base_module_args = {
Expand All @@ -270,6 +282,10 @@ def run(self) -> None:
"mutually_exclusive": [attribute_names],
}

if len(attribute_names) > 0:
base_module_args["required_one_of"].append(attribute_names)
base_module_args["mutually_exclusive"].append(attribute_names)

for entry in self.param_groups:
if InfoModuleParamGroupPolicy.exactly_one_of in entry.policies:
param_names = [param.name for param in entry.params]
Expand Down
81 changes: 17 additions & 64 deletions plugins/modules/profile_info.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,37 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""This module allows users to retrieve information about the current Linode profile."""
"""This module contains all of the functionality for Linode Profile info."""

from __future__ import absolute_import, division, print_function

from typing import Any, List, Optional

import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.profile_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_specdoc.objects import (
FieldType,
SpecDocMeta,
SpecField,
SpecReturnValue,
from ansible_collections.linode.cloud.plugins.module_utils.linode_common_info import (
InfoModule,
InfoModuleResult,
)
from ansible_specdoc.objects import FieldType

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),
}


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

SPECDOC_META = module.spec

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


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

def __init__(self) -> None:
self.required_one_of: List[str] = []
self.results = {"profile": 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["profile"] = self.client.profile()._raw_json

return self.results


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


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

0 comments on commit a700d08

Please sign in to comment.