mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-05 15:57:05 +00:00
multiple: replace namedtuple with dataclass (#12094)
* refactor(multiple): replace namedtuple with dataclass Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(changelog): add fragment for PR 12094 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update comment. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
850ef03fe7
commit
cbc6f6eed3
6 changed files with 47 additions and 20 deletions
|
|
@ -88,6 +88,7 @@ running:
|
|||
|
||||
import json
|
||||
import typing as t
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
|
@ -97,16 +98,15 @@ from ansible_collections.community.general.plugins.module_utils._homebrew import
|
|||
)
|
||||
|
||||
|
||||
# Stores validated arguments for an instance of an action.
|
||||
# See DOCUMENTATION string for argument-specific information.
|
||||
class HomebrewServiceArgs(t.NamedTuple):
|
||||
@dataclass
|
||||
class HomebrewServiceArgs:
|
||||
name: str
|
||||
state: str
|
||||
brew_path: str
|
||||
|
||||
|
||||
# Stores the state of a Homebrew service.
|
||||
class HomebrewServiceState(t.NamedTuple):
|
||||
@dataclass
|
||||
class HomebrewServiceState:
|
||||
running: bool
|
||||
pid: int | None
|
||||
|
||||
|
|
|
|||
|
|
@ -232,11 +232,19 @@ roles:
|
|||
|
||||
import os
|
||||
import time
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
||||
@dataclass
|
||||
class AuthParams:
|
||||
url: str
|
||||
user: str
|
||||
password: str
|
||||
|
||||
|
||||
STATES = (
|
||||
"PENDING",
|
||||
"DEPLOYING",
|
||||
|
|
@ -728,9 +736,7 @@ def get_connection_info(module):
|
|||
module.fail_json(
|
||||
msg="One or more connection parameters (api_url, api_username, api_password) were not specified"
|
||||
)
|
||||
auth_params = namedtuple("auth", ("url", "user", "password"))
|
||||
|
||||
return auth_params(url=url, user=username, password=password)
|
||||
return AuthParams(url=url, user=username, password=password)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
|
|
@ -688,13 +688,21 @@ import copy
|
|||
import os
|
||||
import re
|
||||
import time
|
||||
from collections import namedtuple
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils._opennebula import flatten, render
|
||||
|
||||
|
||||
@dataclass
|
||||
class AuthParams:
|
||||
url: str
|
||||
username: str
|
||||
password: str
|
||||
|
||||
|
||||
# Updateconf attributes documentation: https://docs.opennebula.io/6.10/integration_and_development/system_interfaces/api.html#one-vm-updateconf
|
||||
UPDATECONF_ATTRIBUTES = {
|
||||
"OS": ["ARCH", "MACHINE", "KERNEL", "INITRD", "BOOTLOADER", "BOOT", "SD_DISK_BUS", "UUID", "FIRMWARE"],
|
||||
|
|
@ -1632,9 +1640,7 @@ def get_connection_info(module):
|
|||
if not url:
|
||||
module.fail_json(msg="Opennebula API url (api_url) is not specified")
|
||||
|
||||
auth_params = namedtuple("auth", ("url", "username", "password"))
|
||||
|
||||
return auth_params(url=url, username=username, password=password)
|
||||
return AuthParams(url=url, username=username, password=password)
|
||||
|
||||
|
||||
def main():
|
||||
|
|
|
|||
|
|
@ -275,7 +275,8 @@ EXAMPLES = r"""
|
|||
|
||||
import re
|
||||
import shlex
|
||||
from collections import defaultdict, namedtuple
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
|
@ -296,7 +297,10 @@ class Package:
|
|||
return f'Package("{self.name}", "{self.source}", {self.source_is_URL})'
|
||||
|
||||
|
||||
VersionTuple = namedtuple("VersionTuple", ["current", "latest"])
|
||||
@dataclass
|
||||
class VersionTuple:
|
||||
current: str
|
||||
latest: str
|
||||
|
||||
|
||||
class Pacman:
|
||||
|
|
@ -717,7 +721,7 @@ class Pacman:
|
|||
"installed_groups": {groupname: set(pkgnames)},
|
||||
"available_pkgs": {pkgname: version},
|
||||
"available_groups": {groupname: set(pkgnames)},
|
||||
"upgradable_pkgs": {pkgname: (current_version,latest_version)},
|
||||
"upgradable_pkgs": {pkgname: VersionTuple},
|
||||
"pkg_reasons": {pkgname: reason},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue