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

fix: do not error on location_info invalid id (#292)

* test: fix hcloud_location_info with wrong id test

* chore: cleanup hcloud_location_info tests

* fix: error on location_info invalid id
This commit is contained in:
Jonas L 2023-08-09 12:42:22 +02:00 committed by GitHub
parent dd5ee78386
commit 5c4079e059
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 40 deletions

View file

@ -78,7 +78,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ..module_utils.hcloud import AnsibleHCloud
from ..module_utils.vendor.hcloud import HCloudException
from ..module_utils.vendor.hcloud import APIException, HCloudException
class AnsibleHCloudLocationInfo(AnsibleHCloud):
@ -105,7 +105,12 @@ class AnsibleHCloudLocationInfo(AnsibleHCloud):
def get_locations(self):
try:
if self.module.params.get("id") is not None:
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
try:
self.hcloud_location_info = [self.client.locations.get_by_id(self.module.params.get("id"))]
except APIException as exception:
self.hcloud_location_info = []
if exception.code != "not_found":
raise exception
elif self.module.params.get("name") is not None:
self.hcloud_location_info = [self.client.locations.get_by_name(self.module.params.get("name"))]
else: