From 61fd4500adb657b053f2fa0df5ac4d524d31dc77 Mon Sep 17 00:00:00 2001 From: Mathieu Lamiot Date: Wed, 22 May 2024 09:12:05 +0200 Subject: [PATCH] Handle ResourceExpiredError on OVH --- sources/factories/OvhApiFactory.py | 5 ++++- sources/handlers/ServerListHandler.py | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sources/factories/OvhApiFactory.py b/sources/factories/OvhApiFactory.py index 60d5bd5..86abbb5 100644 --- a/sources/factories/OvhApiFactory.py +++ b/sources/factories/OvhApiFactory.py @@ -56,7 +56,10 @@ def get_dedicated_server_ips(self, app_context, server_name): Return the IPv6 and IPv4 of a dedicated server """ client = self._get_ovh_client(app_context) - raw_result = client.get(f'/dedicated/server/{server_name}/ips') + try: + raw_result = client.get(f'/dedicated/server/{server_name}/ips') + except ovh.exceptions.ResourceExpiredError: + return None result = {} for server_ip in raw_result: ip_split = server_ip.split("/") diff --git a/sources/handlers/ServerListHandler.py b/sources/handlers/ServerListHandler.py index e599ade..544547c 100644 --- a/sources/handlers/ServerListHandler.py +++ b/sources/handlers/ServerListHandler.py @@ -116,6 +116,8 @@ def generate_wp_rocket_ips_human_readable(self, app_context): display_name = self.ovh_api_factory.get_dedicated_server_display_name(app_context, server_name) if 'worker' in display_name: server_ips = self.ovh_api_factory.get_dedicated_server_ips(app_context, server_name) + if server_ips is None: + continue ovh_ipv4 += server_ips[IpAddress.IP_ADDRESS_IPV4] + "\n" ovh_ipv6 += server_ips[IpAddress.IP_ADDRESS_IPV6] + "\n" text += ovh_ipv4 @@ -161,6 +163,8 @@ def generate_wp_rocket_ipv4_machine_readable(self, app_context): display_name = self.ovh_api_factory.get_dedicated_server_display_name(app_context, server_name) if 'worker' in display_name: server_ips = self.ovh_api_factory.get_dedicated_server_ips(app_context, server_name) + if server_ips is None: + continue ovh_ipv4 += server_ips[IpAddress.IP_ADDRESS_IPV4] + "\n" text += ovh_ipv4 deduplicated_text = Duplication.remove_duplicated_lines(text) @@ -179,6 +183,8 @@ def generate_wp_rocket_ipv6_machine_readable(self, app_context): display_name = self.ovh_api_factory.get_dedicated_server_display_name(app_context, server_name) if 'worker' in display_name: server_ips = self.ovh_api_factory.get_dedicated_server_ips(app_context, server_name) + if server_ips is None: + continue ovh_ipv6 += server_ips[IpAddress.IP_ADDRESS_IPV6] + "\n" text += ovh_ipv6 deduplicated_text = Duplication.remove_duplicated_lines(text)