mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 21:56:29 +00:00
Simplify handling with load docker
This commit is contained in:
parent
c55357a4e7
commit
6297eb11a1
@ -33,6 +33,9 @@ class APIHomeAssistant(object):
|
|||||||
version = body.get(ATTR_VERSION, self.config.current_homeassistant)
|
version = body.get(ATTR_VERSION, self.config.current_homeassistant)
|
||||||
|
|
||||||
if self.dock_hass.in_progress:
|
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))
|
return await asyncio.shield(self.dock_hass.update(version))
|
||||||
|
@ -11,7 +11,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
HOMEASSISTANT_CONFIG = "{}/homeassistant_config"
|
HOMEASSISTANT_CONFIG = "{}/homeassistant_config"
|
||||||
HOMEASSISTANT_SSL = "{}/homeassistant_ssl"
|
HOMEASSISTANT_SSL = "{}/homeassistant_ssl"
|
||||||
HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
HOMEASSISTANT_IMAGE = 'homeassistant_image'
|
||||||
HOMEASSISTANT_TAG = 'homeassistant_tag'
|
|
||||||
HOMEASSISTANT_CURRENT = 'homeassistant_current'
|
HOMEASSISTANT_CURRENT = 'homeassistant_current'
|
||||||
|
|
||||||
HASSIO_CURRENT = 'hassio_current'
|
HASSIO_CURRENT = 'hassio_current'
|
||||||
@ -67,17 +66,6 @@ class CoreConfig(object):
|
|||||||
"""Return docker homeassistant repository."""
|
"""Return docker homeassistant repository."""
|
||||||
return self._data.get(HOMEASSISTANT_IMAGE)
|
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
|
@property
|
||||||
def current_homeassistant(self):
|
def current_homeassistant(self):
|
||||||
"""Actual version of homeassistant."""
|
"""Actual version of homeassistant."""
|
||||||
|
@ -66,7 +66,7 @@ class HassIO(object):
|
|||||||
first_run=True)
|
first_run=True)
|
||||||
|
|
||||||
# first start of supervisor?
|
# first start of supervisor?
|
||||||
if self.config.homeassistant_tag is None:
|
if await self.homeassistant.exists():
|
||||||
_LOGGER.info("No HomeAssistant docker found.")
|
_LOGGER.info("No HomeAssistant docker found.")
|
||||||
await self._setup_homeassistant()
|
await self._setup_homeassistant()
|
||||||
|
|
||||||
@ -100,5 +100,4 @@ class HassIO(object):
|
|||||||
await asyncio.sleep(60, loop=self.loop)
|
await asyncio.sleep(60, loop=self.loop)
|
||||||
|
|
||||||
# store version
|
# store version
|
||||||
self.config.homeassistant_tag = self.config.current_homeassistant
|
_LOGGER.info("HomeAssistant docker now installed.")
|
||||||
_LOGGER.info("HomeAssistant docker now exists.")
|
|
||||||
|
@ -60,6 +60,26 @@ class DockerBase(object):
|
|||||||
return False
|
return False
|
||||||
return True
|
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):
|
def is_running(self):
|
||||||
"""Return True if docker is Running.
|
"""Return True if docker is Running.
|
||||||
|
|
||||||
@ -118,8 +138,8 @@ class DockerBase(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
async with self._lock:
|
async with self._lock:
|
||||||
_LOGGER.info("Run docker image %s.",
|
_LOGGER.info("Run docker image %s with version %s.",
|
||||||
self.image)
|
self.image, self.version)
|
||||||
return await self.loop.run_in_executor(None, self._run)
|
return await self.loop.run_in_executor(None, self._run)
|
||||||
|
|
||||||
def _run(self):
|
def _run(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user