1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

feat: query floating ip info by name (#303)

##### SUMMARY

Fixes #302 

The feature was missing, this make the floating_ip_info module consistent with what is expected to be implemented. 

##### ISSUE TYPE

- Feature Pull Request


##### COMPONENT NAME

floating_ip_info
This commit is contained in:
Jonas L 2023-08-17 11:50:19 +02:00 committed by GitHub
parent 8b24cf2522
commit 4bb2bb80fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 16 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- hcloud_floating_ip_info - Allow querying floating ip by name.

View file

@ -22,6 +22,10 @@ options:
- The ID of the Floating IP you want to get.
- The module will fail if the provided ID is invalid.
type: int
name:
description:
- The name for the Floating IP you want to get.
type: str
label_selector:
description:
- The label selector for the Floating IP you want to get.
@ -133,6 +137,8 @@ class AnsibleHCloudFloatingIPInfo(AnsibleHCloud):
try:
if self.module.params.get("id") is not None:
self.hcloud_floating_ip_info = [self.client.floating_ips.get_by_id(self.module.params.get("id"))]
elif self.module.params.get("name") is not None:
self.hcloud_floating_ip_info = [self.client.floating_ips.get_by_name(self.module.params.get("name"))]
elif self.module.params.get("label_selector") is not None:
self.hcloud_floating_ip_info = self.client.floating_ips.get_all(
label_selector=self.module.params.get("label_selector")
@ -148,6 +154,7 @@ class AnsibleHCloudFloatingIPInfo(AnsibleHCloud):
return AnsibleModule(
argument_spec=dict(
id={"type": "int"},
name={"type": "str"},
label_selector={"type": "str"},
**super().base_module_arguments(),
),

View file

@ -37,23 +37,23 @@
that:
- result is failed
# - name: Gather hcloud_floating_ip_info with correct name
# hetzner.hcloud.hcloud_floating_ip_info:
# name: "{{ hcloud_floating_ip_name }}"
# register: result
# - name: Verify hcloud_floating_ip_info with correct name
# ansible.builtin.assert:
# that:
# - result.hcloud_floating_ip_info | list | count == 1
- name: Gather hcloud_floating_ip_info with correct name
hetzner.hcloud.hcloud_floating_ip_info:
name: "{{ hcloud_floating_ip_name }}"
register: result
- name: Verify hcloud_floating_ip_info with correct name
ansible.builtin.assert:
that:
- result.hcloud_floating_ip_info | list | count == 1
# - name: Gather hcloud_floating_ip_info with wrong name
# hetzner.hcloud.hcloud_floating_ip_info:
# name: "{{ hcloud_floating_ip_name }}-invalid"
# register: result
# - name: Verify hcloud_floating_ip_info with wrong name
# ansible.builtin.assert:
# that:
# - result.hcloud_floating_ip_info | list | count == 0
- name: Gather hcloud_floating_ip_info with wrong name
hetzner.hcloud.hcloud_floating_ip_info:
name: "{{ hcloud_floating_ip_name }}-invalid"
register: result
- name: Verify hcloud_floating_ip_info with wrong name
ansible.builtin.assert:
that:
- result.hcloud_floating_ip_info | list | count == 0
- name: Gather hcloud_floating_ip_info with correct label selector
hetzner.hcloud.hcloud_floating_ip_info: