Skip to content

Commit

Permalink
Merge pull request #379 from linode/dev
Browse files Browse the repository at this point in the history
v0.16.1
  • Loading branch information
jriddle-linode authored Jun 13, 2023
2 parents 97b369d + d3d2c98 commit ad91960
Show file tree
Hide file tree
Showing 81 changed files with 1,256 additions and 1,214 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
run-docs-validation:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: pip3 install -r requirements-dev.txt -r requirements.txt

- name: install ansible dependencies
run: ansible-galaxy collection install amazon.aws:==1.5.1
run: ansible-galaxy collection install amazon.aws:==6.0.1

- name: install collection
run: make install
Expand All @@ -61,7 +61,7 @@ jobs:
env:
LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}

- uses: actions/github-script@v5
- uses: actions/github-script@v6
id: update-check-run
if: ${{ always() }}
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
run-tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
Expand All @@ -34,7 +34,7 @@ jobs:
run: pip3 install -r requirements-dev.txt -r requirements.txt

- name: install ansible dependencies
run: ansible-galaxy collection install amazon.aws:==1.5.1
run: ansible-galaxy collection install amazon.aws:==6.0.1

- name: install collection
run: make install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
lint:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@fe52e97d262833ae07d05efaf1a239df3f1b5cd4 # pin@v5
- uses: release-drafter/release-drafter@569eb7ee3a85817ab916c8f8ff03a5bd96c9c83e # pin@v5.23.0
with:
config-name: release-drafter.yml
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: pip3 install -r requirements-dev.txt -r requirements.txt

- name: install ansible dependencies
run: ansible-galaxy collection install amazon.aws:==1.5.1
run: ansible-galaxy collection install amazon.aws:==6.0.1

- name: publish the collection
run: make publish
Expand Down
25 changes: 0 additions & 25 deletions .pylintrc

This file was deleted.

