added states and hostgroup to pillar output
This commit is contained in:
parent
6a5b92a937
commit
cda9df9e13
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -11,7 +11,7 @@ from starlette.requests import Request
|
||||
from fastapi import APIRouter, Depends
|
||||
from starlette.responses import JSONResponse
|
||||
|
||||
from pillar_tool.db import Host, Pillar
|
||||
from pillar_tool.db import Host, Pillar, TopFile
|
||||
from pillar_tool.db.models.top_data import State, StateAssignment
|
||||
from pillar_tool.db.queries.pillar_queries import get_pillar_for_target
|
||||
from pillar_tool.schemas import PillarParams, get_model_from_query
|
||||
@ -83,9 +83,20 @@ def pillar_get(req: Request, target: str) -> JSONResponse:
|
||||
|
||||
path.reverse()
|
||||
|
||||
# create 'virtual' pillar for states
|
||||
stmt_states = select(State).join(TopFile, TopFile.state_id == State.id).where(TopFile.host_id == host.id)
|
||||
states_list: list[str] = [ x[0].name for x in db.execute(stmt_states).fetchall() ]
|
||||
|
||||
# create path name
|
||||
hostgroup_name = '/'.join(x.name for x in path[:-1])
|
||||
|
||||
print("[DEBUG] pillar_get: resolved host hierarchy with {} hosts: {}".format(len(path), [h.name for h in path]))
|
||||
|
||||
out = merge([get_pillar_for_target(db, host.id) for host in path]) # type: ignore
|
||||
out.update({
|
||||
"states": states_list,
|
||||
"hostgroup": hostgroup_name
|
||||
})
|
||||
print("[DEBUG] pillar_get: merged pillar data contains {} top-level key(s)".format(len(out)))
|
||||
return JSONResponse(status_code=200, content=out)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user