diff options
| author | omnom62 <75066712+omnom62@users.noreply.github.com> | 2026-06-04 06:48:22 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-04 06:48:22 +1000 |
| commit | 4d03dd58cd5d14b8f8094e2490034b31187aea2b (patch) | |
| tree | b42be5a26b1881fd81542d510a88aef8d4247d3b /plugins/module_utils/vyos_rest.py | |
| parent | 6a660fbbb1a855ca88b4926eda118f28f61518ca (diff) | |
| parent | cc8b7230098feb057ce5d903ded00ac0a7e648c0 (diff) | |
| download | rest.vyos-4d03dd58cd5d14b8f8094e2490034b31187aea2b.tar.gz rest.vyos-4d03dd58cd5d14b8f8094e2490034b31187aea2b.zip | |
Merge pull request #3 from vyos/init
Init Collection
Diffstat (limited to 'plugins/module_utils/vyos_rest.py')
| -rw-r--r-- | plugins/module_utils/vyos_rest.py | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/plugins/module_utils/vyos_rest.py b/plugins/module_utils/vyos_rest.py index 95b3aac..f4aa0dc 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 @@ -111,7 +80,7 @@ class VyOSRestClient: def _post_httpapi(self, endpoint, payload): try: - result = self._conn.send_request(endpoint=endpoint, **payload) + result = self._conn.send_request(endpoint, **payload) return result except ConnectionError as exc: raise VyOSRestError(str(exc)) @@ -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( + "/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: |
