mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
feat: add support for ARM APIs (#208)
* feat: add architecture fields for image & server type * feat: filter images by architecture * feat: select right image by arch on server create & rebuild * feat(inventory): add architecture field to returned servers * docs: add changelog for arm features * chore: prepare v1.11.0
This commit is contained in:
parent
6a3983c9cd
commit
3c2d4df8bb
9 changed files with 94 additions and 8 deletions
|
|
@ -217,6 +217,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
self.inventory.set_variable(server.name, "name", to_native(server.name))
|
||||
self.inventory.set_variable(server.name, "status", to_native(server.status))
|
||||
self.inventory.set_variable(server.name, "type", to_native(server.server_type.name))
|
||||
self.inventory.set_variable(server.name, "architecture", to_native(server.server_type.architecture))
|
||||
|
||||
# Network
|
||||
if server.public_net.ipv4:
|
||||
|
|
|
|||
|
|
@ -38,10 +38,15 @@ options:
|
|||
type: str
|
||||
type:
|
||||
description:
|
||||
- The label selector for the images you want to get.
|
||||
- The type for the images you want to get.
|
||||
default: system
|
||||
choices: [ system, snapshot, backup ]
|
||||
type: str
|
||||
architecture:
|
||||
description:
|
||||
- The architecture for the images you want to get.
|
||||
type: str
|
||||
choices: [ x86, arm ]
|
||||
extends_documentation_fragment:
|
||||
- hetzner.hcloud.hcloud
|
||||
|
||||
|
|
@ -98,6 +103,11 @@ hcloud_image_info:
|
|||
returned: always
|
||||
type: str
|
||||
sample: 18.04
|
||||
architecture:
|
||||
description: Image is compatible with this architecture
|
||||
returned: always
|
||||
type: str
|
||||
sample: x86
|
||||
labels:
|
||||
description: User-defined labels (key-value pairs)
|
||||
returned: always
|
||||
|
|
@ -127,6 +137,7 @@ class AnsibleHcloudImageInfo(Hcloud):
|
|||
"description": to_native(image.description),
|
||||
"os_flavor": to_native(image.os_flavor),
|
||||
"os_version": to_native(image.os_version),
|
||||
"architecture": to_native(image.architecture),
|
||||
"labels": image.labels,
|
||||
})
|
||||
return tmp
|
||||
|
|
@ -137,6 +148,11 @@ class AnsibleHcloudImageInfo(Hcloud):
|
|||
self.hcloud_image_info = [self.client.images.get_by_id(
|
||||
self.module.params.get("id")
|
||||
)]
|
||||
elif self.module.params.get("name") is not None and self.module.params.get("architecture") is not None:
|
||||
self.hcloud_image_info = [self.client.images.get_by_name_and_architecture(
|
||||
self.module.params.get("name"),
|
||||
self.module.params.get("architecture")
|
||||
)]
|
||||
elif self.module.params.get("name") is not None:
|
||||
self.hcloud_image_info = [self.client.images.get_by_name(
|
||||
self.module.params.get("name")
|
||||
|
|
@ -151,6 +167,10 @@ class AnsibleHcloudImageInfo(Hcloud):
|
|||
if image_type:
|
||||
params["type"] = image_type
|
||||
|
||||
architecture = self.module.params.get("architecture")
|
||||
if architecture:
|
||||
params["architecture"] = architecture
|
||||
|
||||
self.hcloud_image_info = self.client.images.get_all(**params)
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -164,6 +184,7 @@ class AnsibleHcloudImageInfo(Hcloud):
|
|||
name={"type": "str"},
|
||||
label_selector={"type": "str"},
|
||||
type={"choices": ["system", "snapshot", "backup"], "default": "system", "type": "str"},
|
||||
architecture={"choices": ["x86", "arm"], "type": "str"},
|
||||
**Hcloud.base_module_arguments()
|
||||
),
|
||||
supports_check_mode=True,
|
||||
|
|
|
|||
|
|
@ -402,12 +402,14 @@ class AnsibleHcloudServer(Hcloud):
|
|||
required_params=["name", "server_type", "image"]
|
||||
)
|
||||
|
||||
server_type = self._get_server_type()
|
||||
|
||||
params = {
|
||||
"name": self.module.params.get("name"),
|
||||
"server_type": self._get_server_type(),
|
||||
"server_type": server_type,
|
||||
"user_data": self.module.params.get("user_data"),
|
||||
"labels": self.module.params.get("labels"),
|
||||
"image": self._get_image(),
|
||||
"image": self._get_image(server_type),
|
||||
"placement_group": self._get_placement_group(),
|
||||
"public_net": ServerCreatePublicNetwork(
|
||||
enable_ipv4=self.module.params.get("enable_ipv4"),
|
||||
|
|
@ -499,8 +501,8 @@ class AnsibleHcloudServer(Hcloud):
|
|||
self._mark_as_changed()
|
||||
self._get_server()
|
||||
|
||||
def _get_image(self):
|
||||
image_resp = self.client.images.get_list(name=self.module.params.get("image"), include_deprecated=True)
|
||||
def _get_image(self, server_type):
|
||||
image_resp = self.client.images.get_list(name=self.module.params.get("image"), architecture=server_type.architecture, include_deprecated=True)
|
||||
images = getattr(image_resp, 'images')
|
||||
image = None
|
||||
if images is not None and len(images) > 0:
|
||||
|
|
@ -828,7 +830,7 @@ class AnsibleHcloudServer(Hcloud):
|
|||
)
|
||||
try:
|
||||
if not self.module.check_mode:
|
||||
image = self._get_image()
|
||||
image = self._get_image(self.hcloud_server.server_type)
|
||||
self.client.servers.rebuild(self.hcloud_server, image).wait_until_finished(1000) # When we rebuild the server progress takes some more time.
|
||||
self._mark_as_changed()
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,11 @@ hcloud_server_type_info:
|
|||
returned: always
|
||||
type: str
|
||||
sample: shared
|
||||
architecture:
|
||||
description: Architecture of cpu
|
||||
returned: always
|
||||
type: str
|
||||
sample: x86
|
||||
"""
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
|
@ -118,7 +123,8 @@ class AnsibleHcloudServerTypeInfo(Hcloud):
|
|||
"memory": server_type.memory,
|
||||
"disk": server_type.disk,
|
||||
"storage_type": to_native(server_type.storage_type),
|
||||
"cpu_type": to_native(server_type.cpu_type)
|
||||
"cpu_type": to_native(server_type.cpu_type),
|
||||
"architecture": to_native(server_type.architecture)
|
||||
})
|
||||
return tmp
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue