summaryrefslogtreecommitdiff
path: root/example.py
diff options
context:
space:
mode:
authoreduardormorais <eduardoromorais@gmail.com>2025-08-28 18:01:24 -0300
committereduardormorais <eduardoromorais@gmail.com>2025-08-28 18:01:24 -0300
commit7b147d6964e6390a93b069c6cc2a06bdc2c7651f (patch)
treedf4cf9c9570378635578cd161bfb304e1ad1da89 /example.py
parente770412a93d2bbbc95bbb5a5edcdbb23036fd7dd (diff)
downloadpyvyos-7b147d6964e6390a93b069c6cc2a06bdc2c7651f.tar.gz
pyvyos-7b147d6964e6390a93b069c6cc2a06bdc2c7651f.zip
Feature - Separation of API communication logic into a separate class. Code adjustments and improvements.
Diffstat (limited to 'example.py')
-rw-r--r--example.py63
1 files changed, 32 insertions, 31 deletions
diff --git a/example.py b/example.py
index 2796329..85dccbe 100644
--- a/example.py
+++ b/example.py
@@ -1,10 +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
@@ -19,48 +21,47 @@ 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)
-
-
-
- #response = device.retrieve_show_config(['system'])
- #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)
+ device = VyDevice(
+ hostname=hostname, apikey=apikey, port=port, protocol=protocol, verify=verify
+ )
+ response = device.retrieve_show_config(["system"])
+ 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)