Extend API to view logs from docker (#11)

* Extend API to view logs from docker

* Pump version

* Fix lint

* Change to raw api output

* Fix aiohttp response

* Fix aiohttp response p2

* Fix body convert

* Add attach to docker addon
This commit is contained in:
Pascal Vizeli
2017-04-24 12:00:44 +02:00
committed by GitHub
parent 98f0ff2a01
commit f99c6335c0
11 changed files with 108 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ import logging
import voluptuous as vol
from .util import api_process, api_validate
from .util import api_process, api_process_raw, api_validate
from ..const import ATTR_VERSION, ATTR_CURRENT
_LOGGER = logging.getLogger(__name__)
@@ -17,17 +17,17 @@ SCHEMA_VERSION = vol.Schema({
class APIHomeAssistant(object):
"""Handle rest api for homeassistant functions."""
def __init__(self, config, loop, dock_hass):
def __init__(self, config, loop, homeassistant):
"""Initialize homeassistant rest api part."""
self.config = config
self.loop = loop
self.dock_hass = dock_hass
self.homeassistant = homeassistant
@api_process
async def info(self, request):
"""Return host information."""
info = {
ATTR_VERSION: self.dock_hass.version,
ATTR_VERSION: self.homeassistant.version,
ATTR_CURRENT: self.config.current_homeassistant,
}
@@ -39,11 +39,19 @@ class APIHomeAssistant(object):
body = await api_validate(SCHEMA_VERSION, request)
version = body.get(ATTR_VERSION, self.config.current_homeassistant)
if self.dock_hass.in_progress:
if self.homeassistant.in_progress:
raise RuntimeError("Other task is in progress")
if version == self.dock_hass.version:
if version == self.homeassistant.version:
raise RuntimeError("Version is already in use")
return await asyncio.shield(
self.dock_hass.update(version), loop=self.loop)
self.homeassistant.update(version), loop=self.loop)
@api_process_raw
def logs(self, request):
"""Return homeassistant docker logs.
Return a coroutine.
"""
return self.homeassistant.logs()