Skip to content
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

ci: add support for ruff format and linting #42

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Ruff
on:
pull_request:
jobs:
format:
name: Format
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v2
with:
args: "format --check"
check:
name: Check
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v2
93 changes: 6 additions & 87 deletions plugins/inventory/scaleway.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,6 @@

__metaclass__ = type

DOCUMENTATION = r"""
name: scaleway
author:
- Nathanael Demacon (@quantumsheep)
short_description: Scaleway inventory source
version_added: "1.0.0"
requirements:
- scaleway >= 0.6.0
description:
- Scaleway inventory plugin.
- Uses configuration file that ends with '(scaleway|scw).(yaml|yml)'.
extends_documentation_fragment:
- scaleway.scaleway.scaleway
- constructed
- inventory_cache
options:
plugin:
description:
- The name of the Scaleway Inventory Plugin, this should always be C(scaleway.scaleway.scaleway).
required: true
choices: ['scaleway.scaleway.scaleway']
zones:
description:
- List of zones to filter on.
type: list
elements: str
default:
- fr-par-1
- fr-par-2
- fr-par-3
- nl-ams-1
- nl-ams-2
- pl-waw-1
- pl-waw-2
tags:
description:
- List of tags to filter on.
type: list
elements: str
default: []
hostnames:
description: List of preference about what to use as an hostname.
type: list
elements: str
default:
- public_ipv4
choices:
- public_ipv4
- private_ipv4
- public_ipv6
- hostname
- id
variables:
description:
- "Variables mapping to apply to hosts in the format destination_variable: host_variable."
- "You can use the following host variables:"
- " - C(id): The server id."
- " - C(tags): The server tags."
- " - C(zone): The server zone."
- " - C(state): The server state."
- " - C(hostname): The server hostname."
- " - C(public_ipv4): The server public ipv4."
- " - C(private_ipv4): The server private ipv4."
- " - C(public_ipv6): The server public ipv6."
- " - C(public_dns): The server public dns."
- " - C(private_dns): The server private dns."
- ""
- "If the variable is not found, the host will be ignored."
type: dict
"""

EXAMPLES = r"""
plugin: scaleway.scaleway.scaleway
access_key: <your access key>
secret_key: <your secret key>
api_url: https://api.scaleway.com
regions:
- fr-par-2
- nl-ams-1
tags:
- dev
variables:
ansible_host: public_ipv4
"""


from dataclasses import dataclass, field
from types import SimpleNamespace
Expand Down Expand Up @@ -369,8 +284,12 @@ def _get_dedibox(self, client: "Client", filters: _Filters) -> List[_Host]:

results: List[_Host] = []
for server in servers:
public_ipv4 = filter(lambda ip: ip.version == IPVersion.IPV4, server.interfaces.ips)
public_ipv6 = filter(lambda ip: ip.version == IPVersion.IPV6, server.interfaces.ips)
public_ipv4 = filter(
lambda ip: ip.version == IPVersion.IPV4, server.interfaces.ips
)
public_ipv6 = filter(
lambda ip: ip.version == IPVersion.IPV6, server.interfaces.ips
)
public_ipv4 = next(public_ipv4, None)
public_ipv6 = next(public_ipv6, None)

Expand Down
82 changes: 82 additions & 0 deletions plugins/inventory/scaleway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
DOCUMENTATION:
name: scaleway
author:
- Nathanael Demacon (@quantumsheep)
short_description: Scaleway inventory source
version_added: "1.0.0"
requirements:
- scaleway >= 0.6.0
description:
- Scaleway inventory plugin.
- Uses configuration file that ends with '(scaleway|scw).(yaml|yml)'.
extends_documentation_fragment:
- scaleway.scaleway.scaleway
- constructed
- inventory_cache
options:
plugin:
description:
- The name of the Scaleway Inventory Plugin, this should always be C(scaleway.scaleway.scaleway).
required: true
choices: ['scaleway.scaleway.scaleway']
zones:
description:
- List of zones to filter on.
type: list
elements: str
default:
- fr-par-1
- fr-par-2
- fr-par-3
- nl-ams-1
- nl-ams-2
- pl-waw-1
- pl-waw-2
tags:
description:
- List of tags to filter on.
type: list
elements: str
default: []
hostnames:
description: List of preference about what to use as an hostname.
type: list
elements: str
default:
- public_ipv4
choices:
- public_ipv4
- private_ipv4
- public_ipv6
- hostname
- id
variables:
description:
- "Variables mapping to apply to hosts in the format destination_variable: host_variable."
- "You can use the following host variables:"
- " - C(id): The server id."
- " - C(tags): The server tags."
- " - C(zone): The server zone."
- " - C(state): The server state."
- " - C(hostname): The server hostname."
- " - C(public_ipv4): The server public ipv4."
- " - C(private_ipv4): The server private ipv4."
- " - C(public_ipv6): The server public ipv6."
- " - C(public_dns): The server public dns."
- " - C(private_dns): The server private dns."
- ""
- "If the variable is not found, the host will be ignored."
type: dict

