Skip to content

Commit 2c5fe73

Browse files
Merge pull request #695 from linode/dev
Release v0.40.0
2 parents 8a9ce68 + 1c8e5dc commit 2c5fe73

File tree

8 files changed

+249
-4
lines changed

8 files changed

+249
-4
lines changed

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
steps:
207207
- name: Notify Slack
208208
id: main_message
209-
uses: slackapi/slack-github-action@v2.1.0
209+
uses: slackapi/slack-github-action@v2.1.1
210210
with:
211211
method: chat.postMessage
212212
token: ${{ secrets.SLACK_BOT_TOKEN }}
@@ -238,7 +238,7 @@ jobs:
238238
239239
- name: Test summary thread
240240
if: success()
241-
uses: slackapi/slack-github-action@v2.1.0
241+
uses: slackapi/slack-github-action@v2.1.1
242242
with:
243243
method: chat.postMessage
244244
token: ${{ secrets.SLACK_BOT_TOKEN }}

.github/workflows/nightly-smoke-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454

5555
- name: Notify Slack
5656
if: (success() || failure()) && github.repository == 'linode/ansible_linode'
57-
uses: slackapi/slack-github-action@v2.1.0
57+
uses: slackapi/slack-github-action@v2.1.1
5858
with:
5959
method: chat.postMessage
6060
token: ${{ secrets.SLACK_BOT_TOKEN }}

