2023-07-04 07:54:53 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
# Copyright: (c) 2022, Patrice Le Guyader
|
|
|
|
# heavily inspired by the work of @LKaemmerling
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
|
2023-11-23 13:53:10 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-07-04 07:54:53 +00:00
|
|
|
DOCUMENTATION = """
|
|
|
|
---
|
2023-11-20 12:21:23 +00:00
|
|
|
module: iso_info
|
2023-07-04 07:54:53 +00:00
|
|
|
|
|
|
|
short_description: Gather infos about the Hetzner Cloud ISO list.
|
|
|
|
|
|
|
|
description:
|
|
|
|
- Gather infos about the Hetzner Cloud ISO list.
|
|
|
|
|
|
|
|
author:
|
|
|
|
- Patrice Le Guyader (@patlegu)
|
|
|
|
- Lukas Kaemmerling (@LKaemmerling)
|
|
|
|
|
|
|
|
options:
|
|
|
|
id:
|
|
|
|
description:
|
|
|
|
- The ID of the ISO image you want to get.
|
2023-08-16 14:14:55 +00:00
|
|
|
- The module will fail if the provided ID is invalid.
|
2023-07-04 07:54:53 +00:00
|
|
|
type: int
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the ISO you want to get.
|
|
|
|
type: str
|
|
|
|
architecture:
|
|
|
|
description:
|
|
|
|
- Filter ISOs with compatible architecture.
|
|
|
|
type: str
|
|
|
|
choices: [x86, arm]
|
|
|
|
include_architecture_wildcard:
|
|
|
|
description:
|
|
|
|
- Include ISOs with wildcard architecture (architecture is null).
|
|
|
|
- Works only if architecture filter is specified.
|
|
|
|
type: bool
|
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- hetzner.hcloud.hcloud
|
|
|
|
"""
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Gather hcloud ISO type infos
|
2023-11-21 08:40:11 +00:00
|
|
|
hetzner.hcloud.iso_info:
|
2023-07-04 07:54:53 +00:00
|
|
|
register: output
|
|
|
|
|
|
|
|
- name: Print the gathered infos
|
|
|
|
debug:
|
|
|
|
var: output.hcloud_iso_info
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
hcloud_iso_info:
|
|
|
|
description: The ISO type infos as list
|
|
|
|
returned: always
|
|
|
|
type: complex
|
|
|
|
contains:
|
|
|
|
id:
|
|
|
|
description: ID of the ISO
|
|
|
|
returned: always
|
|
|
|
type: int
|
|
|
|
sample: 22110
|
|
|
|
name:
|
|
|
|
description: Unique identifier of the ISO. Only set for public ISOs
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: debian-12.0.0-amd64-netinst.iso
|
|
|
|
description:
|
|
|
|
description: Description of the ISO
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: Debian 12.0 (amd64/netinstall)
|
|
|
|
architecture:
|
|
|
|
description: >
|
|
|
|
Type of cpu architecture this ISO is compatible with.
|
|
|
|
None indicates no restriction on the architecture (wildcard).
|
|
|
|
returned: when supported
|
|
|
|
type: str
|
|
|
|
sample: x86
|
|
|
|
type:
|
|
|
|
description: Type of the ISO, can be one of `public`, `private`.
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: public
|
|
|
|
deprecated:
|
|
|
|
description: >
|
|
|
|
ISO 8601 timestamp of deprecation, None if ISO is still available.
|
|
|
|
After the deprecation time it will no longer be possible to attach the
|
2023-10-16 09:16:31 +00:00
|
|
|
ISO to servers. This field is deprecated. Use `deprecation` instead.
|
2023-07-04 07:54:53 +00:00
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: "2024-12-01T00:00:00+00:00"
|
2023-10-16 09:16:31 +00:00
|
|
|
deprecation:
|
|
|
|
description: >
|
|
|
|
Describes if, when & how the resources was deprecated. If this field is
|
|
|
|
set to None the resource is not deprecated. If it has a value, it is
|
|
|
|
considered deprecated.
|
|
|
|
returned: if the resource is deprecated
|
|
|
|
type: dict
|
|
|
|
contains:
|
|
|
|
announced:
|
|
|
|
description: Date of when the deprecation was announced.
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: "2021-11-01T00:00:00+00:00"
|
|
|
|
unavailable_after:
|
|
|
|
description: >
|
|
|
|
After the time in this field, the resource will not be available
|
|
|
|
from the general listing endpoint of the resource type, and it can
|
|
|
|
not be used in new resources. For example, if this is an image,
|
|
|
|
you can not create new servers with this image after the mentioned
|
|
|
|
date.
|
|
|
|
returned: always
|
|
|
|
type: str
|
|
|
|
sample: "2021-12-01T00:00:00+00:00"
|
2023-07-04 07:54:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2023-07-31 08:12:55 +00:00
|
|
|
|
2023-08-04 07:24:14 +00:00
|
|
|
from ..module_utils.hcloud import AnsibleHCloud
|
2023-09-26 07:41:01 +00:00
|
|
|
from ..module_utils.vendor.hcloud import HCloudException
|
|
|
|
from ..module_utils.vendor.hcloud.isos import BoundIso
|
2023-07-04 07:54:53 +00:00
|
|
|
|
|
|
|
|
2023-08-04 07:24:14 +00:00
|
|
|
class AnsibleHCloudIsoInfo(AnsibleHCloud):
|
2023-09-26 07:41:01 +00:00
|
|
|
represent = "hcloud_iso_info"
|
|
|
|
|
2023-11-23 13:53:10 +00:00
|
|
|
hcloud_iso_info: list[BoundIso] | None = None
|
2023-07-04 07:54:53 +00:00
|
|
|
|
|
|
|
def _prepare_result(self):
|
|
|
|
tmp = []
|
|
|
|
|
|
|
|
for iso_info in self.hcloud_iso_info:
|
|
|
|
if iso_info is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
tmp.append(
|
|
|
|
{
|
2024-03-27 13:11:30 +00:00
|
|
|
"id": str(iso_info.id),
|
|
|
|
"name": iso_info.name,
|
|
|
|
"description": iso_info.description,
|
2023-07-04 07:54:53 +00:00
|
|
|
"type": iso_info.type,
|
|
|
|
"architecture": iso_info.architecture,
|
2023-10-23 11:36:14 +00:00
|
|
|
"deprecated": (
|
2024-02-05 11:18:53 +00:00
|
|
|
iso_info.deprecation.unavailable_after.isoformat() if iso_info.deprecation is not None else None
|
2023-10-23 11:36:14 +00:00
|
|
|
),
|
2024-01-26 10:22:13 +00:00
|
|
|
"deprecation": (
|
|
|
|
{
|
|
|
|
"announced": iso_info.deprecation.announced.isoformat(),
|
|
|
|
"unavailable_after": iso_info.deprecation.unavailable_after.isoformat(),
|
|
|
|
}
|
|
|
|
if iso_info.deprecation is not None
|
|
|
|
else None
|
|
|
|
),
|
2023-07-04 07:54:53 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return tmp
|
|
|
|
|
|
|
|
def get_iso_infos(self):
|
|
|
|
try:
|
|
|
|
if self.module.params.get("id") is not None:
|
|
|
|
self.hcloud_iso_info = [self.client.isos.get_by_id(self.module.params.get("id"))]
|
|
|
|
elif self.module.params.get("name") is not None:
|
|
|
|
self.hcloud_iso_info = [self.client.isos.get_by_name(self.module.params.get("name"))]
|
|
|
|
else:
|
|
|
|
self.hcloud_iso_info = self.client.isos.get_all(
|
|
|
|
architecture=self.module.params.get("architecture"),
|
chore(deps): update dependency hcloud to v2 (#523)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)
This PR contains the following updates:
| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [hcloud](https://togithub.com/hetznercloud/hcloud-python)
([changelog](https://togithub.com/hetznercloud/hcloud-python/blob/main/CHANGELOG.md))
| `1.35.0` -> `2.0.1` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/hcloud/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/hcloud/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/hcloud/1.35.0/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/hcloud/1.35.0/2.0.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
---
### Release Notes
<details>
<summary>hetznercloud/hcloud-python (hcloud)</summary>
###
[`v2.0.1`](https://togithub.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#201-2024-07-03)
[Compare
Source](https://togithub.com/hetznercloud/hcloud-python/compare/v2.0.0...v2.0.1)
##### Bug Fixes
- `assignee_type` is required when creating a primary ip
([#​409](https://togithub.com/hetznercloud/hcloud-python/issues/409))
([bce5e94](https://togithub.com/hetznercloud/hcloud-python/commit/bce5e940e27f2c6d9d50016b5828c79aadfc4401))
- clean unused arguments in the `Client.servers.rebuild` method
([#​407](https://togithub.com/hetznercloud/hcloud-python/issues/407))
([6d33c3c](https://togithub.com/hetznercloud/hcloud-python/commit/6d33c3cff5443686c7ed37eb8635e0461bb3b928))
- details are optional in API errors
([#​411](https://togithub.com/hetznercloud/hcloud-python/issues/411))
([f1c6594](https://togithub.com/hetznercloud/hcloud-python/commit/f1c6594dee7088872f2375359ee259e4e93b31d2))
- rename `trace_id` variable to `correlation_id`
([#​408](https://togithub.com/hetznercloud/hcloud-python/issues/408))
([66a0f54](https://togithub.com/hetznercloud/hcloud-python/commit/66a0f546998193f9078f70a4a2fb1fc11937c086))
###
[`v2.0.0`](https://togithub.com/hetznercloud/hcloud-python/blob/HEAD/CHANGELOG.md#200-2024-07-03)
[Compare
Source](https://togithub.com/hetznercloud/hcloud-python/compare/v1.35.0...v2.0.0)
##### ⚠ BREAKING CHANGES
- return full rebuild response in `Client.servers.rebuild`
([#​406](https://togithub.com/hetznercloud/hcloud-python/issues/406))
- make `datacenter` argument optional when creating a primary ip
([#​363](https://togithub.com/hetznercloud/hcloud-python/issues/363))
- remove deprecated `include_wildcard_architecture` argument in
`IsosClient.get_list` and `IsosClient.get_all`
([#​402](https://togithub.com/hetznercloud/hcloud-python/issues/402))
- make `Client.request` `tries` a private argument
([#​399](https://togithub.com/hetznercloud/hcloud-python/issues/399))
- make `Client.poll_interval` a private property
([#​398](https://togithub.com/hetznercloud/hcloud-python/issues/398))
- return empty dict on empty responses in `Client.request`
([#​400](https://togithub.com/hetznercloud/hcloud-python/issues/400))
- remove deprecated `hcloud.hcloud` module
([#​401](https://togithub.com/hetznercloud/hcloud-python/issues/401))
- move `hcloud.__version__.VERSION` to `hcloud.__version__`
([#​397](https://togithub.com/hetznercloud/hcloud-python/issues/397))
##### Features
- add `trace_id` to API exceptions
([#​404](https://togithub.com/hetznercloud/hcloud-python/issues/404))
([8375261](https://togithub.com/hetznercloud/hcloud-python/commit/8375261da3b84d6fece97263c7bea40ad2a6cfcf))
- allow using a custom poll_interval function
([#​403](https://togithub.com/hetznercloud/hcloud-python/issues/403))
([93eb56b](https://togithub.com/hetznercloud/hcloud-python/commit/93eb56ba4d1a69e175398bca42e723a7e8e46371))
- make `Client.poll_interval` a private property
([#​398](https://togithub.com/hetznercloud/hcloud-python/issues/398))
([d5f24db](https://togithub.com/hetznercloud/hcloud-python/commit/d5f24db2816a0d00b8c7936e2a0290d2c4bb1e92))
- make `Client.request` `tries` a private argument
([#​399](https://togithub.com/hetznercloud/hcloud-python/issues/399))
([428ea7e](https://togithub.com/hetznercloud/hcloud-python/commit/428ea7e3be03a16114f875146971db59aabaac2c))
- move `hcloud.__version__.VERSION` to `hcloud.__version__`
([#​397](https://togithub.com/hetznercloud/hcloud-python/issues/397))
([4e3f638](https://togithub.com/hetznercloud/hcloud-python/commit/4e3f638862c9d260df98182c3f7858282049c26c)),
closes
[#​234](https://togithub.com/hetznercloud/hcloud-python/issues/234)
- remove deprecated `hcloud.hcloud` module
([#​401](https://togithub.com/hetznercloud/hcloud-python/issues/401))
([db37e63](https://togithub.com/hetznercloud/hcloud-python/commit/db37e633ebbf73354d3b2f4858cf3eebf173bfbc))
- remove deprecated `include_wildcard_architecture` argument in
`IsosClient.get_list` and `IsosClient.get_all`
([#​402](https://togithub.com/hetznercloud/hcloud-python/issues/402))
([6b977e2](https://togithub.com/hetznercloud/hcloud-python/commit/6b977e2da5cec30110c32a91d572003e5b5c400a))
- return empty dict on empty responses in `Client.request`
([#​400](https://togithub.com/hetznercloud/hcloud-python/issues/400))
([9f46adb](https://togithub.com/hetznercloud/hcloud-python/commit/9f46adb946eb2770ee4f3a4e87cfc1c8b9b33c28))
- return full rebuild response in `Client.servers.rebuild`
([#​406](https://togithub.com/hetznercloud/hcloud-python/issues/406))
([1970d84](https://togithub.com/hetznercloud/hcloud-python/commit/1970d84bec2106c8c53d8e611b74d41eb5286e9b))
##### Bug Fixes
- make `datacenter` argument optional when creating a primary ip
([#​363](https://togithub.com/hetznercloud/hcloud-python/issues/363))
([ebef774](https://togithub.com/hetznercloud/hcloud-python/commit/ebef77464c4c3b0ce33460cad2747e89d35047c7))
##### Dependencies
- update dependency coverage to >=7.5,<7.6
([#​386](https://togithub.com/hetznercloud/hcloud-python/issues/386))
([5660691](https://togithub.com/hetznercloud/hcloud-python/commit/5660691ebd6122fa7ebec56a24bce9fce0577573))
- update dependency mypy to >=1.10,<1.11
([#​387](https://togithub.com/hetznercloud/hcloud-python/issues/387))
([35c933b](https://togithub.com/hetznercloud/hcloud-python/commit/35c933bd2108d42e74b74b01d6db74e159ec9142))
- update dependency myst-parser to v3
([#​385](https://togithub.com/hetznercloud/hcloud-python/issues/385))
([9f18270](https://togithub.com/hetznercloud/hcloud-python/commit/9f182704898cb96f1ea162511605906f87cff50c))
- update dependency pylint to >=3,<3.3
([#​391](https://togithub.com/hetznercloud/hcloud-python/issues/391))
([4a6f005](https://togithub.com/hetznercloud/hcloud-python/commit/4a6f005cb0488291ae91390a612bab6afc6d80b6))
- update dependency pytest to >=8,<8.3
([#​390](https://togithub.com/hetznercloud/hcloud-python/issues/390))
([584a36b](https://togithub.com/hetznercloud/hcloud-python/commit/584a36b658670297ffffa9afa70835d29d27fbca))
- update dependency sphinx to >=7.3.4,<7.4
([#​383](https://togithub.com/hetznercloud/hcloud-python/issues/383))
([69c2e16](https://togithub.com/hetznercloud/hcloud-python/commit/69c2e16073df9ef8520e3a635b3866403eba030e))
- update pre-commit hook asottile/pyupgrade to v3.16.0
([0ce5fbc](https://togithub.com/hetznercloud/hcloud-python/commit/0ce5fbccba4a4255e08a37abf1f21ab9cc85f287))
- update pre-commit hook pre-commit/pre-commit-hooks to v4.6.0
([5ef25ab](https://togithub.com/hetznercloud/hcloud-python/commit/5ef25ab3966d731c4c36ea3e785c2b5f20c69489))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.0
([0941fbf](https://togithub.com/hetznercloud/hcloud-python/commit/0941fbfab20ca8a59e768c4a5e6fc101393c97f0))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.1
([fec08c5](https://togithub.com/hetznercloud/hcloud-python/commit/fec08c5323359d0a4f0771123f483ff975aa68b0))
- update pre-commit hook psf/black-pre-commit-mirror to v24.4.2
([#​389](https://togithub.com/hetznercloud/hcloud-python/issues/389))
([2b2e21f](https://togithub.com/hetznercloud/hcloud-python/commit/2b2e21f61366b5ec0f2ff5558f652d2bfed9d138))
- update pre-commit hook pycqa/flake8 to v7.1.0
([3bc651d](https://togithub.com/hetznercloud/hcloud-python/commit/3bc651d50d85aa92ba76dbfeef1d604cabaa4628))
##### Documentation
- add v2 upgrade notes
([#​405](https://togithub.com/hetznercloud/hcloud-python/issues/405))
([c77f771](https://togithub.com/hetznercloud/hcloud-python/commit/c77f771e2bed176acd6aa5011be006c800181809))
- cx11 is name, not an id
([#​381](https://togithub.com/hetznercloud/hcloud-python/issues/381))
([b745d40](https://togithub.com/hetznercloud/hcloud-python/commit/b745d4049f720b93d840a9204a99d246ecb499e5))
</details>
---
### Configuration
📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).
🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.
♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.
🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.
---
- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box
---
This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ansible-collections/hetzner.hcloud).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjEuOSIsInVwZGF0ZWRJblZlciI6IjM3LjQyMS45IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
---------
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: jo <ljonas@riseup.net>
2024-07-03 13:05:12 +00:00
|
|
|
include_architecture_wildcard=self.module.params.get("include_wildcard_architecture"),
|
2023-07-04 07:54:53 +00:00
|
|
|
)
|
|
|
|
|
2023-09-26 07:41:01 +00:00
|
|
|
except HCloudException as exception:
|
|
|
|
self.fail_json_hcloud(exception)
|
2023-07-04 07:54:53 +00:00
|
|
|
|
2023-08-02 10:05:00 +00:00
|
|
|
@classmethod
|
|
|
|
def define_module(cls):
|
2023-07-04 07:54:53 +00:00
|
|
|
return AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
id={"type": "int"},
|
|
|
|
name={"type": "str"},
|
|
|
|
architecture={"type": "str", "choices": ["x86", "arm"]},
|
|
|
|
include_architecture_wildcard={"type": "bool"},
|
2023-08-02 10:05:00 +00:00
|
|
|
**super().base_module_arguments(),
|
2023-07-04 07:54:53 +00:00
|
|
|
),
|
|
|
|
supports_check_mode=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2023-08-04 07:24:14 +00:00
|
|
|
module = AnsibleHCloudIsoInfo.define_module()
|
|
|
|
hcloud = AnsibleHCloudIsoInfo(module)
|
2023-07-04 07:54:53 +00:00
|
|
|
hcloud.get_iso_infos()
|
|
|
|
result = hcloud.get_result()
|
|
|
|
ansible_info = {"hcloud_iso_info": result["hcloud_iso_info"]}
|
|
|
|
module.exit_json(**ansible_info)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|