diff options
| author | Oleksandr Kuchmystyi <o.kuchmystyi@vyos.io> | 2026-01-23 16:15:22 +0300 |
|---|---|---|
| committer | Oleksandr Kuchmystyi <o.kuchmystyi@vyos.io> | 2026-01-28 09:57:55 +0300 |
| commit | 7fd4b50494d3b8865a7300e97c72df2a4fe11f14 (patch) | |
| tree | 5df53b3c936f35aed73f9911dc17b78de72adabf /src/helpers | |
| parent | 0a619674e6ce46add5d1573399179c0d8e29456c (diff) | |
| download | vyos-1x-7fd4b50494d3b8865a7300e97c72df2a4fe11f14.tar.gz vyos-1x-7fd4b50494d3b8865a7300e97c72df2a4fe11f14.zip | |
http-api: T7090: Implement background configure operations for REST API
Large config commits (`service config-sync`) can block the REST API request
path and sometimes must be deferred (e.g., when changing `service https`).
This commit introduces an in-memory background operation manager
that queues (FIFO) full configure operations (commands + commit/commit-confirm)
as single jobs, tracks status/result, and exposes active operations
via `/retrieve/background-operations`.
Diffstat (limited to 'src/helpers')
| -rwxr-xr-x | src/helpers/vyos_config_sync.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/helpers/vyos_config_sync.py b/src/helpers/vyos_config_sync.py index 80bfb6d17..f0650c5fc 100755 --- a/src/helpers/vyos_config_sync.py +++ b/src/helpers/vyos_config_sync.py @@ -40,9 +40,12 @@ logger.name = os.path.basename(__file__) API_HEADERS = {'Content-Type': 'application/json'} -def post_request(url: str, - data: str, - headers: Dict[str, str]) -> requests.Response: +def post_request( + url: str, + data: str, + params: Dict[str, Any], + headers: Dict[str, str], +) -> requests.Response: """Sends a POST request to the specified URL Args: @@ -54,11 +57,14 @@ def post_request(url: str, requests.Response: The response object representing the server's response to the request """ - response = requests.post(url, - data=data, - headers=headers, - verify=False, - timeout=timeout) + response = requests.post( + url, + data=data, + params=params, + headers=headers, + verify=False, + timeout=timeout, + ) return response @@ -116,6 +122,10 @@ def set_remote_config( urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) url = f'https://{address}:{port}/configure-section' + params = { + # Ask the remote API to perform the configure and commit workflow asynchronously + 'in_background': True, + } data = json.dumps({ 'op': op, 'mask': mask, @@ -124,7 +134,7 @@ def set_remote_config( }) try: - config = post_request(url, data, headers) + config = post_request(url, data, params, headers) return config.json() except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") |
