Skip to content

Commit

Permalink
Merge pull request #98 from wp-media/develop
Browse files Browse the repository at this point in the history
Handle ResourceExpiredError on OVH
  • Loading branch information
MathieuLamiot authored May 22, 2024
2 parents 4f0477f + 61fd450 commit a3e0637
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sources/factories/OvhApiFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down
6 changes: 6 additions & 0 deletions sources/handlers/ServerListHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit a3e0637

Please sign in to comment.