EXAMPLES:
- plugin: scaleway.scaleway.scaleway
access_key: <your access key>
secret_key: <your secret key>
api_url: https://api.scaleway.com
regions:
- fr-par-2
- nl-ams-1
tags:
- dev
variables:
ansible_host: public_ipv4
63 changes: 0 additions & 63 deletions plugins/modules/scaleway_account_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,6 @@

__metaclass__ = type

DOCUMENTATION = r"""
---
module: scaleway_account_project
short_description: Manage Scaleway account's project
description:
- This module can be used to manage Scaleway account's project.
version_added: "2.1.0"
author:
- Nathanael Demacon (@quantumsheep)
extends_documentation_fragment:
- scaleway.scaleway.scaleway
- scaleway.scaleway.scaleway_waitable_resource
requirements:
- scaleway >= 0.6.0
options:
state:
description:
- Indicate desired state of the target.
- C(present) will create the resource.
- C(absent) will delete the resource, if it exists.
default: present
choices: ["present", "absent"]
type: str
project_id:
description: project_id
type: str
required: false
name:
description: name
type: str
required: true
organization_id:
description: organization_id
type: str
required: false
description:
description: description
type: str
required: false
"""

EXAMPLES = r"""
- name: Create a project
scaleway.scaleway.scaleway_account_project:
access_key: "{{ scw_access_key }}"
secret_key: "{{ scw_secret_key }}"
name: "aaaaaa"
"""

RETURN = r"""
---
project:
description: The project information
returned: when I(state=present)
type: dict
sample:
id: 00000000-0000-0000-0000-000000000000
name: "aaaaaa"
organization_id: 00000000-0000-0000-0000-000000000000
created_at: "aaaaaa"
updated_at: "aaaaaa"
description: "aaaaaa"
"""

from ansible.module_utils.basic import (
AnsibleModule,
Expand Down
58 changes: 58 additions & 0 deletions plugins/modules/scaleway_account_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
DOCUMENTATION:
module: scaleway_account_project
short_description: Manage Scaleway account's project
description:
- This module can be used to manage Scaleway account's project.
version_added: "2.1.0"
author:
- Nathanael Demacon (@quantumsheep)
extends_documentation_fragment:
- scaleway.scaleway.scaleway
- scaleway.scaleway.scaleway_waitable_resource
requirements:
- scaleway >= 0.6.0
options:
state:
description:
- Indicate desired state of the target.
- C(present) will create the resource.
- C(absent) will delete the resource, if it exists.
default: present
choices: ["present", "absent"]
type: str
project_id:
description: project_id
type: str
required: false
name:
description: name
type: str
required: true
organization_id:
description: organization_id
type: str
required: false
description:
description: description
type: str
required: false

EXAMPLES:
- name: Create a project
scaleway.scaleway.scaleway_account_project:
access_key: "{{ scw_access_key }}"
secret_key: "{{ scw_secret_key }}"
name: "aaaaaa"

RETURN:
project:
description: The project information
returned: when I(state=present)
type: dict
sample:
id: 00000000-0000-0000-0000-000000000000
name: "aaaaaa"
organization_id: 00000000-0000-0000-0000-000000000000
created_at: "aaaaaa"
updated_at: "aaaaaa"
description: "aaaaaa"
Loading
Loading