Compare commits
3 commits
07bd99d38e
...
acacf19a12
Author | SHA1 | Date | |
---|---|---|---|
acacf19a12 | |||
d097cedc6b | |||
0654f06a71 |
3 changed files with 13 additions and 61 deletions
|
@ -78,22 +78,6 @@ class Cgroup:
|
||||||
namespace = maybe_or(val, "namespace", "")
|
namespace = maybe_or(val, "namespace", "")
|
||||||
how = maybe_or(val, "how", "")
|
how = maybe_or(val, "how", "")
|
||||||
|
|
||||||
if not isinstance(config, list):
|
|
||||||
logger.log_warning("Config key in cgroup Config is invalid!")
|
|
||||||
config = []
|
|
||||||
|
|
||||||
if not isinstance(parent, str):
|
|
||||||
logger.log_warning("Parent key in cgroup Config is invalid!")
|
|
||||||
parent = ""
|
|
||||||
|
|
||||||
if not isinstance(namespace, str):
|
|
||||||
logger.log_warning("Namespace key in cgroup Config is invalid!")
|
|
||||||
namespace = ""
|
|
||||||
|
|
||||||
if not isinstance(how, str):
|
|
||||||
logger.log_warning("How key in cgroup Config is invalid!")
|
|
||||||
how = ""
|
|
||||||
|
|
||||||
if how == "split" and parent != "":
|
if how == "split" and parent != "":
|
||||||
logger.log_warning(
|
logger.log_warning(
|
||||||
"Split cgroups can not be combined with a cgroup parent!"
|
"Split cgroups can not be combined with a cgroup parent!"
|
||||||
|
|
|
@ -34,23 +34,21 @@ def load_container_config(file: Path, log: Log) -> dict | None:
|
||||||
data = json.load(fp)
|
data = json.load(fp)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
log.log_error(f"{file.name} is not a valid JSON file!")
|
log.log_error(f"{file.name} is not a valid JSON file!")
|
||||||
log.log_debug(f"Exception: {e}")
|
log.log_error(f"Exception: {e}")
|
||||||
return None
|
return None
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError as e:
|
||||||
log.log_error(f"{file.name} is not a valid UTF8 file!")
|
log.log_error(f"{file.name} is not a valid UTF8 file!")
|
||||||
log.log_debug(f"Exception: {e}")
|
log.log_error(f"Exception: {e}")
|
||||||
return None
|
return None
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.log_error(f"{file.name} could not be read!")
|
log.log_error(f"{file.name} could not be read!")
|
||||||
log.log_debug(f"Exception: {e}")
|
log.log_error(f"Exception: {e}")
|
||||||
return None
|
return None
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def create_container_from_config(data: dict, log: Log) -> Container | None:
|
def create_container_from_config(data: dict, log: Log) -> Container | None:
|
||||||
"""Create a container object."""
|
"""Create a container object."""
|
||||||
log.log_info("Creating container...")
|
|
||||||
log.log_debug(f"Container config is:\n{data}")
|
|
||||||
ct: Container | None = None
|
ct: Container | None = None
|
||||||
try:
|
try:
|
||||||
ct = Container(data)
|
ct = Container(data)
|
||||||
|
@ -82,10 +80,8 @@ def main() -> None:
|
||||||
if data is None:
|
if data is None:
|
||||||
logger.log_error(f"{config_file} is invalid, aborting!")
|
logger.log_error(f"{config_file} is invalid, aborting!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
try:
|
|
||||||
ct = create_container_from_config(data, logger)
|
ct = create_container_from_config(data, logger)
|
||||||
except ConfigError as e:
|
if ct is None:
|
||||||
logger.log_error(e)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
scripts = {
|
scripts = {
|
||||||
"create-volumes": ct.create_volumes,
|
"create-volumes": ct.create_volumes,
|
||||||
|
|
|
@ -8,21 +8,11 @@
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TypeAlias
|
|
||||||
|
|
||||||
UNKNOWN = -1
|
|
||||||
ERROR = 0
|
|
||||||
WARNING = 1
|
|
||||||
INFO = 2
|
|
||||||
DEBUG = 3
|
|
||||||
|
|
||||||
LogLevel: TypeAlias = int
|
|
||||||
|
|
||||||
|
|
||||||
class Log:
|
class Log:
|
||||||
"""Class for Logging."""
|
"""Class for Logging."""
|
||||||
|
|
||||||
level: LogLevel = ERROR
|
|
||||||
messages: list = []
|
messages: list = []
|
||||||
logfile: Path
|
logfile: Path
|
||||||
|
|
||||||
|
@ -34,7 +24,6 @@ class Log:
|
||||||
|
|
||||||
def log_error(self, msg: str) -> None:
|
def log_error(self, msg: str) -> None:
|
||||||
"""Log an error."""
|
"""Log an error."""
|
||||||
if self.level >= ERROR:
|
|
||||||
now = self.timestamp()
|
now = self.timestamp()
|
||||||
prefix = "EE"
|
prefix = "EE"
|
||||||
log_message = f"[{now}] ({prefix}) {msg}"
|
log_message = f"[{now}] ({prefix}) {msg}"
|
||||||
|
@ -42,28 +31,11 @@ class Log:
|
||||||
|
|
||||||
def log_warning(self, msg: str) -> None:
|
def log_warning(self, msg: str) -> None:
|
||||||
"""Log a warning."""
|
"""Log a warning."""
|
||||||
if self.level >= WARNING:
|
|
||||||
now = self.timestamp()
|
now = self.timestamp()
|
||||||
prefix = "WW"
|
prefix = "WW"
|
||||||
log_message = f"[{now}] ({prefix}) {msg}"
|
log_message = f"[{now}] ({prefix}) {msg}"
|
||||||
self.write_message(log_message)
|
self.write_message(log_message)
|
||||||
|
|
||||||
def log_info(self, msg: str) -> None:
|
|
||||||
"""Log an information."""
|
|
||||||
if self.level >= INFO:
|
|
||||||
now = self.timestamp()
|
|
||||||
prefix = "II"
|
|
||||||
log_message = f"[{now}] ({prefix}) {msg}"
|
|
||||||
self.write_message(log_message)
|
|
||||||
|
|
||||||
def log_debug(self, msg: str) -> None:
|
|
||||||
"""Log a debug message."""
|
|
||||||
if self.level >= DEBUG:
|
|
||||||
now = self.timestamp()
|
|
||||||
prefix = "DD"
|
|
||||||
log_message = f"[{now}] ({prefix}) {msg}"
|
|
||||||
self.write_message(log_message)
|
|
||||||
|
|
||||||
def write_message(self, msg: str) -> None:
|
def write_message(self, msg: str) -> None:
|
||||||
"""Write the message."""
|
"""Write the message."""
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
Loading…
Add table
Reference in a new issue