Add inventory relations model and API structure
CI / basic-check (push) Has been cancelled

This commit is contained in:
Perplexity Bot
2026-08-04 19:20:19 +00:00
parent 69124b31f1
commit 4466e59684
6 changed files with 252 additions and 1 deletions
+48
View File
@@ -11,6 +11,14 @@ ObjectType = Literal[
'site', 'area', 'rack', 'physical_host', 'vm', 'lxc', 'container',
'app', 'switch', 'firewall', 'router', 'ap', 'camera', 'storage', 'other'
]
RelationType = Literal[
'contains', 'mounted_in', 'attached_to', 'connects_to', 'uplink_to',
'routes_via', 'bridges_to', 'depends_on', 'hosts_service', 'managed_by'
]
RelationLayer = Literal['physical', 'network', 'logical', 'service']
RelationSource = Literal['manual', 'snmp', 'lldp', 'arp', 'nmap', 'inference', 'import']
RelationStatus = Literal['active', 'stale', 'planned', 'deleted']
RelationDirection = Literal['forward']
class HealthCheck(BaseModel):
@@ -75,6 +83,43 @@ class Link(BaseModel):
source: Literal['manual', 'snmp', 'lldp', 'arp', 'import', 'inference']
class Relation(BaseModel):
id: str
type: RelationType
layer: RelationLayer
source_id: str
target_id: str
direction: RelationDirection = 'forward'
source: RelationSource
confidence: float = Field(ge=0, le=1, default=1.0)
status: RelationStatus = 'active'
attributes: Dict[str, Any] = Field(default_factory=dict)
created_at: datetime
updated_at: datetime
class InventoryTreeNode(BaseModel):
id: str
name: str
type: ObjectType
status: ObjectStatus
badges: List[str] = Field(default_factory=list)
children_count: int = 0
children: List['InventoryTreeNode'] = Field(default_factory=list)
class NodeContextRelations(BaseModel):
incoming: List[Relation] = Field(default_factory=list)
outgoing: List[Relation] = Field(default_factory=list)
class NodeContext(BaseModel):
item: NetObject
parent: Optional[NetObject] = None
children: List[NetObject] = Field(default_factory=list)
relations: NodeContextRelations = Field(default_factory=NodeContextRelations)
class Job(BaseModel):
id: str
type: str
@@ -123,3 +168,6 @@ class ListResponse(BaseModel, Generic[T]):
class EntityResponse(BaseModel, Generic[T]):
item: T
InventoryTreeNode.model_rebuild()