mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 14:46:30 +00:00
Update API / fix isoformat
This commit is contained in:
parent
bcfd76d33c
commit
772709dd75
84
API.md
84
API.md
@ -51,48 +51,13 @@ The addons from `addons` are only installed one.
|
|||||||
],
|
],
|
||||||
"addons_repositories": [
|
"addons_repositories": [
|
||||||
"REPO_URL"
|
"REPO_URL"
|
||||||
],
|
|
||||||
"snapshots": [
|
|
||||||
{
|
|
||||||
"slug": "SLUG",
|
|
||||||
"data": "ISO",
|
|
||||||
"name": "Custom name"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- GET `/supervisor/addons`
|
- GET `/supervisor/addons`
|
||||||
|
|
||||||
Get all available addons
|
Get all available addons. Will be delete soon. Look to `/addons`
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"addons": [
|
|
||||||
{
|
|
||||||
"name": "xy bla",
|
|
||||||
"slug": "xy",
|
|
||||||
"description": "description",
|
|
||||||
"arch": ["armhf", "aarch64", "i386", "amd64"],
|
|
||||||
"repository": "core|local|REP_ID",
|
|
||||||
"version": "LAST_VERSION",
|
|
||||||
"installed": "none|INSTALL_VERSION",
|
|
||||||
"detached": "bool",
|
|
||||||
"build": "bool",
|
|
||||||
"url": "null|url"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"repositories": [
|
|
||||||
{
|
|
||||||
"slug": "12345678",
|
|
||||||
"name": "Repitory Name|unknown",
|
|
||||||
"source": "URL_OF_REPOSITORY",
|
|
||||||
"url": "WEBSITE|REPOSITORY",
|
|
||||||
"maintainer": "BLA BLU <fla@dld.ch>|unknown"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- POST `/supervisor/update`
|
- POST `/supervisor/update`
|
||||||
Optional:
|
Optional:
|
||||||
@ -157,6 +122,21 @@ Return QR-Code
|
|||||||
|
|
||||||
### Backup/Snapshot
|
### Backup/Snapshot
|
||||||
|
|
||||||
|
- GET `/snapshots`
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"snapshots": [
|
||||||
|
{
|
||||||
|
"slug": "SLUG",
|
||||||
|
"date": "ISO",
|
||||||
|
"name": "Custom name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- POST `/snapshots/reload`
|
||||||
|
|
||||||
- POST `/snapshots/new/full`
|
- POST `/snapshots/new/full`
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@ -302,6 +282,38 @@ Image with `null` and last_version with `null` reset this options.
|
|||||||
|
|
||||||
### REST API addons
|
### REST API addons
|
||||||
|
|
||||||
|
- GET `/addons`
|
||||||
|
|
||||||
|
Get all available addons
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"addons": [
|
||||||
|
{
|
||||||
|
"name": "xy bla",
|
||||||
|
"slug": "xy",
|
||||||
|
"description": "description",
|
||||||
|
"arch": ["armhf", "aarch64", "i386", "amd64"],
|
||||||
|
"repository": "core|local|REP_ID",
|
||||||
|
"version": "LAST_VERSION",
|
||||||
|
"installed": "none|INSTALL_VERSION",
|
||||||
|
"detached": "bool",
|
||||||
|
"build": "bool",
|
||||||
|
"url": "null|url"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"slug": "12345678",
|
||||||
|
"name": "Repitory Name|unknown",
|
||||||
|
"source": "URL_OF_REPOSITORY",
|
||||||
|
"url": "WEBSITE|REPOSITORY",
|
||||||
|
"maintainer": "BLA BLU <fla@dld.ch>|unknown"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
- POST `/addons/reload`
|
- POST `/addons/reload`
|
||||||
|
|
||||||
- GET `/addons/{addon}/info`
|
- GET `/addons/{addon}/info`
|
||||||
|
@ -77,6 +77,9 @@ class RestAPI(object):
|
|||||||
"""Register homeassistant function."""
|
"""Register homeassistant function."""
|
||||||
api_addons = APIAddons(self.config, self.loop, addons)
|
api_addons = APIAddons(self.config, self.loop, addons)
|
||||||
|
|
||||||
|
self.webapp.router.add_get('/addons', api_addons.list)
|
||||||
|
self.webapp.router.add_post('/addons/reload', api_addons.reload)
|
||||||
|
|
||||||
self.webapp.router.add_get('/addons/{addon}/info', api_addons.info)
|
self.webapp.router.add_get('/addons/{addon}/info', api_addons.info)
|
||||||
self.webapp.router.add_post(
|
self.webapp.router.add_post(
|
||||||
'/addons/{addon}/install', api_addons.install)
|
'/addons/{addon}/install', api_addons.install)
|
||||||
@ -105,6 +108,9 @@ class RestAPI(object):
|
|||||||
"""Register snapshots function."""
|
"""Register snapshots function."""
|
||||||
api_snapshots = APISnapshots(self.config, self.loop, snapshots)
|
api_snapshots = APISnapshots(self.config, self.loop, snapshots)
|
||||||
|
|
||||||
|
self.webapp.router.add_get('/snapshots', api_snapshots.list)
|
||||||
|
self.webapp.router.add_post('/snapshots/reload', api_snapshots.reload)
|
||||||
|
|
||||||
self.webapp.router.add_post(
|
self.webapp.router.add_post(
|
||||||
'/snapshots/new/full', api_snapshots.snapshot_full)
|
'/snapshots/new/full', api_snapshots.snapshot_full)
|
||||||
self.webapp.router.add_post(
|
self.webapp.router.add_post(
|
||||||
|
@ -9,7 +9,8 @@ from .util import api_process, api_process_raw, api_validate
|
|||||||
from ..const import (
|
from ..const import (
|
||||||
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_STATE, ATTR_BOOT, ATTR_OPTIONS,
|
ATTR_VERSION, ATTR_LAST_VERSION, ATTR_STATE, ATTR_BOOT, ATTR_OPTIONS,
|
||||||
ATTR_URL, ATTR_DESCRIPTON, ATTR_DETACHED, ATTR_NAME, ATTR_REPOSITORY,
|
ATTR_URL, ATTR_DESCRIPTON, ATTR_DETACHED, ATTR_NAME, ATTR_REPOSITORY,
|
||||||
ATTR_BUILD, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_HOST_NETWORK,
|
ATTR_BUILD, ATTR_AUTO_UPDATE, ATTR_NETWORK, ATTR_HOST_NETWORK, ATTR_SLUG,
|
||||||
|
ATTR_SOURCE, ATTR_REPOSITORY, ATTR_REPOSITORIES, ATTR_ADDONS,
|
||||||
BOOT_AUTO, BOOT_MANUAL)
|
BOOT_AUTO, BOOT_MANUAL)
|
||||||
from ..validate import DOCKER_PORTS
|
from ..validate import DOCKER_PORTS
|
||||||
|
|
||||||
@ -47,6 +48,44 @@ class APIAddons(object):
|
|||||||
|
|
||||||
return addon
|
return addon
|
||||||
|
|
||||||
|
@api_process
|
||||||
|
async def list(self, request):
|
||||||
|
"""Return all addons / repositories ."""
|
||||||
|
data_addons = []
|
||||||
|
for addon in self.addons.list_addons:
|
||||||
|
data_addons.append({
|
||||||
|
ATTR_NAME: addon.name,
|
||||||
|
ATTR_SLUG: addon.slug,
|
||||||
|
ATTR_DESCRIPTON: addon.description,
|
||||||
|
ATTR_VERSION: addon.last_version,
|
||||||
|
ATTR_INSTALLED: addon.version_installed,
|
||||||
|
ATTR_ARCH: addon.supported_arch,
|
||||||
|
ATTR_DETACHED: addon.is_detached,
|
||||||
|
ATTR_REPOSITORY: addon.repository,
|
||||||
|
ATTR_BUILD: addon.need_build,
|
||||||
|
ATTR_URL: addon.url,
|
||||||
|
})
|
||||||
|
|
||||||
|
data_repositories = []
|
||||||
|
for repository in self.addons.list_repositories:
|
||||||
|
data_repositories.append({
|
||||||
|
ATTR_SLUG: repository.slug,
|
||||||
|
ATTR_NAME: repository.name,
|
||||||
|
ATTR_SOURCE: repository.source,
|
||||||
|
ATTR_URL: repository.url,
|
||||||
|
ATTR_MAINTAINER: repository.maintainer,
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
ATTR_ADDONS: data_addons,
|
||||||
|
ATTR_REPOSITORIES: data_repositories,
|
||||||
|
}
|
||||||
|
|
||||||
|
@api_process
|
||||||
|
def reload(self, request):
|
||||||
|
"""Reload all addons data."""
|
||||||
|
return self.addons.reload()
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
async def info(self, request):
|
async def info(self, request):
|
||||||
"""Return addon information."""
|
"""Return addon information."""
|
||||||
|
@ -9,7 +9,7 @@ from ..snapshots.validate import ALL_FOLDERS
|
|||||||
from ..const import (
|
from ..const import (
|
||||||
ATTR_NAME, ATTR_SLUG, ATTR_DATE, ATTR_ADDONS, ATTR_REPOSITORIES,
|
ATTR_NAME, ATTR_SLUG, ATTR_DATE, ATTR_ADDONS, ATTR_REPOSITORIES,
|
||||||
ATTR_HOMEASSISTANT, ATTR_VERSION, ATTR_SIZE, ATTR_FOLDERS, ATTR_TYPE,
|
ATTR_HOMEASSISTANT, ATTR_VERSION, ATTR_SIZE, ATTR_FOLDERS, ATTR_TYPE,
|
||||||
ATTR_DEVICES)
|
ATTR_DEVICES, ATTR_SNAPSHOTS)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -47,23 +47,39 @@ class APISnapshots(object):
|
|||||||
raise RuntimeError("Snapshot not exists")
|
raise RuntimeError("Snapshot not exists")
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
@staticmethod
|
@api_process
|
||||||
def _addons_list(snapshot):
|
async def list(self, request):
|
||||||
"""Generate a list with addons data."""
|
"""Return snapshot list."""
|
||||||
data = []
|
data_snapshots = []
|
||||||
for addon_data in snapshot.addons:
|
for snapshot in self.snapshots.list_snapshots:
|
||||||
data.append({
|
data_snapshots.append({
|
||||||
ATTR_SLUG: addon_data[ATTR_SLUG],
|
ATTR_SLUG: snapshot.slug,
|
||||||
ATTR_NAME: addon_data[ATTR_NAME],
|
ATTR_NAME: snapshot.name,
|
||||||
ATTR_VERSION: addon_data[ATTR_VERSION],
|
ATTR_DATE: snapshot.date,
|
||||||
})
|
})
|
||||||
return data
|
|
||||||
|
return {
|
||||||
|
ATTR_SNAPSHOTS: data_snapshots,
|
||||||
|
}
|
||||||
|
|
||||||
|
@api_process
|
||||||
|
def reload(self, request):
|
||||||
|
"""Reload snapshot list."""
|
||||||
|
return asyncio.shield(self.snapshots.reload(), loop=self.loop)
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
async def info(self, request):
|
async def info(self, request):
|
||||||
"""Return snapshot info."""
|
"""Return snapshot info."""
|
||||||
snapshot = self._extract_snapshot(request)
|
snapshot = self._extract_snapshot(request)
|
||||||
|
|
||||||
|
data_addons = []
|
||||||
|
for addon_data in snapshot.addons:
|
||||||
|
data_addons.append({
|
||||||
|
ATTR_SLUG: addon_data[ATTR_SLUG],
|
||||||
|
ATTR_NAME: addon_data[ATTR_NAME],
|
||||||
|
ATTR_VERSION: addon_data[ATTR_VERSION],
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ATTR_SLUG: snapshot.slug,
|
ATTR_SLUG: snapshot.slug,
|
||||||
ATTR_TYPE: snapshot.sys_type,
|
ATTR_TYPE: snapshot.sys_type,
|
||||||
@ -74,7 +90,7 @@ class APISnapshots(object):
|
|||||||
ATTR_VERSION: snapshot.homeassistant_version,
|
ATTR_VERSION: snapshot.homeassistant_version,
|
||||||
ATTR_DEVICES: snapshot.homeassistant_devices,
|
ATTR_DEVICES: snapshot.homeassistant_devices,
|
||||||
},
|
},
|
||||||
ATTR_ADDONS: self._addons_list(snapshot),
|
ATTR_ADDONS: data_addons,
|
||||||
ATTR_REPOSITORIES: snapshot.repositories,
|
ATTR_REPOSITORIES: snapshot.repositories,
|
||||||
ATTR_FOLDERS: snapshot.folders,
|
ATTR_FOLDERS: snapshot.folders,
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ from ..const import (
|
|||||||
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES,
|
HASSIO_VERSION, ATTR_ADDONS_REPOSITORIES, ATTR_REPOSITORIES,
|
||||||
ATTR_REPOSITORY, ATTR_DESCRIPTON, ATTR_NAME, ATTR_SLUG, ATTR_INSTALLED,
|
ATTR_REPOSITORY, ATTR_DESCRIPTON, ATTR_NAME, ATTR_SLUG, ATTR_INSTALLED,
|
||||||
ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL, ATTR_ARCH,
|
ATTR_DETACHED, ATTR_SOURCE, ATTR_MAINTAINER, ATTR_URL, ATTR_ARCH,
|
||||||
ATTR_BUILD, ATTR_TIMEZONE, ATTR_DATE, ATTR_SNAPSHOTS)
|
ATTR_BUILD, ATTR_TIMEZONE)
|
||||||
from ..tools import validate_timezone
|
from ..tools import validate_timezone
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -77,18 +77,6 @@ class APISupervisor(object):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _snapshots_list(self):
|
|
||||||
"""Return a list of available snapshots."""
|
|
||||||
data = []
|
|
||||||
for snapshot in self.snapshots.list_snapshots:
|
|
||||||
data.append({
|
|
||||||
ATTR_SLUG: snapshot.slug,
|
|
||||||
ATTR_NAME: snapshot.name,
|
|
||||||
ATTR_DATE: snapshot.date,
|
|
||||||
})
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
async def ping(self, request):
|
async def ping(self, request):
|
||||||
"""Return ok for signal that the api is ready."""
|
"""Return ok for signal that the api is ready."""
|
||||||
|
@ -37,7 +37,7 @@ class SnapshotsManager(object):
|
|||||||
|
|
||||||
def _create_snapshot(self, name, sys_type):
|
def _create_snapshot(self, name, sys_type):
|
||||||
"""Initialize a new snapshot object from name."""
|
"""Initialize a new snapshot object from name."""
|
||||||
date_str = str(datetime.utcnow())
|
date_str = datetime.utcnow().isoformat()
|
||||||
slug = create_slug(name, date_str)
|
slug = create_slug(name, date_str)
|
||||||
tar_file = Path(self.config.path_backup, "{}.tar".format(slug))
|
tar_file = Path(self.config.path_backup, "{}.tar".format(slug))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user