40 lines
934 B
Python
40 lines
934 B
Python
from dataclasses import dataclass, field
|
|
from datetime import datetime
|
|
|
|
from docker.models.containers import Container
|
|
|
|
|
|
@dataclass
|
|
class SimpleContainer:
|
|
name: str
|
|
image: str
|
|
status: str
|
|
health: str
|
|
created: datetime
|
|
|
|
@staticmethod
|
|
def from_container(container: Container):
|
|
created = datetime.strptime(container.attrs['Created'].split('.')[0], '%Y-%m-%dT%H:%M:%S')
|
|
return SimpleContainer(
|
|
name=container.name,
|
|
image=container.image.tags[0],
|
|
status=container.status,
|
|
health=container.health,
|
|
created=created
|
|
)
|
|
|
|
|
|
@dataclass
|
|
class Compose:
|
|
directory: str
|
|
containers: list[SimpleContainer] = field(default_factory=list)
|
|
|
|
@property
|
|
def last_modified(self):
|
|
return max(self.containers, key=lambda c: c.created).created
|
|
|
|
|
|
@dataclass
|
|
class Tree:
|
|
composes: dict[str, Compose] = field(default_factory=dict)
|
|
containers: list[SimpleContainer] = field(default_factory=list)
|