diff options
| author | anusajith <88121157+anusajith@users.noreply.github.com> | 2024-05-20 09:41:53 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-20 09:41:53 +1000 |
| commit | f0d26d17c0260cc3444a1a8ba78f841d746f0c5c (patch) | |
| tree | 4f4be7bcefe279ace41a05282e641664f10c3f62 | |
| parent | 5e96d1a01056c5ad1a1308c0a6a31f59d09c6c49 (diff) | |
| download | pyvyos-f0d26d17c0260cc3444a1a8ba78f841d746f0c5c.tar.gz pyvyos-f0d26d17c0260cc3444a1a8ba78f841d746f0c5c.zip | |
Update device.py
adding support for multiple operation in a single commit
| -rw-r--r-- | pyvyos/device.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/pyvyos/device.py b/pyvyos/device.py index d168b65..0fc4a7b 100644 --- a/pyvyos/device.py +++ b/pyvyos/device.py @@ -107,11 +107,16 @@ class VyDevice: Returns: dict: The payload for the API request. """ - # Adjusting the data structure based on whether path is single or multiple - if isinstance(path[0], list): # Handling multiple paths - data = [{'op': op, 'path': p} for p in path] - else: # Handling a single path - data = {'op': op, 'path': path} + # Adding option to pass multiple operation (eg:delete and set) commands + if op: + # Adjusting the data structure based on whether path is single or multiple + if path and isinstance(path, list) and isinstance(path[0], list): # Handling multiple paths + data = [{'op': op, 'path': p} for p in path] + else: # Handling a single path + data = {'op': op, 'path': path} + else: + if path and isinstance(path[0], dict): + data = path # Including the optional parameters if provided if file: @@ -308,6 +313,19 @@ class VyDevice: """ return self._api_request(command="configure", op='delete', path=path, method="POST") + def configure_multiple_op(self, op_path=[]): + """ + Set configuration based on the given path for multiple operation. + + Args: + op_path (list): The path elements for configuration deletion or/and setting alongwith operations specific to them. + eg: [{'op': 'delete', 'path': [...]}, {'op': 'set', 'path': [...]}] + + Returns: + ApiResponse: An ApiResponse object representing the API response. + """ + return self._api_request(command="configure", op=None, path=op_path) + def config_file_save(self, file=None): """ Save the configuration to a file. |
