From 0e2653d9b5dfcc81b105a8663045cbfd23506db4 Mon Sep 17 00:00:00 2001 From: Neda Moeini <neda.moeini@geant.org> Date: Thu, 4 Apr 2024 12:15:34 +0200 Subject: [PATCH] used suppress instead of try-except. --- gso/services/netbox_client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gso/services/netbox_client.py b/gso/services/netbox_client.py index 3f49a095..212b1fb9 100644 --- a/gso/services/netbox_client.py +++ b/gso/services/netbox_client.py @@ -1,5 +1,6 @@ """Contain all methods to communicate with the NetBox API endpoint. Data Center Infrastructure Main (DCIM).""" +from contextlib import suppress from uuid import UUID import pydantic @@ -125,8 +126,9 @@ class NetboxClient: def delete_interface(self, device_name: str, iface_name: str) -> None: """Delete an interface from a device by name.""" interface = self.get_interface_by_name_and_device(iface_name, device_name) - if interface is not None: + if interface: return interface.delete() + return None def create_device_type(self, manufacturer: str, model: str, slug: str) -> DeviceTypes: """Create a new device type in Netbox.""" @@ -199,10 +201,8 @@ class NetboxClient: def delete_device(self, device_name: str) -> None: """Delete device by name if exists.""" - try: + with suppress(AttributeError): self.netbox.dcim.devices.get(name=device_name).delete() - except AttributeError: - pass def attach_interface_to_lag( self, -- GitLab