Skip to content

Commit

Permalink
Add hostmeta fact collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fliepeltje committed Feb 1, 2024
1 parent af7f353 commit 0ea8f90
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions humitifier/infra/facts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from .blocks import Blocks
from .groups import Groups
from .hostmeta import HostMeta
from .hostnamectl import HostnameCtl
from .memory import Memory
from .package_list import PackageList
Expand All @@ -17,6 +18,7 @@
Blocks,
Groups,
HostnameCtl,
HostMeta,
Memory,
PackageList,
Uptime,
Expand All @@ -27,6 +29,7 @@
Blocks,
Groups,
HostnameCtl,
HostMeta,
Memory,
PackageList,
Uptime,
Expand All @@ -37,6 +40,7 @@
Blocks.alias: Blocks,
Groups.alias: Groups,
HostnameCtl.alias: HostnameCtl,
HostMeta.alias: HostMeta,
Memory.alias: Memory,
PackageList.alias: PackageList,
Uptime.alias: Uptime,
Expand Down
46 changes: 46 additions & 0 deletions humitifier/infra/facts/hostmeta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
from dataclasses import asdict, dataclass


@dataclass
class HostMeta:
department: str | None
contact: str | None
update_policy: dict[str, bool] | None
webdav: str | None
vhosts: list[dict] | None
fileservers: list[str] | None
databases: dict[dict[str, list[str]]] | None

@classmethod
@property
def alias(cls) -> str:
return "hostmeta"

@classmethod
def from_stdout(cls, output: list[str]) -> "HostMeta":
base_args = {
"department": None,
"contact": None,
"update_policy": None,
"webdav": None,
"vhosts": None,
"fileservers": None,
"databases": None,
}
if output[0] == "cat: /hum/doc/server_facts.json: No such file or directory":
return cls(**base_args)
json_str = "\n".join(output)
json_args = json.loads(json_str)
return cls(**{**base_args, **json_args})

@staticmethod
def ssh_command(_) -> str:
return "cat /hum/doc/server_facts.json"

@classmethod
def from_sql(cls, sql_data) -> "HostMeta":
return cls(**sql_data)

def to_sql(self):
return asdict(self)

0 comments on commit 0ea8f90

Please sign in to comment.