Files
ovirt-api-simulator/app/ovirt/common.py
T
inecs af26ad4141 Return native Engine NotFound faults and clear Web UI session on 401.
Include the bad id in host/datacenter/cluster errors, expire stale auth in the
console, and document Ingress annotations that preserve fault bodies.
2026-07-22 06:52:04 +03:00

44 lines
1.2 KiB
Python

"""Shared oVirt Engine helpers (existence checks, native NotFound faults)."""
from __future__ import annotations
from typing import Any
from asyncpg import Connection
from app.ovirt.errors import OVirtError
def no_such(kind: str, entity_id: str) -> OVirtError:
"""Engine-shaped 404 with the bad id in the detail (never an HTML page)."""
return OVirtError(
"NotFound",
f"No such {kind} ('{entity_id}')",
status_code=404,
)
async def require_host(conn: Connection, host_id: str) -> Any:
row = await conn.fetchrow("SELECT * FROM ov_hosts WHERE id=$1::uuid", host_id)
if row is None:
raise no_such("host", host_id)
return row
async def require_datacenter(conn: Connection, datacenter_id: str) -> Any:
row = await conn.fetchrow(
"SELECT * FROM ov_datacenters WHERE id=$1::uuid",
datacenter_id,
)
if row is None:
raise no_such("datacenter", datacenter_id)
return row
async def require_cluster(conn: Connection, cluster_id: str) -> Any:
row = await conn.fetchrow("SELECT * FROM ov_clusters WHERE id=$1::uuid", cluster_id)
if row is None:
raise no_such("cluster", cluster_id)
return row