Get all hosts, optionally filtered by status. Args: status: Filter by status ('alive', 'degraded', None for all) Returns: List of host dictionaries
(self, status: str = None)
| 928 | # If multiple entries exist for same IP, prefer real MAC over pseudo-MAC |
| 929 | if len(rows) > 1: |
| 930 | logger.warning(f"Found {len(rows)} entries for IP {ip} - preferring real MAC") |
| 931 | for row in rows: |
| 932 | if not self._is_pseudo_mac(row['mac']): |
| 933 | return dict(row) |
| 934 | |
| 935 | return dict(rows[0]) |
| 936 | except Exception as e: |
| 937 | logger.error(f"Failed to get host by IP {ip}: {e}") |
| 938 | return None |
| 939 | |
| 940 | def get_all_hosts(self, status: str = None) -> List[Dict]: |
| 941 | """ |
| 942 | Get all hosts, optionally filtered by status. |
| 943 | |
| 944 | Args: |
| 945 | status: Filter by status ('alive', 'degraded', None for all) |
| 946 | |
| 947 | Returns: |
| 948 | List of host dictionaries |
| 949 | """ |
| 950 | try: |
| 951 | with self.get_connection() as conn: |
| 952 | cursor = conn.cursor() |
| 953 | |
| 954 | if status: |
| 955 | cursor.execute("SELECT * FROM hosts WHERE status = ? ORDER BY ip", (status,)) |
no test coverage detected