diff options
| author | eduardormorais <eduardoromorais@gmail.com> | 2025-09-01 19:19:13 -0300 |
|---|---|---|
| committer | eduardormorais <eduardoromorais@gmail.com> | 2025-09-01 19:19:13 -0300 |
| commit | c2b12490527ef60db79250d9d7524a3b970713e1 (patch) | |
| tree | c7762bd777f35e18ee6e7f7955d7a40d12f0d099 /example.py | |
| parent | 27a1362ff964d39c2f91f226d7453b65567df6bd (diff) | |
| download | pyvyos-c2b12490527ef60db79250d9d7524a3b970713e1.tar.gz pyvyos-c2b12490527ef60db79250d9d7524a3b970713e1.zip | |
Feature/9930599848 - Configuration and implementation of unit tests for the device
Diffstat (limited to 'example.py')
| -rw-r--r-- | example.py | 56 |
1 files changed, 51 insertions, 5 deletions
@@ -2,13 +2,11 @@ import warnings warnings.filterwarnings("ignore", category=RuntimeWarning) -import sys import os # adding pyvyos to sys.path # sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__)))) -import unittest from dotenv import load_dotenv import pprint import random @@ -16,8 +14,6 @@ import string # importing pyvyos modules from pyvyos.device import VyDevice -from pyvyos.device import ApiResponse - # getting env variables load_dotenv() @@ -36,11 +32,61 @@ else: if __name__ == "__main__": # preparing connection to vyos device device = VyDevice( - hostname=hostname, apikey=apikey, port=port, protocol=protocol, verify=verify + hostname=hostname, + apikey=apikey, + port=port, + protocol=protocol, + verify=verify, + timeout=60, ) response = device.retrieve_show_config(["system"]) pprint.pprint(response) + response = device.configure_set( + path=["interfaces", "dummy", "dum1", "address", "192.168.56.100/24"] + ) + pprint.pprint(response) + + response = device.retrieve_return_values( + path=["interfaces", "dummy", "dum1", "address"] + ) + pprint.pprint(response) + + response = device.configure_delete(path=["interfaces", "dummy", "dum1"]) + pprint.pprint(response) + + 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]) + pprint.pprint(response) + + response = device.show(path=["system", "image"]) + pprint.pprint(response) + + response = device.reset(path=["conntrack-sync", "internal-cache"]) + pprint.pprint(response) + + response = device.config_file_save(file="/config/test300.config") + pprint.pprint(response) + + response = device.config_file_load(file="/config/test300.config") + pprint.pprint(response) + + response = device.configure_multiple_op( + op_path=[ + { + "op": "set", + "path": ["interfaces", "dummy", "dum1", "address", "192.168.56.100/24"], + }, + { + "op": "delete", + "path": ["interfaces", "dummy", "dum1"], + }, + ] + ) + pprint.pprint(response) # print("### Generating ssh key ###") # randstring = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20)) |
