summaryrefslogtreecommitdiff
path: root/docs/examples.md
diff options
context:
space:
mode:
authorRoberto Bertó <463349+robertoberto@users.noreply.github.com>2025-11-02 19:55:55 -0300
committerGitHub <noreply@github.com>2025-11-02 19:55:55 -0300
commit6ca1269b138696b69c33d2db4bcf7dd03ea4caeb (patch)
tree4c0a634730df2123ff506252cbec050de006dac8 /docs/examples.md
parent1ada32975f0bb559ec7526e0dd545700dde1cb94 (diff)
parent6b4e9015744ab8c9f17a6b8e23387cd676b1d827 (diff)
downloadpyvyos-6ca1269b138696b69c33d2db4bcf7dd03ea4caeb.tar.gz
pyvyos-6ca1269b138696b69c33d2db4bcf7dd03ea4caeb.zip
Merge pull request #27 from vyos-contrib/feat/architecture-and-quality-improvements
feat: v0.4.0 - Architecture refactor, bug fixes, and quality improvem…
Diffstat (limited to 'docs/examples.md')
-rw-r--r--docs/examples.md91
1 files changed, 91 insertions, 0 deletions
diff --git a/docs/examples.md b/docs/examples.md
new file mode 100644
index 0000000..6f4cf29
--- /dev/null
+++ b/docs/examples.md
@@ -0,0 +1,91 @@
+# Examples
+
+Common usage patterns and examples for PyVyOS.
+
+## Basic Connection
+
+```python
+from pyvyos import VyDevice
+device = VyDevice(hostname="192.168.1.1", apikey="your-api-key", verify=False)
+```
+
+## Viewing System Information
+
+```python
+response = device.show(path=["system", "image"])
+if not response.error:
+ print(response.result)
+```
+
+## Interface Configuration
+
+Add, view, get, or remove interface configuration:
+
+```python
+# Add address
+device.configure_set(path=["interfaces", "ethernet", "eth0", "address", "192.168.1.1/24"])
+
+# View configuration
+device.retrieve_show_config(path=["interfaces", "ethernet", "eth0"])
+
+# Get address value
+device.retrieve_return_values(path=["interfaces", "ethernet", "eth0", "address"])
+
+# Remove interface
+device.configure_delete(path=["interfaces", "dummy", "dum1"])
+```
+
+## Multiple Operations
+
+Execute multiple configuration changes atomically:
+
+```python
+device.configure_multiple_op(op_path=[
+ {"op": "set", "path": ["interfaces", "dummy", "dum1", "address", "192.168.1.1/24"]},
+ {"op": "set", "path": ["interfaces", "dummy", "dum1", "description", "Test"]},
+ {"op": "delete", "path": ["interfaces", "dummy", "old1"]}
+])
+```
+
+## Configuration Backup
+
+```python
+device.config_file_save(file="/config/backup-2024.config")
+device.config_file_load(file="/config/backup-2024.config")
+```
+
+## SSH Key Generation
+
+```python
+import random, string
+randstring = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(20))
+device.generate(path=["ssh", "client-key", f'/tmp/key_{randstring}'])
+```
+
+## System Operations
+
+```python
+device.reboot(path=["now"])
+device.poweroff(path=["now"])
+```
+
+## Error Handling
+
+```python
+response = device.configure_set(path=["invalid", "path"])
+if response.error:
+ print(f"Error {response.status}: {response.error}")
+else:
+ print("Success:", response.result)
+```
+
+## Working with Responses
+
+```python
+response = device.show(path=["system"])
+print(f"Status: {response.status}")
+if not response.error:
+ data = response.result # Process data...
+print(f"Request: {response.request}") # API key sanitized
+```
+