Simplify handling with load docker

This commit is contained in:
pvizeli 2017-04-04 10:19:14 +02:00
parent c55357a4e7
commit 6297eb11a1
4 changed files with 28 additions and 18 deletions

View File

@ -33,6 +33,9 @@ class APIHomeAssistant(object):
version = body.get(ATTR_VERSION, self.config.current_homeassistant)
if self.dock_hass.in_progress:
raise RuntimeError("Other task is in progress!")
raise RuntimeError("Other task is in progress.")
if version == self.dock_hass.version:
raise RuntimeError("%s is already in use.", version)
return await asyncio.shield(self.dock_hass.update(version))

View File

@ -11,7 +11,6 @@ _LOGGER = logging.getLogger(__name__)
HOMEASSISTANT_CONFIG = "{}/homeassistant_config"
HOMEASSISTANT_SSL = "{}/homeassistant_ssl"
HOMEASSISTANT_IMAGE = 'homeassistant_image'
HOMEASSISTANT_TAG = 'homeassistant_tag'
HOMEASSISTANT_CURRENT = 'homeassistant_current'
HASSIO_CURRENT = 'hassio_current'
@ -67,17 +66,6 @@ class CoreConfig(object):
"""Return docker homeassistant repository."""
return self._data.get(HOMEASSISTANT_IMAGE)
@property
def homeassistant_tag(self):
"""Return docker homeassistant tag."""
return self._data.get(HOMEASSISTANT_TAG)
@homeassistant_tag.setter
def homeassistant_tag(self, value):
"""Set docker homeassistant tag."""
self._data[HOMEASSISTANT_TAG] = value
self.save()
@property
def current_homeassistant(self):
"""Actual version of homeassistant."""

View File

@ -66,7 +66,7 @@ class HassIO(object):
first_run=True)
# first start of supervisor?
if self.config.homeassistant_tag is None:
if await self.homeassistant.exists():
_LOGGER.info("No HomeAssistant docker found.")
await self._setup_homeassistant()
@ -100,5 +100,4 @@ class HassIO(object):
await asyncio.sleep(60, loop=self.loop)
# store version
self.config.homeassistant_tag = self.config.current_homeassistant
_LOGGER.info("HomeAssistant docker now exists.")
_LOGGER.info("HomeAssistant docker now installed.")

View File

@ -60,6 +60,26 @@ class DockerBase(object):
return False
return True
def exists(self):
"""Return True if docker image exists in local repo.
Return a Future.
"""
return self.loop.run_in_executor(None, self._is_running)
def _exists(self):
"""Return True if docker image exists in local repo.
Need run inside executor.
"""
try:
image = self.dock.images.get(self.image)
self.version = get_version_from_env(image.attrs['Config']['Env'])
except docker.errors.DockerException:
return False
return True
def is_running(self):
"""Return True if docker is Running.
@ -118,8 +138,8 @@ class DockerBase(object):
return False
async with self._lock:
_LOGGER.info("Run docker image %s.",
self.image)
_LOGGER.info("Run docker image %s with version %s.",
self.image, self.version)
return await self.loop.run_in_executor(None, self._run)
def _run(self):