diff options
| author | Roberto Bertó <463349+robertoberto@users.noreply.github.com> | 2025-09-18 13:08:55 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-18 13:08:55 -0300 |
| commit | 9a69a954a086df321640dfa65a2ac0ac35a15095 (patch) | |
| tree | 3c8e41a08dab6e47e4639e09eebcc37c4549b914 /example.py | |
| parent | 85e4714c53b662c45a1f6ee4b6cb0089ad29cc7b (diff) | |
| parent | f25d28ab90a266c03fd966ddabc752088da080d6 (diff) | |
| download | pyvyos-9a69a954a086df321640dfa65a2ac0ac35a15095.tar.gz pyvyos-9a69a954a086df321640dfa65a2ac0ac35a15095.zip | |
Merge pull request #18 from eduardormorais/release/0.3.0
Updating version release 0.3.0
Diffstat (limited to 'example.py')
| -rw-r--r-- | example.py | 109 |
1 files changed, 78 insertions, 31 deletions
@@ -1,12 +1,12 @@ # importing modules 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__)))) +# sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__)))) -import unittest from dotenv import load_dotenv import pprint import random @@ -14,53 +14,100 @@ import string # importing pyvyos modules from pyvyos.device import VyDevice -from pyvyos.device import ApiResponse - # getting env variables load_dotenv() -hostname = os.getenv('VYDEVICE_HOSTNAME') -apikey = os.getenv('VYDEVICE_APIKEY') -port = os.getenv('VYDEVICE_PORT') -protocol = os.getenv('VYDEVICE_PROTOCOL') -verify = os.getenv('VYDEVICE_VERIFY_SSL') +hostname = os.getenv("VYDEVICE_HOSTNAME") +apikey = os.getenv("VYDEVICE_APIKEY") +port = os.getenv("VYDEVICE_PORT") +protocol = os.getenv("VYDEVICE_PROTOCOL") +verify = os.getenv("VYDEVICE_VERIFY_SSL") + if verify == "False": verify = False else: verify = True # running example -if __name__ == '__main__': +if __name__ == "__main__": # preparing connection to vyos device - device = VyDevice(hostname=hostname, apikey=apikey, port=port, protocol=protocol, verify=verify) + device = VyDevice( + 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.retrieve_show_config(['system']) - #pprint.pprint(response) + response = device.reset(path=["conntrack-sync", "internal-cache"]) + pprint.pprint(response) - #print("### Generating ssh key ###") - #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.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)) + # keyrand = f'/tmp/key_{randstring}' + # response = device.generate(path=["ssh", "client-key", keyrand]) + # pprint.pprint(response) - #response = device.retrieve_return_values(path=["interfaces", "ethernet", "eth0", "address"]) - #pprint.pprint(response) + # response = device.retrieve_return_values(path=["interfaces", "ethernet", "eth0", "address"]) + # pprint.pprint(response) - #response = device.reset(path=["conntrack-sync", "internal-cache"]) - #pprint.pprint(response) + # response = device.reset(path=["conntrack-sync", "internal-cache"]) + # pprint.pprint(response) - #response = device.reboot(path=["now"]) - #pprint.pprint(response) + # response = device.reboot(path=["now"]) + # pprint.pprint(response) - #response = device.shutdown(path=["now"]) - #pprint.pprint(response) + # response = device.shutdown(path=["now"]) + # pprint.pprint(response) - #response = device.image_add(url="https://github.com/vyos/vyos-rolling-nightly-builds/releases/download/1.5-rolling-202312130023/vyos-1.5-rolling-202312130023-amd64.iso") - #pprint.pprint(response) + # response = device.image_add(url="https://github.com/vyos/vyos-rolling-nightly-builds/releases/download/1.5-rolling-202312130023/vyos-1.5-rolling-202312130023-amd64.iso") + # pprint.pprint(response) - response = device.image_delete(name="foo") - pprint.pprint(response) + # response = device.image_delete(name="foo") + # pprint.pprint(response) |
