Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Modules for managing Linode infrastructure.

Name | Description |
--- | ------------ |
[linode.cloud.account_settings](./docs/modules/account_settings.md)|Returns information related to your Account settings.|
[linode.cloud.api_request](./docs/modules/api_request.md)|Make an arbitrary Linode API request.|
[linode.cloud.database_mysql](./docs/modules/database_mysql.md)|Manage a Linode MySQL database.|
[linode.cloud.database_mysql_v2](./docs/modules/database_mysql_v2.md)|Create, read, and update a Linode MySQL database.|
Expand Down
53 changes: 53 additions & 0 deletions docs/modules/account_settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# account_settings

Returns information related to your Account settings.

- [Minimum Required Fields](#minimum-required-fields)
- [Examples](#examples)
- [Parameters](#parameters)
- [Return Values](#return-values)

## Minimum Required Fields
| Field | Type | Required | Description |
|-------------|-------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api_token` | `str` | **Required** | The Linode account personal access token. It is necessary to run the module. <br/>It can be exposed by the environment variable `LINODE_API_TOKEN` instead. <br/>See details in [Usage](https://github.com/linode/ansible_linode?tab=readme-ov-file#usage). |

## Examples

```yaml
- name: Retrieve
linode.cloud.account_settings:
state: present
```


## Parameters

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `state` | <center>`str`</center> | <center>**Required**</center> | The state of Account Settings. **(Choices: `present`)** |
| `backups_enabled` | <center>`bool`</center> | <center>Optional</center> | Account-wide backups default. If true, all Linodes created will automatically be enrolled in the Backups service. If false, Linodes will not be enrolled by default, but may still be enrolled on creation or later. |
| `interfaces_for_new_linodes` | <center>`str`</center> | <center>Optional</center> | Defines if new Linodes can use legacy configuration interfaces. |
| `longview_subscription` | <center>`str`</center> | <center>Optional</center> | The Longview Pro tier you are currently subscribed to. The value must be a Longview subscription ID or null for Longview Free. |
| `managed` | <center>`bool`</center> | <center>Optional</center> | Our 24/7 incident response service. This robust, multi-homed monitoring system distributes monitoring checks to ensure that your servers remain online and available at all times. Linode Managed can monitor any service or software stack reachable over TCP or HTTP. Once you add a service to Linode Managed, we'll monitor it for connectivity, response, and total request time. |
| `network_helper` | <center>`bool`</center> | <center>Optional</center> | Enables network helper across all users by default for new Linodes and Linode Configs. |
| `object_storage` | <center>`str`</center> | <center>Optional</center> | A string describing the status of this account's Object Storage service enrollment. |

## Return Values

- `account_settings` - Account Settings in JSON serialized form.

- Sample Response:
```json
{
"backups_enabled": true,
"interfaces_for_new_linodes": "linode_only",
"longview_subscription": "longview-3",
"managed": true,
"network_helper": false,
"object_storage": "active",
}
```
- See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-account-settings) for a list of returned fields


15 changes: 15 additions & 0 deletions plugins/module_utils/doc_fragments/account_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Documentation fragments for the account settings module"""

specdoc_examples = ['''
- name: Retrieve
linode.cloud.account_settings:
state: present''']

result_account_settings_samples = ['''{
"backups_enabled": true,
"interfaces_for_new_linodes": "linode_only",
"longview_subscription": "longview-3",
"managed": true,
"network_helper": false,
"object_storage": "active",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jriddle-linode When you have a chance, could you make this change and re-render the docs to fix the CI?

Suggested change
"object_storage": "active",
"object_storage": "active"

}''']
151 changes: 151 additions & 0 deletions plugins/modules/account_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""This module allows users to retrieve information about the Linode account settings."""

from __future__ import absolute_import, division, print_function

from typing import Any, Optional, List

import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.account_settings 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_helper import (
filter_null_values,
handle_updates,
)
from ansible_specdoc.objects import (
FieldType,
SpecDocMeta,
SpecField,
SpecReturnValue,
)
from linode_api4 import AccountSettings

SPEC = {
"state": SpecField(
type=FieldType.string,
choices=["present"],
required=True,
description=["The state of Account Settings."],
),
"backups_enabled": SpecField(
type=FieldType.bool,
description=[
"Account-wide backups default. If true, all Linodes created "
"will automatically be enrolled in the Backups service. "
"If false, Linodes will not be enrolled by default, "
"but may still be enrolled on creation or later."
],
),
"interfaces_for_new_linodes": SpecField(
type=FieldType.string,
description=["Defines if new Linodes can use legacy configuration interfaces."],
),
"longview_subscription": SpecField(
type=FieldType.string,
description=[
"The Longview Pro tier you are currently subscribed to. "
"The value must be a Longview subscription ID or null for Longview Free."
],
),
"managed": SpecField(
type=FieldType.bool,
description=[
"Our 24/7 incident response service. This robust, multi-homed "
"monitoring system distributes monitoring checks to ensure that "
"your servers remain online and available at all times. "
"Linode Managed can monitor any service or software stack "
"reachable over TCP or HTTP. Once you add a service to Linode Managed, "
"we'll monitor it for connectivity, response, and total request time."
],
),
"network_helper": SpecField(
type=FieldType.bool,
description=[
"Enables network helper across all users by default "
"for new Linodes and Linode Configs."
],
),
"object_storage": SpecField(
type=FieldType.string,
description=[
"A string describing the status of this account's "
"Object Storage service enrollment."
],
),
}

SPECDOC_META = SpecDocMeta(
description=["Returns information related to your Account settings."],
requirements=global_requirements,
author=global_authors,
options=SPEC,
examples=docs.specdoc_examples,
return_values={
"account_settings": SpecReturnValue(
description="Account Settings in JSON serialized form.",
docs_url="https://techdocs.akamai.com/linode-api/reference/get-account-settings",
type=FieldType.dict,
sample=docs.result_account_settings_samples,
)
},
)

MUTABLE_FIELDS = {"interfaces_for_new_linodes", "backups_enabled", "network_helper"}

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

class Module(LinodeModuleBase):
"""Module for viewing and updating Account Settings"""

def __init__(self) -> None:
self.module_arg_spec = SPECDOC_META.ansible_spec
self.required_one_of: List[str] = []
self.results = {
"changed": False,
"actions": [],
"account_settings": None,
}

self._account_settings: Optional[AccountSettings] = None

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

def _update(self) -> None:
"""Handles all updates for Account Settings"""
handle_updates(
self._account_settings,
filter_null_values(self.module.params),
MUTABLE_FIELDS,
self.register_action,
)

def _present(self) -> None:
self._account_settings = self.client.account.settings()
self._update()
self._account_settings._api_get()
self.results["account_settings"] = self._account_settings._raw_json

def exec_module(self, **kwargs: Any) -> Optional[dict]:
"""Entrypoint for Account Settings module"""
if kwargs.get("state") == "present":
self._present()
return self.results

if __name__ == "__main__":
Module()
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
linode-api4>=5.32.0
# TODO: Revert once the enhanced Linode interfaces support is released in linode_api4
# linode-api4>=5.32.0
git+https://github.com/linode/linode_api4-python@proj/enhanced-interfaces
polling==0.3.2
ansible-specdoc>=0.0.19
42 changes: 42 additions & 0 deletions tests/integration/targets/account_settings/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
- name: account_settings
block:
- set_fact:
r: "{{ 1000000000 | random }}"

- name: Get account_settings
linode.cloud.account_settings:
state: 'present'
register: info

- name: Assert account_settings response
assert:
that:
- info.account_settings.longview_subscription is none
- info.account_settings.managed == false
- info.account_settings.object_storage == 'active'

- name: Update account_settings
linode.cloud.account_settings:
state: 'present'
interfaces_for_new_linodes: 'legacy_config_only'
register: update

- name: Assert account_settings updates
assert:
that:
- update.account_settings.interfaces_for_new_linodes == 'legacy_config_only'

always:
- ignore_errors: yes
block:
- name: Change account_settings back
linode.cloud.account_settings:
state: 'present'
interfaces_for_new_linodes: 'linode_only'

environment:
LINODE_UA_PREFIX: '{{ ua_prefix }}'
LINODE_API_TOKEN: '{{ api_token }}'
LINODE_API_URL: '{{ api_url }}'
LINODE_API_VERSION: '{{ api_version }}'
LINODE_CA: '{{ ca_file or "" }}'
Loading