Init template sooner (#2194)

This commit is contained in:
Pascal Vizeli 2020-10-30 10:37:34 +01:00 committed by GitHub
parent f71549e3df
commit 8cbb4b510b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 17 deletions

View File

@ -91,6 +91,12 @@ class Audio(JsonConfig, CoreSysAttributes):
async def load(self) -> None:
"""Load Audio setup."""
# Initialize Client Template
try:
self.client_template = jinja2.Template(PULSE_CLIENT_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read pulse-client.tmpl: %s", err)
# Check Audio state
try:
# Evaluate Version if we lost this information
@ -114,12 +120,6 @@ class Audio(JsonConfig, CoreSysAttributes):
if not await self.instance.is_running():
await self.start()
# Initialize Client Template
try:
self.client_template = jinja2.Template(PULSE_CLIENT_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read pulse-client.tmpl: %s", err)
# Setup default asound config
asound = self.sys_config.path_audio.joinpath("asound")
if not asound.exists():

View File

@ -131,9 +131,18 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
async def load(self) -> None:
"""Load DNS setup."""
self._init_hosts()
# Initialize CoreDNS Template
try:
self.resolv_template = jinja2.Template(RESOLV_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read resolve.tmpl: %s", err)
try:
self.hosts_template = jinja2.Template(HOSTS_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read hosts.tmpl: %s", err)
# Check CoreDNS state
self._init_hosts()
try:
# Evaluate Version if we lost this information
if not self.version:
@ -153,16 +162,6 @@ class CoreDNS(JsonConfig, CoreSysAttributes):
self.image = self.instance.image
self.save_data()
# Initialize CoreDNS Template
try:
self.resolv_template = jinja2.Template(RESOLV_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read resolve.tmpl: %s", err)
try:
self.hosts_template = jinja2.Template(HOSTS_TMPL.read_text())
except OSError as err:
_LOGGER.error("Can't read hosts.tmpl: %s", err)
# Run CoreDNS
with suppress(CoreDNSError):
if not await self.instance.is_running():