Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions osism/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from fastapi import (
FastAPI,
Header,
Query,
Request,
Response,
HTTPException,
Expand Down Expand Up @@ -826,7 +827,7 @@ async def get_host_hostvars(host: str) -> HostvarsResponse:
)

if result.returncode != 0:
if "Unable to parse" in result.stderr or "Could not match" in result.stderr:
if "Could not match" in result.stderr:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Host '{host}' not found in inventory",
Expand Down Expand Up @@ -889,7 +890,7 @@ async def get_host_hostvar(host: str, variable: str) -> HostvarSingleResponse:
)

if result.returncode != 0:
if "Unable to parse" in result.stderr or "Could not match" in result.stderr:
if "Could not match" in result.stderr:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Host '{host}' not found in inventory",
Expand Down Expand Up @@ -1019,7 +1020,7 @@ async def search_inventory(
name_pattern: str,
host_pattern: Optional[str] = None,
source: Optional[str] = None,
limit: int = 100,
limit: int = Query(default=100, gt=0),
) -> SearchResponse:
"""Search for variables or facts across hosts using regex patterns.

Expand Down Expand Up @@ -1092,11 +1093,12 @@ async def search_inventory(
hosts_to_search = all_hosts

results: List[SearchResultEntry] = []
hosts_searched = len(hosts_to_search)
hosts_searched = 0

for host in hosts_to_search:
if len(results) >= limit:
break
hosts_searched += 1

# Search hostvars
if source in (None, "hostvars"):
Expand Down
Loading