WIP: Refactory / Cleanup docker base (#73)

* Refactory / Cleanup docker base

* Check ID of running image

* Small bugs / lint

* Add log info

* Fix lint

* Add a real cleanup solution

* fix unused import

* Cleanup restart after updates

* Use restart callback

* rename callback

* Add info log for cleanup & fix lint

* Fix lint

* fix wrong id

* fix set addon as install
This commit is contained in:
Pascal Vizeli
2017-05-31 23:41:04 +02:00
committed by GitHub
parent c1cd9bba45
commit 6b16da93cd
8 changed files with 118 additions and 177 deletions

View File

@@ -18,7 +18,7 @@ class DockerHomeAssistant(DockerBase):
super().__init__(config, loop, dock, image=config.homeassistant_image)
@property
def docker_name(self):
def name(self):
"""Return name of docker container."""
return HASS_DOCKER_NAME
@@ -30,13 +30,13 @@ class DockerHomeAssistant(DockerBase):
if self._is_running():
return
# cleanup old container
# cleanup
self._stop()
try:
self.container = self.dock.containers.run(
self.dock.containers.run(
self.image,
name=self.docker_name,
name=self.name,
detach=True,
privileged=True,
network_mode='host',
@@ -53,15 +53,12 @@ class DockerHomeAssistant(DockerBase):
{'bind': '/share', 'mode': 'rw'},
})
self.process_metadata()
_LOGGER.info("Start docker addon %s with version %s",
self.image, self.version)
except docker.errors.DockerException as err:
_LOGGER.error("Can't run %s -> %s", self.image, err)
return False
_LOGGER.info(
"Start homeassistant %s with version %s", self.image, self.version)
return True
async def update(self, tag):
@@ -71,8 +68,4 @@ class DockerHomeAssistant(DockerBase):
return False
async with self._lock:
if await self.loop.run_in_executor(None, self._update, tag):
await self.loop.run_in_executor(None, self._run)
return True
return False
return await self.loop.run_in_executor(None, self._update, tag)