summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Berto <roberto.berto@under.com.br>2024-03-10 13:57:07 -0300
committerRoberto Berto <roberto.berto@under.com.br>2024-03-10 13:57:07 -0300
commit8ae0b4f237eb20d9ad9f511154df8eb554bde398 (patch)
tree60625b70ebcae51e0a48f67251eb6eb768f956fc
parentf3d382288980f4e49b6b9a1bd1b9f86e22f1f06c (diff)
parentc7f43864e8d31fde53105e991f88761947035124 (diff)
downloadpyvyos-8ae0b4f237eb20d9ad9f511154df8eb554bde398.tar.gz
pyvyos-8ae0b4f237eb20d9ad9f511154df8eb554bde398.zip
Merge branch 'main' of github.com-robertoberto:robertoberto/pyvyos
-rw-r--r--pyvyos/device.py59
1 files changed, 48 insertions, 11 deletions
diff --git a/pyvyos/device.py b/pyvyos/device.py
index 5b54394..6d8a1dc 100644
--- a/pyvyos/device.py
+++ b/pyvyos/device.py
@@ -106,24 +106,61 @@ class VyDevice:
Returns:
dict: The payload for the API request.
"""
- data = {
- 'op': op,
- 'path': path
+ if not path:
+ data = {
+ 'op': op,
+ 'path': path
+ }
+
+ if file is not None:
+ data['file'] = file
+
+ if url is not None:
+ data['url'] = url
+
+ if name is not None:
+ data['name'] = name
+
+ payload = {
+ 'data': json.dumps(data),
+ 'key': self.apikey
+ }
+
+ return payload
+
+ elif isinstance(path, list) and len(path) == 1:
+ # If path is a list and contains only one element, use it directly
+ data = {'op': op, 'path': path[0]}
+ else:
+ data = []
+ current_command = {'op': op, 'path': []}
+ for p in path:
+ if isinstance(p, list):
+ # If the current item is a list, merge it into the current command
+ if current_command['path']:
+ data.append(current_command)
+ current_command = {'op': op, 'path': p}
+ else:
+ # Otherwise, add the item to the current command's path
+ current_command['path'].append(p)
+
+ # Add the last command to data
+ if current_command['path']:
+ data.append(current_command)
+
+ payload = {
+ 'data': json.dumps(data),
+ 'key': self.apikey
}
if file is not None:
data['file'] = file
-
+
if url is not None:
- data['url'] = url
-
+ payload['url'] = url
+
if name is not None:
data['name'] = name
-
- payload = {
- 'data': json.dumps(data),
- 'key': self.apikey
- }
return payload