diff options
author | Roberto Bertó <roberto.berto@gmail.com> | 2023-12-14 13:16:08 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-14 13:16:08 -0300 |
commit | b7c5de2ba791622d34706cad211fb763e9518c82 (patch) | |
tree | cb1cf376225d7553e13246358d06aff5383e61e5 | |
parent | d5fcce81b1f0972ecfd948c1df6ab2df73c2c8fa (diff) | |
download | pyvyos-b7c5de2ba791622d34706cad211fb763e9518c82.tar.gz pyvyos-b7c5de2ba791622d34706cad211fb763e9518c82.zip |
Update README.md
improved documentation with better names and .env example
-rw-r--r-- | README.md | 99 |
1 files changed, 48 insertions, 51 deletions
@@ -35,46 +35,56 @@ class ApiResponse: ``` ### Initializing a VyDevice Object -To interact with your VyOS device, you'll need to create an instance of the VyDevice class. You can set up your device using the following code, -assuming you've stored your credentials as environment variables: + + +#### Configuring Your Environment for VyDevice +# Rename the file .env.example to .env. +# Open the .env file in a text editor. +# Replace the placeholder values with your VyOS device credentials: ``` -from dotenv import load_dotenv +VYDEVICE_HOSTNAME: Your device's hostname or IP address. +VYDEVICE_APIKEY: Your API key for authentication. +VYDEVICE_PORT: The port number for the API. Default 443 +VYDEVICE_PROTOCOL: The protocol (e.g., http or https). Default https +VYDEVICE_VERIFY_SSL: Set to True or False for SSL verification. +``` -# Load environment variables from a .env file -load_dotenv() -# Retrieve VyOS device connection details from environment variables +``` +# Retrieve VyOS device connection details from environment variables and configure VyDevice +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') - -# Convert the verify_ssl value to a boolean -verify = verify_ssl.lower() == "true" if verify_ssl else True - -# Create an instance of the VyOS device +verify = verify_ssl.lower() == "true" if verify_ssl else True # Convert the verify_ssl value to a boolean device = VyDevice(hostname=hostname, apikey=apikey, port=port, protocol=protocol, verify=verify) ``` ## Using PyVyOS -Once you have created a VyDevice object, you can use it to interact with your VyOS device using various methods provided by the library. - -### Reset -The reset method allows you to run a reset command: +### configure, then set +The configure_set method sets a VyOS configuration: ``` -# Execute the reset command -response = device.reset(path=["conntrack-sync", "internal-cache"]) +# Set a VyOS configuration +response = device.configure_set(path=["interfaces", "ethernet", "eth0", "address", "192.168.1.1/24"]) # Check for errors and print the result if not response.error: print(response.result) ``` +### configure, then show a single OBJECT value +``` +# Retrieve VyOS return values for a specific interface +response = device.retrieve_return_values(path=["interfaces", "dummy", "dum1", "address"]) +print(response.result) +``` -### Retrieve Show Configuration +### configure, then show OBJECT The retrieve_show_config method retrieves the VyOS configuration: ``` @@ -86,65 +96,52 @@ if not response.error: print(response.result) ``` -### Retrieve Return Values +### configure, then delete OBJECT ``` -# Retrieve VyOS return values for a specific interface -response = device.retrieve_return_values(path=["interfaces", "dummy", "dum1", "address"]) -print(response.result) +# Delete a VyOS interface configuration +response = device.configure_delete(path=["interfaces", "dummy", "dum1"]) ``` -### Configure Delete +### configure, then save ``` -# Delete a VyOS interface configuration -response = device.configure_delete(path=["interfaces", "dummy", "dum1"]) +# Save VyOS configuration without specifying a file (default location) +response = device.config_file_save() ``` -### Generate +### configure, then save FILE ``` -# Generate an SSH key with a random string in the name -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]) +# Save VyOS configuration to a specific file +response = device.config_file_save(file="/config/test300.config") ``` -### Show +## show OBJECT ``` # Show VyOS system image information response = device.show(path=["system", "image"]) print(response.result) ``` -### Reset +### generate OBJECT ``` -# Reset VyOS with specific parameters -response = device.reset(path=["conntrack-sync", "internal-cache"]) +# Generate an SSH key with a random string in the name +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]) ``` -### Configure Set -The configure_set method sets a VyOS configuration: +### reset OBJECT +The reset method allows you to run a reset command: ``` -# Set a VyOS configuration -response = device.configure_set(path=["interfaces", "ethernet", "eth0", "address", "192.168.1.1/24"]) +# Execute the reset command +response = device.reset(path=["conntrack-sync", "internal-cache"]) # Check for errors and print the result if not response.error: print(response.result) ``` -### Config File Save -``` -# Save VyOS configuration without specifying a file (default location) -response = device.config_file_save() -``` - -### Config File Save with custom filename -``` -# Save VyOS configuration to a specific file -response = device.config_file_save(file="/config/test300.config") -``` - -### Config File Load +### configure, then load FILE ``` # Load VyOS configuration from a specific file response = device.config_file_load(file="/config/test300.config") |