-
Notifications
You must be signed in to change notification settings - Fork 25
Adds Account Settings #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jriddle-linode
wants to merge
2
commits into
linode:proj/linode-interfaces
Choose a base branch
from
jriddle-linode:interfacces/accounts
base: proj/linode-interfaces
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}'''] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
42
tests/integration/targets/account_settings/tasks/main.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" }}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?