Files
RoleForge/app/services/runner_client.py
Sergey Antropoff 1d2301fb09 first commit
2026-04-30 08:59:31 +03:00

60 lines
2.0 KiB
Python

from typing import Any
import httpx
async def create_playbook_run(
runner_base_url: str, playbook_yaml: str, inventory_text: str, extra_vars: dict[str, Any]
) -> str:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{runner_base_url}/runs/playbook",
json={
"playbook_yaml": playbook_yaml,
"inventory_text": inventory_text,
"extra_vars": extra_vars,
},
)
response.raise_for_status()
return str(response.json()["run_id"])
async def create_molecule_playbook_run(
runner_base_url: str, playbook_yaml: str, hosts: list[dict], extra_vars: dict[str, Any]
) -> str:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{runner_base_url}/runs/molecule/playbook",
json={"playbook_yaml": playbook_yaml, "hosts": hosts, "extra_vars": extra_vars},
)
response.raise_for_status()
return str(response.json()["run_id"])
async def create_molecule_role_run(
runner_base_url: str,
role_name: str,
role_tasks_yaml: str,
hosts: list[dict],
extra_vars: dict[str, Any],
) -> str:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.post(
f"{runner_base_url}/runs/molecule/role",
json={
"role_name": role_name,
"role_tasks_yaml": role_tasks_yaml,
"hosts": hosts,
"extra_vars": extra_vars,
},
)
response.raise_for_status()
return str(response.json()["run_id"])
async def get_run_status(runner_base_url: str, run_id: str, offset: int) -> dict[str, Any]:
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(f"{runner_base_url}/runs/{run_id}", params={"offset": offset})
response.raise_for_status()
return dict(response.json())