summaryrefslogtreecommitdiff
path: root/plugins/module_utils/vyos_rest.py
diff options
context:
space:
mode:
authoromnom62 <omnom62@outlook.com>2026-05-31 07:25:03 +1000
committeromnom62 <omnom62@outlook.com>2026-05-31 07:25:03 +1000
commit6a161ed8f263e152ebfd227e669a51773de5a028 (patch)
treeefd9cef101e459daa021b98ba00e5f75d897048e /plugins/module_utils/vyos_rest.py
parentf37d4e313154ea7ea40250849549065196fab722 (diff)
downloadrest.vyos-6a161ed8f263e152ebfd227e669a51773de5a028.tar.gz
rest.vyos-6a161ed8f263e152ebfd227e669a51773de5a028.zip
updated tests
Diffstat (limited to 'plugins/module_utils/vyos_rest.py')
-rw-r--r--plugins/module_utils/vyos_rest.py48
1 files changed, 16 insertions, 32 deletions
diff --git a/plugins/module_utils/vyos_rest.py b/plugins/module_utils/vyos_rest.py
index 95b3aac..aaf2b23 100644
--- a/plugins/module_utils/vyos_rest.py
+++ b/plugins/module_utils/vyos_rest.py
@@ -1,36 +1,5 @@
"""
VyOS REST API client utility — supports both connection modes.
-
-**httpapi mode (recommended)**::
-
- # inventory
- vyos15x ansible_host=192.168.122.194
- ansible_network_os=vyos.rest.vyos
- ansible_connection=ansible.netcommon.httpapi
- ansible_httpapi_use_ssl=true
- ansible_httpapi_port=443
- ansible_httpapi_validate_certs=false
- ansible_httpapi_api_key=vyos123
-
- # playbook — no connection params needed on any task
- - vyos.rest.vyos_banner:
- banner: pre-login
- text: "Authorised use only."
- state: present
-
-**local mode (alternative, no inventory network_os required)**::
-
- - vyos.rest.vyos_banner:
- hostname: 192.168.122.194
- api_key: vyos123
- verify_ssl: false
- banner: pre-login
- text: "Authorised use only."
- state: present
-
-Both modes call the same VyOS endpoints. The httpapi mode routes calls
-through the persistent connection daemon (better for large inventories);
-the local mode opens a new HTTPS connection per task.
"""
from __future__ import absolute_import, division, print_function
@@ -45,7 +14,7 @@ import os
try:
from urllib.parse import urlencode
except ImportError:
- from urllib import urlencode # Python 2
+ from urllib import urlencode
try:
import urllib3
@@ -218,6 +187,21 @@ class VyOSRestClient:
def image_delete(self, name):
return self._post("/image", {"op": "delete", "name": name})
+ def configure_batch(self, commands):
+ """Send all commands as a single atomic commit."""
+ if self._mode == "httpapi":
+ try:
+ return self._conn.send_request(
+ endpoint="/configure",
+ _raw_list=commands,
+ )
+ except ConnectionError as exc:
+ raise VyOSRestError(str(exc))
+ except Exception as exc:
+ raise VyOSRestError(
+ "configure_batch failed: {e}".format(e=str(exc)),
+ )
+
def config_file_save(self, path=None):
payload = {"op": "save"}
if path: