From b2c1c8a31b555b0198cb657c0f791208454b5854 Mon Sep 17 00:00:00 2001 From: Roberto Berto Date: Fri, 15 Dec 2023 17:21:16 -0300 Subject: + pyvyos python sdk --- docs/automation/index.rst | 2 + docs/automation/vyos-pyvyos.rst | 134 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 docs/automation/vyos-pyvyos.rst (limited to 'docs') diff --git a/docs/automation/index.rst b/docs/automation/index.rst index dd7b596a..22414cca 100644 --- a/docs/automation/index.rst +++ b/docs/automation/index.rst @@ -13,7 +13,9 @@ VyOS Automation vyos-api vyos-ansible vyos-napalm + vyos-pyvyos vyos-netmiko vyos-salt command-scripting cloud-init + diff --git a/docs/automation/vyos-pyvyos.rst b/docs/automation/vyos-pyvyos.rst new file mode 100644 index 00000000..fba1e0c1 --- /dev/null +++ b/docs/automation/vyos-pyvyos.rst @@ -0,0 +1,134 @@ +: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 -- cgit v1.2.3 From ddc9c32d0209dd7bcac0ae99dba36f010a53398b Mon Sep 17 00:00:00 2001 From: Roberto Berto Date: Fri, 15 Dec 2023 17:32:23 -0300 Subject: + pyvyos python sdk improved titles --- docs/automation/index.rst | 2 +- docs/automation/vyos-pyvyos.rst | 40 +++++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'docs') diff --git a/docs/automation/index.rst b/docs/automation/index.rst index 22414cca..ee8282ac 100644 --- a/docs/automation/index.rst +++ b/docs/automation/index.rst @@ -13,9 +13,9 @@ VyOS Automation vyos-api vyos-ansible vyos-napalm - vyos-pyvyos vyos-netmiko vyos-salt command-scripting cloud-init + vyos-pyvyos diff --git a/docs/automation/vyos-pyvyos.rst b/docs/automation/vyos-pyvyos.rst index fba1e0c1..d3740b42 100644 --- a/docs/automation/vyos-pyvyos.rst +++ b/docs/automation/vyos-pyvyos.rst @@ -23,14 +23,16 @@ You can install PyVyOS using pip: Getting Started --------------- -### Importing and Disabling Warnings for verify=False +Importing and Disabling Warnings for verify=False +------------------------------------------------- .. code-block:: none import urllib3 urllib3.disable_warnings() -### Using API Response Class +Using API Response Class +------------------------ .. code-block:: none @@ -41,7 +43,8 @@ Getting Started result: dict error: str -### Initializing a VyDevice Object +Initializing a VyDevice Object +------------------------------ .. code-block:: none @@ -61,7 +64,8 @@ Getting Started Using PyVyOS ------------ -### Configure, then Set +Configure, then Set +^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: none @@ -69,14 +73,16 @@ Using PyVyOS if not response.error: print(response.result) -### Configure, then Show a Single Object Value +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 +Configure, then Show Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: none @@ -84,32 +90,37 @@ Using PyVyOS if not response.error: print(response.result) -### Configure, then Delete Object +Configure, then Delete Object +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: none response = device.configure_delete(path=["interfaces", "dummy", "dum1"]) -### Configure, then Save +Configure, then Save +^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: none response = device.config_file_save() -### Configure, then Save File +Configure, then Save File +------------------------- .. code-block:: none response = device.config_file_save(file="/config/test300.config") -### Show Object +Show Object +^^^^^^^^^^^^^^ .. code-block:: none response = device.show(path=["system", "image"]) print(response.result) -### Generate Object +Generate Object +^^^^^^^^^^^^^^^^ .. code-block:: none @@ -117,7 +128,8 @@ Using PyVyOS keyrand = f'/tmp/key_{randstring}' response = device.generate(path=["ssh", "client-key", keyrand]) -### Reset Object +Reset Object +^^^^^^^^^^^^^^ .. code-block:: none @@ -125,10 +137,12 @@ Using PyVyOS if not response.error: print(response.result) -### Configure, then Load File +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 -- cgit v1.2.3 From 0993a91255cad0dd893b7a60e05fd2120a343407 Mon Sep 17 00:00:00 2001 From: Roberto Berto Date: Fri, 15 Dec 2023 17:35:47 -0300 Subject: + pyvyos python sdk improved href at botoom --- docs/automation/vyos-pyvyos.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/automation/vyos-pyvyos.rst b/docs/automation/vyos-pyvyos.rst index d3740b42..fba9b8b7 100644 --- a/docs/automation/vyos-pyvyos.rst +++ b/docs/automation/vyos-pyvyos.rst @@ -145,4 +145,4 @@ Configure, then Load File response = device.config_file_load(file="/config/test300.config") -. _pyvyos: https://github.com/robertoberto/pyvyos \ No newline at end of file +.. _pyvyos: https://github.com/robertoberto/pyvyos \ No newline at end of file -- cgit v1.2.3