.github/workflows/release-notify-slack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- name: Notify Slack - Main Message
1313
id: main_message
14-
uses: slackapi/slack-github-action@v2.1.0
14+
uses: slackapi/slack-github-action@v2.1.1
1515
with:
1616
method: chat.postMessage
1717
token: ${{ secrets.SLACK_BOT_TOKEN }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Modules for managing Linode infrastructure.
2121

2222
Name | Description |
2323
--- | ------------ |
24+
[linode.cloud.account_settings](./docs/modules/account_settings.md)|Returns information related to your Account settings.|
2425
[linode.cloud.api_request](./docs/modules/api_request.md)|Make an arbitrary Linode API request.|
2526
[linode.cloud.database_mysql](./docs/modules/database_mysql.md)|Manage a Linode MySQL database.|
2627
[linode.cloud.database_mysql_v2](./docs/modules/database_mysql_v2.md)|Create, read, and update a Linode MySQL database.|

docs/modules/account_settings.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# account_settings
2+
3+
Returns information related to your Account settings.
4+
5+
- [Minimum Required Fields](#minimum-required-fields)
6+
- [Examples](#examples)
7+
- [Parameters](#parameters)
8+
- [Return Values](#return-values)
9+
10+
## Minimum Required Fields
11+
| Field | Type | Required | Description |
12+
|-------------|-------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
13+
| `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). |
14+
15+
## Examples
16+
17+
```yaml
18+
- name: Retrieve
19+
linode.cloud.account_settings:
20+
state: present
21+
```
22+
23+
24+
## Parameters
25+
26+
| Field | Type | Required | Description |
27+
|-----------|------|----------|------------------------------------------------------------------------------|
28+
| `state` | <center>`str`</center> | <center>**Required**</center> | The state of Account Settings. **(Choices: `present`)** |
29+
| `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. |
30+
| `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. |
31+
| `network_helper` | <center>`bool`</center> | <center>Optional</center> | Enables network helper across all users by default for new Linodes and Linode Configs. |
32+
33+
## Return Values
34+
35+
- `account_settings` - Account Settings in JSON serialized form.
36+
37+
- Sample Response:
38+
```json
39+
{
40+
"backups_enabled": true,
41+
"interfaces_for_new_linodes": "linode_only",
42+
"longview_subscription": "longview-3",
43+
"managed": true,
44+
"network_helper": false,
45+
"object_storage": "active"
46+
}
47+
```
48+
- See the [Linode API response documentation](https://techdocs.akamai.com/linode-api/reference/get-account-settings) for a list of returned fields
49+
50+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Documentation fragments for the account settings module"""
2+
3+
specdoc_examples = ['''
4+
- name: Retrieve
5+
linode.cloud.account_settings:
6+
state: present''']
7+
8+
result_account_settings_samples = ['''{
9+
"backups_enabled": true,
10+
"interfaces_for_new_linodes": "linode_only",
11+
"longview_subscription": "longview-3",
12+
"managed": true,
13+
"network_helper": false,
14+
"object_storage": "active"
15+
}''']
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
"""This module allows users to retrieve and modify Linode account settings."""
5+
6+
from __future__ import absolute_import, division, print_function
7+
8+
from typing import Any, List, Optional
9+
10+
import ansible_collections.linode.cloud.plugins.module_utils.doc_fragments.account_settings as docs
11+
from ansible_collections.linode.cloud.plugins.module_utils.linode_common import (
12+
LinodeModuleBase,
13+
)
14+
from ansible_collections.linode.cloud.plugins.module_utils.linode_docs import (
15+
global_authors,
16+
global_requirements,
17+
)
18+
from ansible_collections.linode.cloud.plugins.module_utils.linode_helper import (
19+
filter_null_values,
20+
handle_updates,
21+
)
22+
from ansible_specdoc.objects import (
23+
FieldType,
24+
SpecDocMeta,
25+
SpecField,
26+
SpecReturnValue,
27+
)
28+
from linode_api4 import AccountSettings
29+
30+
SPEC = {
31+
"state": SpecField(
32+
type=FieldType.string,
33+
choices=["present"],
34+
required=True,
35+
description=["The state of Account Settings."],
36+
),
37+
"backups_enabled": SpecField(
38+
type=FieldType.bool,
39+
description=[
40+
"Account-wide backups default. If true, all Linodes created "
41+
"will automatically be enrolled in the Backups service. "
42+
"If false, Linodes will not be enrolled by default, "
43+
"but may still be enrolled on creation or later."
44+
],
45+
),
46+
"longview_subscription": SpecField(
47+
type=FieldType.string,
48+
description=[
49+
"The Longview Pro tier you are currently subscribed to. "
50+
"The value must be a Longview subscription ID or null for Longview Free."
51+
],
52+
),
53+
"network_helper": SpecField(
54+
type=FieldType.bool,
55+
description=[
56+
"Enables network helper across all users by default "
57+
"for new Linodes and Linode Configs."
58+
],
59+
),
60+
}
61+
62+
SPECDOC_META = SpecDocMeta(
63+
description=["Returns information related to your Account settings."],
64+
requirements=global_requirements,
65+
author=global_authors,
66+
options=SPEC,
67+
examples=docs.specdoc_examples,
68+
return_values={
69+
"account_settings": SpecReturnValue(
70+
description="Account Settings in JSON serialized form.",
71+
docs_url="https://techdocs.akamai.com/linode-api/reference/get-account-settings",
72+
type=FieldType.dict,
73+
sample=docs.result_account_settings_samples,
74+
)
75+
},
76+
)
77+
78+
MUTABLE_FIELDS = {"backups_enabled", "network_helper"}
79+
80+
DOCUMENTATION = r"""
81+
"""
82+
EXAMPLES = r"""
83+
"""
84+
RETURN = r"""
85+
"""
86+
87+
88+
class Module(LinodeModuleBase):
89+
"""Module for viewing and updating Account Settings"""
90+
91+
def __init__(self) -> None:
92+
self.module_arg_spec = SPECDOC_META.ansible_spec
93+
self.required_one_of: List[str] = []
94+
self.results = {
95+
"changed": False,
96+
"actions": [],
97+
"account_settings": None,
98+
}
99+
100+
self._account_settings: Optional[AccountSettings] = None
101+
102+
super().__init__(
103+
module_arg_spec=self.module_arg_spec,
104+
required_one_of=self.required_one_of,
105+
)
106+
107+
def _update(self) -> None:
108+
"""Handles all updates for Account Settings"""
109+
handle_updates(
110+
self._account_settings,
111+
filter_null_values(self.module.params),
112+
MUTABLE_FIELDS,
113+
self.register_action,
114+
)
115+
116+
def _present(self) -> None:
117+
self._account_settings = self.client.account.settings()
118+
self._update()
119+
self._account_settings._api_get()
120+
self.results["account_settings"] = self._account_settings._raw_json
121+
122+
def exec_module(self, **kwargs: Any) -> Optional[dict]:
123+
"""Entrypoint for Account Settings module"""
124+
if kwargs.get("state") == "present":
125+
self._present()
126+
return self.results
127+
128+
129+
if __name__ == "__main__":
130+
Module()
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
- name: account_settings
2+
block:
3+
- set_fact:
4+
r: "{{ 1000000000 | random }}"
5+
6+
- name: Get account_settings
7+
linode.cloud.account_settings:
8+
state: 'present'
9+
register: info
10+
11+
- name: Assert account_settings response
12+
assert:
13+
that:
14+
- "'longview_subscription' in info.account_settings"
15+
- info.account_settings.managed is not none
16+
- info.account_settings.object_storage is not none
17+
- info.account_settings.network_helper is not none
18+
- info.account_settings.backups_enabled is not none
19+
20+
- name: Determine opposite of backups_enabled
21+
set_fact:
22+
original_backups_enabled: "{{ info.account_settings.backups_enabled }}"
23+
toggled_backups_enabled: "{{ not info.account_settings.backups_enabled }}"
24+
25+
- name: Update account_settings
26+
linode.cloud.account_settings:
27+
state: 'present'
28+
backups_enabled: "{{ toggled_backups_enabled }}"
29+
register: update
30+
31+
- name: Assert account_settings was updated
32+
assert:
33+
that:
34+
- update.account_settings.backups_enabled == toggled_backups_enabled
35+
36+
always:
37+
- ignore_errors: yes
38+
block:
39+
- name: Revert account settings changes
40+
linode.cloud.account_settings:
41+
state: 'present'
42+
backups_enabled: "{{ original_backups_enabled }}"
43+
44+
environment:
45+
LINODE_UA_PREFIX: '{{ ua_prefix }}'
46+
LINODE_API_TOKEN: '{{ api_token }}'
47+
LINODE_API_URL: '{{ api_url }}'
48+
LINODE_API_VERSION: '{{ api_version }}'
49+
LINODE_CA: '{{ ca_file or "" }}'

0 commit comments

Comments
 (0)