From f0d26d17c0260cc3444a1a8ba78f841d746f0c5c Mon Sep 17 00:00:00 2001 From: anusajith <88121157+anusajith@users.noreply.github.com> Date: Mon, 20 May 2024 09:41:53 +1000 Subject: Update device.py adding support for multiple operation in a single commit --- pyvyos/device.py | 28 +++++++++++++++++++++++----- 1 file 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. -- cgit v1.2.3 From ac03cf884fade1c6945763b6d399e758d706a02b Mon Sep 17 00:00:00 2001 From: anusajith <88121157+anusajith@users.noreply.github.com> Date: Mon, 20 May 2024 10:08:26 +1000 Subject: Update device.py --- pyvyos/device.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyvyos/device.py b/pyvyos/device.py index 0fc4a7b..d0ee654 100644 --- a/pyvyos/device.py +++ b/pyvyos/device.py @@ -315,16 +315,16 @@ class VyDevice: def configure_multiple_op(self, op_path=[]): """ - Set configuration based on the given path for multiple operation. + Set configuration based on the given {operation : path} for multiple operation. Args: - op_path (list): The path elements for configuration deletion or/and setting alongwith operations specific to them. + op_path (list): The path elements for configuration deletion or/and setting. 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) + return self._api_request(command="configure", op="", path=op_path) def config_file_save(self, file=None): """ -- cgit v1.2.3