mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-10-19 16:49:35 +00:00

* Support control of hassos-cli * Update const.py * Update validate.py * Update supervisor.py * Create hassos_cli.py * Update hassos_cli.py * Update hassos_cli.py * Update hassos.py * Update tasks.py * Update hassos.py * Update API.md * Update API.md * Update const.py * Update hassos.py * Update __init__.py * Fix lint * fix * Fix logging * change order * Fix download
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""Init file for HassIO docker object."""
|
|
import logging
|
|
import os
|
|
|
|
import docker
|
|
|
|
from .interface import DockerInterface
|
|
from ..coresys import CoreSysAttributes
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class DockerSupervisor(DockerInterface, CoreSysAttributes):
|
|
"""Docker hassio wrapper for Supervisor."""
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return name of docker container."""
|
|
return os.environ['SUPERVISOR_NAME']
|
|
|
|
def _attach(self):
|
|
"""Attach to running docker container.
|
|
|
|
Need run inside executor.
|
|
"""
|
|
try:
|
|
container = self.sys_docker.containers.get(self.name)
|
|
except docker.errors.DockerException:
|
|
return False
|
|
|
|
self._meta = container.attrs
|
|
_LOGGER.info("Attach to supervisor %s with version %s",
|
|
self.image, self.version)
|
|
|
|
# if already attach
|
|
if container in self.sys_docker.network.containers:
|
|
return True
|
|
|
|
# attach to network
|
|
return self.sys_docker.network.attach_container(
|
|
container, alias=['hassio'],
|
|
ipv4=self.sys_docker.network.supervisor)
|