Add comprehensive Docker containers management page with filtering, search, bulk actions, and enhanced container control with state verification
This commit is contained in:
@@ -138,3 +138,48 @@ class DockerContainerRepository:
|
||||
)
|
||||
)
|
||||
return result.rowcount
|
||||
|
||||
async def list_all(
|
||||
self,
|
||||
state: Optional[str] = None,
|
||||
compose_project: Optional[str] = None,
|
||||
health: Optional[str] = None,
|
||||
host_ids: Optional[List[str]] = None
|
||||
) -> List[DockerContainer]:
|
||||
"""List all containers across all hosts with optional filters."""
|
||||
query = select(DockerContainer)
|
||||
|
||||
if state:
|
||||
query = query.where(DockerContainer.state == state)
|
||||
if compose_project:
|
||||
query = query.where(DockerContainer.compose_project == compose_project)
|
||||
if health:
|
||||
query = query.where(DockerContainer.health == health)
|
||||
if host_ids:
|
||||
query = query.where(DockerContainer.host_id.in_(host_ids))
|
||||
|
||||
query = query.order_by(DockerContainer.host_id, DockerContainer.name)
|
||||
result = await self.session.execute(query)
|
||||
return list(result.scalars().all())
|
||||
|
||||
async def count_all(self) -> dict:
|
||||
"""Count all containers by state across all hosts."""
|
||||
result = await self.session.execute(
|
||||
select(
|
||||
func.count(DockerContainer.id).label('total'),
|
||||
func.sum(case((DockerContainer.state == 'running', 1), else_=0)).label('running'),
|
||||
func.sum(case((DockerContainer.state == 'exited', 1), else_=0)).label('stopped'),
|
||||
func.sum(case((DockerContainer.state == 'paused', 1), else_=0)).label('paused'),
|
||||
func.count(func.distinct(DockerContainer.host_id)).label('hosts_count'),
|
||||
func.max(DockerContainer.last_update_at).label('last_update')
|
||||
)
|
||||
)
|
||||
row = result.one()
|
||||
return {
|
||||
"total": row.total or 0,
|
||||
"running": row.running or 0,
|
||||
"stopped": row.stopped or 0,
|
||||
"paused": row.paused or 0,
|
||||
"hosts_count": row.hosts_count or 0,
|
||||
"last_update": row.last_update
|
||||
}
|
||||
|
||||
@@ -82,3 +82,11 @@ class HostRepository:
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def list_all(self, include_deleted: bool = False) -> list[Host]:
|
||||
"""List all hosts without pagination."""
|
||||
stmt = select(Host).order_by(Host.name)
|
||||
if not include_deleted:
|
||||
stmt = stmt.where(Host.deleted_at.is_(None))
|
||||
result = await self.session.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
Reference in New Issue
Block a user