Compare commits
2 Commits
5ad0cff79b
...
b0099d9d71
| Author | SHA1 | Date | |
|---|---|---|---|
| b0099d9d71 | |||
| 03546a9d60 |
@ -43,7 +43,7 @@ def hostgroups_get(req: Request):
|
|||||||
ancestors = [host]
|
ancestors = [host]
|
||||||
while ancestors[-1].parent_id is not None:
|
while ancestors[-1].parent_id is not None:
|
||||||
ancestors.append(all_hostgroups[ancestors[-1].parent_id])
|
ancestors.append(all_hostgroups[ancestors[-1].parent_id])
|
||||||
all_hostgroup_names.append('/'.join(map(lambda x: x.name, reversed(ancestors))))
|
all_hostgroup_names.append('/'.join(map(lambda x: x.name, reversed(ancestors)))) # type: ignore
|
||||||
|
|
||||||
print("[DEBUG] hostgroups_get: resolved hierarchical names for {} host group(s): {}".format(len(all_hostgroup_names), all_hostgroup_names))
|
print("[DEBUG] hostgroups_get: resolved hierarchical names for {} host group(s): {}".format(len(all_hostgroup_names), all_hostgroup_names))
|
||||||
|
|
||||||
@ -73,9 +73,9 @@ def hostgroup_get(req: Request, name: str, params: HostgroupParams):
|
|||||||
# decode the path
|
# decode the path
|
||||||
last = None
|
last = None
|
||||||
ancestors = []
|
ancestors = []
|
||||||
path = []
|
path: list[str] = []
|
||||||
if params:
|
if params:
|
||||||
path = split_and_validate_path(params.path) if params.path else []
|
path = (split_and_validate_path(params.path) or []) if params.path else []
|
||||||
|
|
||||||
if len(path) > 0:
|
if len(path) > 0:
|
||||||
print("[DEBUG] hostgroup_get: resolving parent path with {} segment(s): {}".format(len(path), path))
|
print("[DEBUG] hostgroup_get: resolving parent path with {} segment(s): {}".format(len(path), path))
|
||||||
@ -184,7 +184,7 @@ def hostgroup_delete(req: Request, name: str, params: HostgroupParams = Depends(
|
|||||||
"""
|
"""
|
||||||
db = req.state.db
|
db = req.state.db
|
||||||
|
|
||||||
labels = split_and_validate_path(params.path) or []
|
labels = (split_and_validate_path(params.path) or []) if params.path is not None else []
|
||||||
labels.append(name)
|
labels.append(name)
|
||||||
last = None
|
last = None
|
||||||
|
|
||||||
@ -208,10 +208,10 @@ def hostgroup_delete(req: Request, name: str, params: HostgroupParams = Depends(
|
|||||||
children_stmt = select(Host).where(Host.parent_id == last)
|
children_stmt = select(Host).where(Host.parent_id == last)
|
||||||
children: list[Host] = list(map(lambda x: x[0], db.execute(children_stmt).fetchall()))
|
children: list[Host] = list(map(lambda x: x[0], db.execute(children_stmt).fetchall()))
|
||||||
if len(children) != 0:
|
if len(children) != 0:
|
||||||
print("[DEBUG] hostgroup_delete: ERROR - Cannot delete hostgroup '{}' because it has {} child(ren): {}. All children must be deleted first.".format(labels[-1], len(children), [ '/'.join(labels + [x.name]) for x in children ]))
|
print("[DEBUG] hostgroup_delete: ERROR - Cannot delete hostgroup '{}' because it has {} child(ren): {}. All children must be deleted first.".format(labels[-1], len(children), [ '/'.join(labels + [x.name]) for x in children ])) # type: ignore
|
||||||
return JSONResponse(status_code=400, content={
|
return JSONResponse(status_code=400, content={
|
||||||
'message': "Cannot delete a hostgroup that still has children",
|
'message': "Cannot delete a hostgroup that still has children",
|
||||||
'children': [ '/'.join(labels + [x.name]) for x in children ]
|
'children': [ '/'.join(labels + [x.name]) for x in children ] # type: ignore
|
||||||
})
|
})
|
||||||
|
|
||||||
print("[DEBUG] hostgroup_delete: deleting hostgroup '{}' (id={}) with no remaining children".format(labels[-1], last))
|
print("[DEBUG] hostgroup_delete: deleting hostgroup '{}' (id={}) with no remaining children".format(labels[-1], last))
|
||||||
|
|||||||
@ -172,7 +172,7 @@ def pillar_create(req: Request, name: str, params: PillarParams):
|
|||||||
print("[DEBUG] pillar_create: storing {} pillar entry/entries for target '{}' (id={})".format(len(pillars_to_store), target.name, target.id)) # type: ignore
|
print("[DEBUG] pillar_create: storing {} pillar entry/entries for target '{}' (id={})".format(len(pillars_to_store), target.name, target.id)) # type: ignore
|
||||||
|
|
||||||
# store pillar data
|
# store pillar data
|
||||||
insert_stmt = insert(Pillar).values(id=bindparam('new_id'), host_id=target.id, pillar_name=bindparam('name'), parameter_type=bindparam('type'), value=bindparam('value'))
|
insert_stmt = insert(Pillar).values(id=bindparam('new_id'), host_id=target.id, pillar_name=bindparam('name'), parameter_type=bindparam('type'), value=bindparam('value')) # type: ignore
|
||||||
upsert_stmt = insert_stmt.on_conflict_do_update(constraint='pillar_unique_pillar_name', set_={'parameter_type': bindparam('type'), 'value': bindparam('value')} )
|
upsert_stmt = insert_stmt.on_conflict_do_update(constraint='pillar_unique_pillar_name', set_={'parameter_type': bindparam('type'), 'value': bindparam('value')} )
|
||||||
|
|
||||||
for instance in pillars_to_store:
|
for instance in pillars_to_store:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user