generate: container: Don't warn or crash on missing optional keys
The entire accounting section is optional, so silently ignore when it is missing. Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
parent
658fc6465c
commit
487be8c49a
1 changed files with 11 additions and 0 deletions
|
@ -66,6 +66,9 @@ class Cgroup:
|
|||
@classmethod
|
||||
def from_json(cls, val: ConfigValue, logger: Log) -> Self:
|
||||
"""Create from JSON."""
|
||||
if val is None:
|
||||
return cls([], "", "", "")
|
||||
|
||||
if not isinstance(val, dict):
|
||||
logger.log_warning("cgroup Config is invalid!")
|
||||
return cls([], "", "", "")
|
||||
|
@ -130,6 +133,9 @@ class Cpu:
|
|||
@classmethod
|
||||
def from_json(cls, val: ConfigValue, logger: Log) -> Self:
|
||||
"""Create from JSON."""
|
||||
if val is None:
|
||||
return cls("", "", "", "", "", "")
|
||||
|
||||
if not isinstance(val, dict):
|
||||
logger.log_warning("cpu Config is invalid!")
|
||||
return cls("", "", "", "", "", "")
|
||||
|
@ -184,6 +190,11 @@ class Accounting:
|
|||
@classmethod
|
||||
def from_json(cls, data: ConfigValue, logger: Log) -> Self:
|
||||
"""Create from JSON."""
|
||||
if data is None:
|
||||
return cls(
|
||||
Cgroup.from_json(None, logger), Cpu.from_json(None, logger)
|
||||
)
|
||||
|
||||
cgroup_data = maybe(data, "cgroup")
|
||||
cpu_data = maybe(data, "cpu")
|
||||
cgroup = Cgroup.from_json(cgroup_data, logger)
|
||||
|
|
Loading…
Add table
Reference in a new issue