Skip to content
Snippets Groups Projects

Updated delete Netbox device functionality to delete the device if it exists...

Merged Neda Moeini requested to merge enhancement/delete-device-in-netbox-if-exists into develop
1 file
+ 4
2
Compare changes
  • Side-by-side
  • Inline
"""Contain all methods to communicate with the NetBox API endpoint. Data Center Infrastructure Main (DCIM)."""
"""Contain all methods to communicate with the NetBox API endpoint. Data Center Infrastructure Main (DCIM)."""
 
from contextlib import suppress
from uuid import UUID
from uuid import UUID
import pydantic
import pydantic
@@ -199,8 +200,9 @@ class NetboxClient:
@@ -199,8 +200,9 @@ class NetboxClient:
return device
return device
def delete_device(self, device_name: str) -> None:
def delete_device(self, device_name: str) -> None:
"""Delete device by name."""
"""Delete device by name if exists."""
self.netbox.dcim.devices.get(name=device_name).delete()
with suppress(AttributeError):
 
self.netbox.dcim.devices.get(name=device_name).delete()
def attach_interface_to_lag(
def attach_interface_to_lag(
self,
self,
Loading