Delete a host record by MAC address. Args: mac: MAC address to delete Returns: bool: True if successful
(self, mac: str)
| 856 | cursor.execute( |
| 857 | f"UPDATE hosts SET {column} = ?, updated_at = CURRENT_TIMESTAMP WHERE lower(mac) = lower(?)", |
| 858 | (status, mac) |
| 859 | ) |
| 860 | updated = cursor.rowcount > 0 |
| 861 | if not updated: |
| 862 | logger.debug(f"No host updated for MAC {mac} when setting {column}") |
| 863 | return updated |
| 864 | except Exception as exc: |
| 865 | logger.error(f"Failed to update action status for {mac}: {exc}") |
| 866 | return False |
| 867 | |
| 868 | def delete_host(self, mac: str) -> bool: |
| 869 | """ |
| 870 | Delete a host record by MAC address. |
| 871 | |
| 872 | Args: |
| 873 | mac: MAC address to delete |
| 874 | |
| 875 | Returns: |
| 876 | bool: True if successful |
| 877 | """ |
| 878 | if not mac: |
| 879 | logger.warning("Cannot delete host without MAC address") |
| 880 | return False |
| 881 | |
| 882 | # Normalize MAC address |
| 883 | mac = mac.lower().strip() |
| 884 | |
| 885 | try: |
| 886 | with self.get_connection() as conn: |
| 887 | cursor = conn.cursor() |
| 888 | cursor.execute("DELETE FROM hosts WHERE mac = ?", (mac,)) |
| 889 | conn.commit() |
| 890 | |
| 891 | if cursor.rowcount > 0: |
| 892 | logger.info(f"Deleted host: {mac}") |
| 893 | return True |
no test coverage detected