added some doc comments
This commit is contained in:
parent
7f5e63e397
commit
6fc2ac7969
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,4 +3,5 @@ __build__/
|
||||
__pycache__/
|
||||
/dist/
|
||||
/.idea/
|
||||
/pillartool.egg-info/
|
||||
pillar_tool.toml
|
||||
|
||||
1
pillar_tool/ptcli/__init__.py
Normal file
1
pillar_tool/ptcli/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .main import main
|
||||
@ -18,12 +18,24 @@ router = APIRouter(
|
||||
)
|
||||
|
||||
|
||||
|
||||
# TODO: check comments in this file (they are written by AI)
|
||||
@router.get("")
|
||||
def hosts_get(req: Request):
|
||||
"""
|
||||
Retrieve a list of all hosts (excluding hostgroups) in the system.
|
||||
|
||||
Queries the database for all host entries where is_hostgroup is False,
|
||||
returning only the names of the hosts in a flat list format.
|
||||
|
||||
Args:
|
||||
req: FastAPI request object containing database session
|
||||
|
||||
Returns:
|
||||
JSONResponse containing a list of host names as strings
|
||||
"""
|
||||
db: Session = req.state.db
|
||||
|
||||
result = db.execute(select(Host)).fetchall()
|
||||
result = db.execute(select(Host).where(Host.is_hostgroup == False)).fetchall()
|
||||
hosts: list[Host] = list(map(lambda x: x[0], result))
|
||||
|
||||
return JSONResponse(status_code=200, content=list(map(lambda x: x.name, hosts)))
|
||||
@ -32,6 +44,23 @@ def hosts_get(req: Request):
|
||||
|
||||
@router.get("/{fqdn}")
|
||||
def host_get(req: Request, fqdn: str):
|
||||
"""
|
||||
Retrieve detailed information about a specific host including its hierarchical path.
|
||||
|
||||
Fetches host details from the database and constructs the full path by traversing
|
||||
parent relationships up to the root. Returns both the host name and its complete
|
||||
hierarchical path as a slash-separated string.
|
||||
|
||||
Args:
|
||||
req: FastAPI request object containing database session
|
||||
fqdn: Fully qualified domain name of the host to retrieve
|
||||
|
||||
Returns:
|
||||
JSONResponse containing host name and hierarchical path
|
||||
|
||||
Raises:
|
||||
HTTPException: If FQDN format is invalid or host is not found
|
||||
"""
|
||||
db: Session = req.state.db
|
||||
|
||||
if not validate_fqdn(fqdn):
|
||||
@ -67,11 +96,31 @@ def host_get(req: Request, fqdn: str):
|
||||
|
||||
@router.post("/{fqdn}")
|
||||
async def host_add(request: Request, fqdn: str, params: HostCreateParams):
|
||||
"""
|
||||
Create a new host with optional parent hierarchy.
|
||||
|
||||
Validates FQDN format and parent path structure before creating the host.
|
||||
If a parent is specified, ensures all parent components exist in the database.
|
||||
Creates the host with a unique UUID and proper hierarchical relationships.
|
||||
|
||||
Args:
|
||||
request: FastAPI request object containing database session
|
||||
fqdn: Fully qualified domain name for the new host
|
||||
params: Host creation parameters including optional parent path
|
||||
|
||||
Returns:
|
||||
JSONResponse with creation details and host information
|
||||
|
||||
Raises:
|
||||
HTTPException: If FQDN format is invalid or parent doesn't exist
|
||||
"""
|
||||
db: Session = request.state.db
|
||||
|
||||
# Validate that the provided FQDN is properly formatted
|
||||
if not validate_fqdn(fqdn):
|
||||
raise HTTPException(status_code=400, detail="Provided host is not an FQDN")
|
||||
|
||||
# Process parent path if provided
|
||||
if params.parent is not None:
|
||||
parent_labels = split_and_validate_path(params.parent)
|
||||
if parent_labels is None:
|
||||
@ -79,6 +128,7 @@ async def host_add(request: Request, fqdn: str, params: HostCreateParams):
|
||||
else:
|
||||
parent_labels = []
|
||||
|
||||
# Traverse the parent hierarchy to ensure all components exist
|
||||
parent_id = None
|
||||
stmt_select_respecting_parent = select(Host).where(Host.name == bindparam("label") and Host.parent_id == bindparam("parent_id"))
|
||||
for label in parent_labels:
|
||||
@ -95,6 +145,7 @@ async def host_add(request: Request, fqdn: str, params: HostCreateParams):
|
||||
|
||||
parent_id = result[0][0].parent_id
|
||||
|
||||
# Create new host with unique ID and hierarchical structure
|
||||
new_host = Host(
|
||||
id=uuid.uuid4(),
|
||||
name=fqdn,
|
||||
|
||||
@ -11,4 +11,5 @@ Requires-Dist: jinja2>=3.1.6
|
||||
Requires-Dist: psycopg2>=2.9.11
|
||||
Requires-Dist: pycryptodome>=3.23.0
|
||||
Requires-Dist: pydantic>=2.12.5
|
||||
Requires-Dist: requests>=2.32.5
|
||||
Requires-Dist: sqlalchemy>=2.0.45
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
pyproject.toml
|
||||
pillar_tool/__init__.py
|
||||
pillar_tool/main.py
|
||||
pillar_tool/ptcli.py
|
||||
pillar_tool/schemas.py
|
||||
pillar_tool/db/__init__.py
|
||||
pillar_tool/db/base_model.py
|
||||
pillar_tool/db/database.py
|
||||
@ -14,19 +14,35 @@ pillar_tool/db/migrations/versions/2025_12_27_1159-4cc7f4e295f1_added_unique_to_
|
||||
pillar_tool/db/migrations/versions/2025_12_27_1958-678356102624_added_pillar_structure.py
|
||||
pillar_tool/db/migrations/versions/2025_12_30_1009-c6fe061ad732_better_uniqueness_contraints.py
|
||||
pillar_tool/db/migrations/versions/2026_01_01_1503-54537e95fc4d_coupled_host_and_hostgroup_into_single_.py
|
||||
pillar_tool/db/migrations/versions/2026_02_08_2034-7eb66922e256_pillars_are_directly_assigned_to_the_.py
|
||||
pillar_tool/db/migrations/versions/2026_02_08_2051-0a912926be8b_added_environments_and_states_to_the_db_.py
|
||||
pillar_tool/db/migrations/versions/2026_02_08_2220-e33744090598_mark_hosts_as_hostgroups.py
|
||||
pillar_tool/db/migrations/versions/2026_02_10_2147-dd573f631ee4_added_environment_assignments_to_.py
|
||||
pillar_tool/db/models/__init__.py
|
||||
pillar_tool/db/models/pillar_data.py
|
||||
pillar_tool/db/models/top_data.py
|
||||
pillar_tool/db/models/user.py
|
||||
pillar_tool/db/queries/__init__.py
|
||||
pillar_tool/db/queries/auth_queries.py
|
||||
pillar_tool/db/queries/host_queries.py
|
||||
pillar_tool/db/queries/pillar_queries.py
|
||||
pillar_tool/frontend/__init__.py
|
||||
pillar_tool/frontend/pillar_view.py
|
||||
pillar_tool/middleware/__init__.py
|
||||
pillar_tool/middleware/basicauth_backend.py
|
||||
pillar_tool/middleware/db_connection.py
|
||||
pillar_tool/middleware/logging.py
|
||||
pillar_tool/ptcli/__init__.py
|
||||
pillar_tool/ptcli/main.py
|
||||
pillar_tool/routers/__init__.py
|
||||
pillar_tool/routers/environment.py
|
||||
pillar_tool/routers/host.py
|
||||
pillar_tool/routers/hostgroup.py
|
||||
pillar_tool/routers/pillar.py
|
||||
pillar_tool/routers/state.py
|
||||
pillar_tool/util/__init__.py
|
||||
pillar_tool/util/config.py
|
||||
pillar_tool/util/validation.py
|
||||
pillartool.egg-info/PKG-INFO
|
||||
pillartool.egg-info/SOURCES.txt
|
||||
pillartool.egg-info/dependency_links.txt
|
||||
|
||||
@ -6,4 +6,5 @@ jinja2>=3.1.6
|
||||
psycopg2>=2.9.11
|
||||
pycryptodome>=3.23.0
|
||||
pydantic>=2.12.5
|
||||
requests>=2.32.5
|
||||
sqlalchemy>=2.0.45
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user