wip: make work Services Status
This commit is contained in:
+82
-18
@@ -408,47 +408,111 @@ class NetworkManager(BaseServiceManager):
|
||||
is_docker = os.path.exists('/.dockerenv') or os.environ.get('DOCKER_CONTAINER') == 'true'
|
||||
|
||||
if is_docker:
|
||||
# Return positive status when running in Docker
|
||||
# Check if network containers are actually running
|
||||
dns_running = self._check_dns_container_status()
|
||||
dhcp_running = self._check_dhcp_container_status()
|
||||
ntp_running = self._check_ntp_container_status()
|
||||
all_running = dns_running and dhcp_running and ntp_running
|
||||
|
||||
status = {
|
||||
'dns_running': True,
|
||||
'dhcp_running': True,
|
||||
'ntp_running': True,
|
||||
'running': True,
|
||||
'status': 'online',
|
||||
'dns_running': dns_running,
|
||||
'dhcp_running': dhcp_running,
|
||||
'ntp_running': ntp_running,
|
||||
'running': all_running,
|
||||
'status': 'online' if all_running else 'offline',
|
||||
'network': {
|
||||
'dns_running': dns_running,
|
||||
'dhcp_running': dhcp_running,
|
||||
'ntp_running': ntp_running,
|
||||
'running': all_running,
|
||||
'status': 'online' if all_running else 'offline'
|
||||
},
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
else:
|
||||
# Check actual service status in production
|
||||
dns_running = self._check_dns_status()
|
||||
dhcp_running = self._check_dhcp_status()
|
||||
ntp_running = self._check_ntp_status()
|
||||
|
||||
status = {
|
||||
'dns_running': self._check_dns_status(),
|
||||
'dhcp_running': self._check_dhcp_status(),
|
||||
'ntp_running': self._check_ntp_status(),
|
||||
'dns_running': dns_running,
|
||||
'dhcp_running': dhcp_running,
|
||||
'ntp_running': ntp_running,
|
||||
'running': dns_running and dhcp_running and ntp_running,
|
||||
'status': 'online' if (dns_running and dhcp_running and ntp_running) else 'offline',
|
||||
'network': {
|
||||
'dns_running': dns_running,
|
||||
'dhcp_running': dhcp_running,
|
||||
'ntp_running': ntp_running,
|
||||
'running': dns_running and dhcp_running and ntp_running,
|
||||
'status': 'online' if (dns_running and dhcp_running and ntp_running) else 'offline'
|
||||
},
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
# Determine overall status
|
||||
status['running'] = status['dns_running'] and status['dhcp_running'] and status['ntp_running']
|
||||
status['status'] = 'online' if status['running'] else 'offline'
|
||||
|
||||
return status
|
||||
except Exception as e:
|
||||
return self.handle_error(e, "get_status")
|
||||
|
||||
def _check_dns_container_status(self) -> bool:
|
||||
"""Check if DNS Docker container is running"""
|
||||
try:
|
||||
import docker
|
||||
client = docker.from_env()
|
||||
containers = client.containers.list(filters={'name': 'cell-dns'})
|
||||
return len(containers) > 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _check_dhcp_container_status(self) -> bool:
|
||||
"""Check if DHCP Docker container is running"""
|
||||
try:
|
||||
import docker
|
||||
client = docker.from_env()
|
||||
containers = client.containers.list(filters={'name': 'cell-dhcp'})
|
||||
return len(containers) > 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def _check_ntp_container_status(self) -> bool:
|
||||
"""Check if NTP Docker container is running"""
|
||||
try:
|
||||
import docker
|
||||
client = docker.from_env()
|
||||
containers = client.containers.list(filters={'name': 'cell-ntp'})
|
||||
return len(containers) > 0
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def test_connectivity(self) -> Dict[str, Any]:
|
||||
"""Test network service connectivity"""
|
||||
try:
|
||||
dns_test = self.test_dns_resolution('google.com')
|
||||
dhcp_test = self.test_dhcp_functionality()
|
||||
ntp_test = self.test_ntp_functionality()
|
||||
|
||||
results = {
|
||||
'dns_test': self.test_dns_resolution('google.com'),
|
||||
'dhcp_test': self.test_dhcp_functionality(),
|
||||
'ntp_test': self.test_ntp_functionality(),
|
||||
'dns_test': dns_test,
|
||||
'dhcp_test': dhcp_test,
|
||||
'ntp_test': ntp_test,
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
# Determine overall success
|
||||
results['success'] = all(
|
||||
success = all(
|
||||
result.get('success', False)
|
||||
for result in [results['dns_test'], results['dhcp_test'], results['ntp_test']]
|
||||
for result in [dns_test, dhcp_test, ntp_test]
|
||||
)
|
||||
results['success'] = success
|
||||
|
||||
# Add network key for compatibility
|
||||
results['network'] = {
|
||||
'dns_test': dns_test,
|
||||
'dhcp_test': dhcp_test,
|
||||
'ntp_test': ntp_test,
|
||||
'success': success
|
||||
}
|
||||
|
||||
return results
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user