summaryrefslogtreecommitdiff
path: root/docs/automation
diff options
context:
space:
mode:
Diffstat (limited to 'docs/automation')
-rw-r--r--docs/automation/cloud-init.rst12
-rw-r--r--docs/automation/command-scripting.rst2
-rw-r--r--docs/automation/index.rst2
-rw-r--r--docs/automation/vyos-api.rst37
-rw-r--r--docs/automation/vyos-pyvyos.rst148
5 files changed, 194 insertions, 7 deletions
diff --git a/docs/automation/cloud-init.rst b/docs/automation/cloud-init.rst
index 2fa102b1..b396fee0 100644
--- a/docs/automation/cloud-init.rst
+++ b/docs/automation/cloud-init.rst
@@ -96,8 +96,8 @@ first boot.
#cloud-config
vyos_config_commands:
- set system host-name 'vyos-prod-ashburn'
- - set system ntp server 1.pool.ntp.org
- - set system ntp server 2.pool.ntp.org
+ - set service ntp server 1.pool.ntp.org
+ - set service ntp server 2.pool.ntp.org
- delete interfaces ethernet eth1 address 'dhcp'
- set interfaces ethernet eth1 address '192.0.2.247/24'
- set protocols static route 198.51.100.0/24 next-hop '192.0.2.1'
@@ -215,7 +215,7 @@ the method with KVM to attach the ISO as a CD drive follows.
For more information on the NoCloud data source, visit its `page
-<https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html>`_
+<https://cloudinit.readthedocs.io/en/latest/reference/datasources/nocloud.html>`_
in the cloud-init documentation.
***************
@@ -223,7 +223,7 @@ Troubleshooting
***************
If you encounter problems, verify that the cloud-config document contains
-valid YAML. Online resources such as https://yamlvalidator.com/ provide
+valid YAML. Online resources such as https://www.yamllint.com/ provide
a simple tool for validating YAML.
cloud-init logs to /var/log/cloud-init.log. This file can be helpful in
@@ -319,8 +319,8 @@ vyos-commands. For example:
#cloud-config
vyos_config_commands:
- set system host-name 'vyos-BRAS'
- - set system ntp server 1.pool.ntp.org
- - set system ntp server 2.pool.ntp.org
+ - set service ntp server 1.pool.ntp.org
+ - set service ntp server 2.pool.ntp.org
- delete interfaces ethernet eth0 address 'dhcp'
- set interfaces ethernet eth0 address '198.51.100.2/30'
- set interfaces ethernet eth0 description 'WAN - ISP01'
diff --git a/docs/automation/command-scripting.rst b/docs/automation/command-scripting.rst
index 64564e5a..c8a72a36 100644
--- a/docs/automation/command-scripting.rst
+++ b/docs/automation/command-scripting.rst
@@ -94,7 +94,7 @@ Here is a simple example:
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
configure
- source < /config/scripts/setfirewallgroup.py
+ source <(/config/scripts/setfirewallgroup.py)
commit
diff --git a/docs/automation/index.rst b/docs/automation/index.rst
index dd7b596a..ee8282ac 100644
--- a/docs/automation/index.rst
+++ b/docs/automation/index.rst
@@ -17,3 +17,5 @@ VyOS Automation
vyos-salt
command-scripting
cloud-init
+ vyos-pyvyos
+
diff --git a/docs/automation/vyos-api.rst b/docs/automation/vyos-api.rst
index efd00dd8..afcc1767 100644
--- a/docs/automation/vyos-api.rst
+++ b/docs/automation/vyos-api.rst
@@ -143,6 +143,43 @@ The ``reset`` endpoint run a ``reset`` command.
"error": null
}
+/reboot
+=======
+
+To initiate a reboot use the ``reboot`` endpoint.
+
+.. code-block:: none
+
+ curl --location --request POST 'https://vyos/reboot' \
+ --form data='{"op": "reboot", "path": ["now"]}' \
+ --form key='MY-HTTPS-API-PLAINTEXT-KEY'
+
+ respone:
+ {
+ "success": true,
+ "data": "",
+ "error": null
+ }
+
+/poweroff
+=========
+
+To power off the system use the ``poweroff`` endpoint.
+
+.. code-block:: none
+
+ curl --location --request POST 'https://vyos/poweroff' \
+ --form data='{"op": "poweroff", "path": ["now"]}' \
+ --form key='MY-HTTPS-API-PLAINTEXT-KEY'
+
+ respone:
+ {
+ "success": true,
+ "data": "",
+ "error": null
+ }
+
+
/image
======
diff --git a/docs/automation/vyos-pyvyos.rst b/docs/automation/vyos-pyvyos.rst
new file mode 100644
index 00000000..fba9b8b7
--- /dev/null
+++ b/docs/automation/vyos-pyvyos.rst
@@ -0,0 +1,148 @@
+:lastproofread: 2023-12-15
+
+.. _vyos-pyvyos:
+
+PyVyOS
+======
+
+PyVyOS is a Python library for interacting with VyOS devices via their API.
+This documentation guides you on using PyVyOS to manage your VyOS devices programmatically.
+The complete PyVyOS documentation is available on [Read the Docs](https://pyvyos.readthedocs.io/en/latest/),
+and the library can be found on [GitHub](https://github.com/robertoberto/pyvyos)
+and [PyPI](https://pypi.org/project/pyvyos/).
+
+Installation
+------------
+
+You can install PyVyOS using pip:
+
+.. code-block:: bash
+
+ pip install pyvyos
+
+Getting Started
+---------------
+
+Importing and Disabling Warnings for verify=False
+-------------------------------------------------
+
+.. code-block:: none
+
+ import urllib3
+ urllib3.disable_warnings()
+
+Using API Response Class
+------------------------
+
+.. code-block:: none
+
+ @dataclass
+ class ApiResponse:
+ status: int
+ request: dict
+ result: dict
+ error: str
+
+Initializing a VyDevice Object
+------------------------------
+
+.. code-block:: none
+
+ from dotenv import load_dotenv
+ load_dotenv()
+
+ hostname = os.getenv('VYDEVICE_HOSTNAME')
+ apikey = os.getenv('VYDEVICE_APIKEY')
+ port = os.getenv('VYDEVICE_PORT')
+ protocol = os.getenv('VYDEVICE_PROTOCOL')
+ verify_ssl = os.getenv('VYDEVICE_VERIFY_SSL')
+
+ verify = verify_ssl.lower() == "true" if verify_ssl else True
+
+ device = VyDevice(hostname=hostname, apikey=apikey, port=port, protocol=protocol, verify=verify)
+
+Using PyVyOS
+------------
+
+Configure, then Set
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.configure_set(path=["interfaces", "ethernet", "eth0", "address", "192.168.1.1/24"])
+ if not response.error:
+ print(response.result)
+
+Configure, then Show a Single Object Value
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.retrieve_return_values(path=["interfaces", "dummy", "dum1", "address"])
+ print(response.result)
+
+Configure, then Show Object
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.retrieve_show_config(path=[])
+ if not response.error:
+ print(response.result)
+
+Configure, then Delete Object
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.configure_delete(path=["interfaces", "dummy", "dum1"])
+
+Configure, then Save
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.config_file_save()
+
+Configure, then Save File
+-------------------------
+
+.. code-block:: none
+
+ response = device.config_file_save(file="/config/test300.config")
+
+Show Object
+^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.show(path=["system", "image"])
+ print(response.result)
+
+Generate Object
+^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ randstring = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
+ keyrand = f'/tmp/key_{randstring}'
+ response = device.generate(path=["ssh", "client-key", keyrand])
+
+Reset Object
+^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.reset(path=["conntrack-sync", "internal-cache"])
+ if not response.error:
+ print(response.result)
+
+Configure, then Load File
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. code-block:: none
+
+ response = device.config_file_load(file="/config/test300.config")
+
+
+.. _pyvyos: https://github.com/robertoberto/pyvyos \ No newline at end of file