-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af7f353
commit 0ea8f90
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |