Skip to content

Commit

Permalink
Add option for detached HUP on start_os_update
Browse files Browse the repository at this point in the history
This will call the v2 actions endpoint for resinhup
which runs a detached version of HUP that increases
HUP reliability on slow networks but will offer
no status updates such as in_progress.

Change-type: minor
  • Loading branch information
jaomaloy committed Jan 30, 2025
1 parent 7e64f52 commit 0b1c6ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions balena/models/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,13 @@ def set_supervisor_release(
}
)

def start_os_update(self, uuid_or_id: Union[str, int], target_os_version: str) -> HUPStatusResponse:
def start_os_update(
self,
uuid_or_id: Union[str, int],
target_os_version: str,
*, # Force keyword arguments after this point
run_detached: Optional[bool] = None
) -> HUPStatusResponse:
"""
Start an OS update on a device.
Expand All @@ -1737,15 +1743,23 @@ def start_os_update(self, uuid_or_id: Union[str, int], target_os_version: str) -
Unsupported (unpublished) version will result in rejection.
The version **must** be the exact version number, a "prod" variant
and greater than the one running on the device.
run_detached (Optional[bool]): run the update in detached mode.
Default behaviour is run_detached=False but is DEPRECATED and will be
removed in a future release. Use run_detached=True.
Returns:
HUPStatusResponse: action response.
Examples:
>>> balena.models.device.start_os_update('b6070f4', '2.29.2+rev1.prod')
>>> balena.models.device.start_os_update('b6070f4', '2.89.0+rev1')
>>> balena.models.device.start_os_update('b6070f4', '2.89.0+rev1', run_detached=True)
"""

# Set default value for run_detached if None
if run_detached is None:
run_detached = False

if target_os_version is None or uuid_or_id is None:
raise exceptions.InvalidParameter("target_os_version or UUID", None)

Expand All @@ -1766,7 +1780,7 @@ def start_os_update(self, uuid_or_id: Union[str, int], target_os_version: str) -
data = {"parameters": {"target_version": target_os_version}}

url_base = self.__config.get_all()["deviceUrlsBase"]
action_api_version = self.__settings.get("device_actions_endpoint_version")
action_api_version = "v2" if run_detached is True else self.__settings.get("device_actions_endpoint_version")

return request(
method="POST",
Expand All @@ -1776,6 +1790,7 @@ def start_os_update(self, uuid_or_id: Union[str, int], target_os_version: str) -
endpoint=f"https://actions.{url_base}/{action_api_version}/",
)

@deprecated("This will be removed in a future major release")
def get_os_update_status(self, uuid_or_id: Union[str, int]) -> HUPStatusResponse:
"""
Get the OS update status of a device.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typing_extensions = "*"
deprecated = "^1.2.13"
ratelimit = "^2.2.1"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
black = {version = "*", python = ">=3.8.1"}
pydocstyle = "*"
flake8 = "*"
Expand Down

0 comments on commit 0b1c6ee

Please sign in to comment.