4 changes: 2 additions & 2 deletions docs/modules/firewall.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Manage Linode Firewalls.
| `action` | <center>`str`</center> | <center>**Required**</center> | Controls whether traffic is accepted or dropped by this rule. **(Choices: `ACCEPT`, `DROP`)** |
| [`addresses` (sub-options)](#addresses) | <center>`dict`</center> | <center>Optional</center> | Allowed IPv4 or IPv6 addresses. |
| `description` | <center>`str`</center> | <center>Optional</center> | A description for this rule. |
| `ports` | <center>`str`</center> | <center>Optional</center> | A string representing the port or ports on which traffic will be allowed. See U(https://www.linode.com/docs/api/networking/#firewall-create) |
| `ports` | <center>`str`</center> | <center>Optional</center> | A string representing the port or ports on which traffic will be allowed. See https://www.linode.com/docs/api/networking/#firewall-create |
| `protocol` | <center>`str`</center> | <center>Optional</center> | The type of network traffic to allow. |

### addresses
Expand All @@ -104,7 +104,7 @@ Manage Linode Firewalls.
| `action` | <center>`str`</center> | <center>**Required**</center> | Controls whether traffic is accepted or dropped by this rule. **(Choices: `ACCEPT`, `DROP`)** |
| [`addresses` (sub-options)](#addresses) | <center>`dict`</center> | <center>Optional</center> | Allowed IPv4 or IPv6 addresses. |
| `description` | <center>`str`</center> | <center>Optional</center> | A description for this rule. |
| `ports` | <center>`str`</center> | <center>Optional</center> | A string representing the port or ports on which traffic will be allowed. See U(https://www.linode.com/docs/api/networking/#firewall-create) |
| `ports` | <center>`str`</center> | <center>Optional</center> | A string representing the port or ports on which traffic will be allowed. See https://www.linode.com/docs/api/networking/#firewall-create |
| `protocol` | <center>`str`</center> | <center>Optional</center> | The type of network traffic to allow. |

## Return Values
Expand Down
4 changes: 3 additions & 1 deletion docs/modules/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Manage Linode Instances, Configs, and Disks.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `state` | <center>`str`</center> | <center>**Required**</center> | The desired state of the target. **(Choices: `present`, `absent`)** |
| `type` | <center>`str`</center> | <center>Optional</center> | The unique label to give this instance. |
| `label` | <center>`str`</center> | <center>Optional</center> | The unique label to give this instance. |
| `type` | <center>`str`</center> | <center>Optional</center> | The Linode Type of the Linode you are creating. |
| `region` | <center>`str`</center> | <center>Optional</center> | The location to deploy the instance in. See the [Linode API documentation](https://api.linode.com/v4/regions). |
| `image` | <center>`str`</center> | <center>Optional</center> | The image ID to deploy the instance disk from. **(Conflicts With: `disks`,`configs`)** |
| `authorized_keys` | <center>`list`</center> | <center>Optional</center> | A list of SSH public key parts to deploy for the root user. |
Expand All @@ -108,6 +109,7 @@ Manage Linode Instances, Configs, and Disks.
| `wait` | <center>`bool`</center> | <center>Optional</center> | Wait for the instance to have status "running" before returning. **(Default: `True`)** |
| `wait_timeout` | <center>`int`</center> | <center>Optional</center> | The amount of time, in seconds, to wait for an instance to have status "running". **(Default: `240`)** |
| [`additional_ipv4` (sub-options)](#additional_ipv4) | <center>`list`</center> | <center>Optional</center> | Additional ipv4 addresses to allocate. |
| `rebooted` | <center>`bool`</center> | <center>Optional</center> | If true, the Linode Instance will be rebooted. NOTE: The instance will only be rebooted if it was previously in a running state. To ensure your Linode will always be rebooted, consider also setting the `booted` field. **(Default: `False`)** |

### configs

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Manage a Linode Volume.
| `label` | <center>`str`</center> | <center>Optional</center> | The Volume’s label, which is also used in the filesystem_path of the resulting volume. |
| `config_id` | <center>`int`</center> | <center>Optional</center> | When creating a Volume attached to a Linode, the ID of the Linode Config to include the new Volume in. |
| `linode_id` | <center>`int`</center> | <center>Optional</center> | The Linode this volume should be attached to upon creation. If not given, the volume will be created without an attachment. **(Updatable)** |
| `region` | <center>`str`</center> | <center>Optional</center> | The location to deploy the volume in. See U(https://api.linode.com/v4/regions) |
| `region` | <center>`str`</center> | <center>Optional</center> | The location to deploy the volume in. See https://api.linode.com/v4/regions |
| `size` | <center>`int`</center> | <center>Optional</center> | The size of this volume, in GB. Be aware that volumes may only be resized up after creation. **(Updatable)** |
| `attached` | <center>`bool`</center> | <center>Optional</center> | If true, the volume will be attached to a Linode. Otherwise, the volume will be detached. **(Default: `True`; Updatable)** |
| `wait_timeout` | <center>`int`</center> | <center>Optional</center> | The amount of time, in seconds, to wait for a volume to have the active status. **(Default: `240`)** |
Expand Down
85 changes: 47 additions & 38 deletions plugins/module_utils/linode_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,45 @@
f"Ansible/{ANSIBLE_VERSION}"
)

LINODE_COMMON_ARGS = dict(
api_token=dict(
type="str",
fallback=(env_fallback, ["LINODE_API_TOKEN", "LINODE_TOKEN"]),
required=True,
no_log=True,
),
api_version=dict(
type="str",
fallback=(env_fallback, ["LINODE_API_VERSION"]),
default="v4",
),
state=dict(
type="str",
required=True,
choices=["present", "absent"],
),
ua_prefix=dict(
type="str",
description="An HTTP User-Agent Prefix to prepend in API requests.",
doc_hide=True,
fallback=(env_fallback, ["LINODE_UA_PREFIX"]),
),
)

LINODE_TAG_ARGS = dict(
tags=dict(type="list", description="The tags to assign to this resource."),
)

LINODE_LABEL_ARGS = dict(
label=dict(
type="str",
required=True,
description="The label to assign to this resource.",
),
)
LINODE_COMMON_ARGS = {
"api_token": {
"type": "str",
"fallback": (env_fallback, ["LINODE_API_TOKEN", "LINODE_TOKEN"]),
"required": True,
"no_log": True,
},
"api_version": {
"type": "str",
"fallback": (env_fallback, ["LINODE_API_VERSION"]),
"default": "v4",
},
"state": {
"type": "str",
"required": True,
"choices": ["present", "absent"],
},
"ua_prefix": {
"type": "str",
"description": "An HTTP User-Agent Prefix to prepend in API requests.",
"doc_hide": True,
"fallback": (env_fallback, ["LINODE_UA_PREFIX"]),
},
}

LINODE_TAG_ARGS = {
"tags": {
"type": "list",
"description": "The tags to assign to this resource.",
},
}

LINODE_LABEL_ARGS = {
"label": {
"type": "str",
"required": True,
"description": "The label to assign to this resource.",
},
}

RESOURCE_NAMES = (
{
Expand All @@ -103,6 +106,10 @@
else {}
)

MAX_RETRIES = 5
RETRY_INTERVAL_SECONDS = float(4)
RETRY_STATUSES = {408, 429, 502}


class LinodeModuleBase:
"""A base for all Linode resource modules."""
Expand Down Expand Up @@ -147,7 +154,7 @@ def __init__(
required_if=required_if,
)

self.results: dict = self.results or dict(changed=False, actions=[])
self.results: dict = self.results or {"changed": False, "actions": []}

# This field may or may not be present depending on the module
timeout_param = self.module.params.get("wait_timeout", 120)
Expand Down Expand Up @@ -240,7 +247,9 @@ def client(self) -> LinodeClient:
api_token,
base_url="https://api.linode.com/{0}".format(api_version),
user_agent=user_agent,
retry_rate_limit_interval=10,
retry_rate_limit_interval=RETRY_INTERVAL_SECONDS,
retry_max=MAX_RETRIES,
retry_statuses=RETRY_STATUSES,
)

return self._client
14 changes: 7 additions & 7 deletions plugins/module_utils/linode_database_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@
from ansible_specdoc.objects import FieldType, SpecField
from linode_api4 import ApiError

SPEC_UPDATE_WINDOW = dict(
day_of_week=SpecField(
SPEC_UPDATE_WINDOW = {
"day_of_week": SpecField(
type=FieldType.integer,
required=True,
choices=list(range(1, 8)),
description=[
"The day to perform maintenance. 1=Monday, 2=Tuesday, etc."
],
),
duration=SpecField(
"duration": SpecField(
type=FieldType.integer,
required=True,
choices=[1, 3],
description=["The maximum maintenance window time in hours."],
),
frequency=SpecField(
"frequency": SpecField(
type=FieldType.string,
choices=["weekly", "monthly"],
default="weekly",
description=[
"Whether maintenance occurs on a weekly or monthly basis."
],
),
hour_of_day=SpecField(
"hour_of_day": SpecField(
type=FieldType.integer,
required=True,
description=["The hour to begin maintenance based in UTC time."],
),
week_of_month=SpecField(
"week_of_month": SpecField(
type=FieldType.integer,
description=[
"The week of the month to perform monthly frequency updates.",
Expand All @@ -44,7 +44,7 @@
"Must be null for weekly frequency updates.",
],
),
)
}


def validate_allow_list(allow_list: Set[str]) -> None:
Expand Down
40 changes: 0 additions & 40 deletions plugins/module_utils/linode_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""This module contains helper functions for various Linode modules."""
import math
import time
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, cast

import linode_api4
Expand All @@ -19,10 +18,6 @@
FilterableMetaclass,
)

MAX_RETRIES = 5
RETRY_INTERVAL_SECONDS = 4
RETRY_STATUSES = {408}


def dict_select_spec(target: dict, spec: dict) -> dict:
"""Returns a new dictionary that only selects the keys from target that are specified in spec"""
Expand Down Expand Up @@ -205,41 +200,6 @@ def validate_required(required_fields: Set[str], params: Dict[str, Any]):
raise Exception("missing fields: {}".format(", ".join(missing_fields)))


def request_retry(
request_func: Callable,
retry_statuses=None,
retry_interval=RETRY_INTERVAL_SECONDS,
max_retries=MAX_RETRIES,
) -> any:
"""Retries requests if the response status code matches the retry_statuses set."""
# Default value for set
if retry_statuses is None:
retry_statuses = RETRY_STATUSES

number_attempts = 0

while number_attempts < max_retries:
number_attempts += 1

try:
response = request_func()
except ApiError as exception:
if exception.status not in retry_statuses:
raise exception

time.sleep(retry_interval)

continue
except Exception as exception:
raise exception

return response

raise Exception(
"exceeded maximum number of retries: {0}".format(max_retries)
)


def filter_null_values_recursive(obj: Any) -> Any:
"""Recursively removes null values and keys from a structure."""
if isinstance(obj, dict):
Expand Down
Loading

0 comments on commit ad91960

Please sign in to comment.