From 307e5ba1bbae8e0b5a904c6ac8a1c4f157013be9 Mon Sep 17 00:00:00 2001 From: hajipour <shajipour@cttc.es> Date: Sun, 19 Jan 2025 13:38:43 +0100 Subject: [PATCH] code polishing --- src/device/service/drivers/nce/Constants.py | 2 +- src/device/service/drivers/nce/Tools.py | 2 +- src/device/service/drivers/nce/__init__.py | 2 +- src/device/service/drivers/nce/driver.py | 11 +++++------ src/device/service/drivers/nce/nce_fan_client.py | 4 +++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/device/service/drivers/nce/Constants.py b/src/device/service/drivers/nce/Constants.py index df66eb16b..172c328ae 100644 --- a/src/device/service/drivers/nce/Constants.py +++ b/src/device/service/drivers/nce/Constants.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/device/service/drivers/nce/Tools.py b/src/device/service/drivers/nce/Tools.py index ba54beb36..f9b2f24a8 100644 --- a/src/device/service/drivers/nce/Tools.py +++ b/src/device/service/drivers/nce/Tools.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/device/service/drivers/nce/__init__.py b/src/device/service/drivers/nce/__init__.py index bbfc943b6..6242c89c7 100644 --- a/src/device/service/drivers/nce/__init__.py +++ b/src/device/service/drivers/nce/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/src/device/service/drivers/nce/driver.py b/src/device/service/drivers/nce/driver.py index 003a0fabf..4ac1a2b1c 100644 --- a/src/device/service/drivers/nce/driver.py +++ b/src/device/service/drivers/nce/driver.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -195,8 +195,10 @@ class NCEDriver(_Driver): self, resources: List[Tuple[str, Any]] ) -> List[Union[bool, Exception]]: results = [] + if len(resources) == 0: return results + with self.__lock: for resource in resources: resource_key, resource_value = resource @@ -215,13 +217,14 @@ class NCEDriver(_Driver): try: resource_value = json.loads(resource_value) if operation_type == "create": + self.nce.create_app_flow(resource_value) elif operation_type == "delete": + app_flow_name = resource_value["huawei-nce-app-flow:app-flows"][ "app-flow" ][0]["app-name"] self.nce.delete_app_flow(app_flow_name) - LOGGER.debug(f"app_flow_datamodel {resource_value}") results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( @@ -244,10 +247,6 @@ class NCEDriver(_Driver): LOGGER.info("resource = {:s}".format(str(resource))) resource_key, resource_value = resource try: - # resource_value = json.loads(resource_value) - # service_uuid = resource_value["uuid"] - # if service_exists(self.__tfs_nbi_root, self.__auth, service_uuid): - # self.tac.delete_connectivity_service(service_uuid) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( diff --git a/src/device/service/drivers/nce/nce_fan_client.py b/src/device/service/drivers/nce/nce_fan_client.py index fd42ef962..1c3523427 100644 --- a/src/device/service/drivers/nce/nce_fan_client.py +++ b/src/device/service/drivers/nce/nce_fan_client.py @@ -1,4 +1,4 @@ -# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# Copyright 2022-2025 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -71,6 +71,7 @@ class NCEClient: app_url = self._nce_fan_url + "/app-flows/apps" LOGGER.info(f'Creating app: {app_data} URL: {app_url}') requests.post(app_url, json=app_data, headers=HEADERS) + app_flow_data = { "app-flow": app_flow_data["huawei-nce-app-flow:app-flows"]["app-flow"] } @@ -85,6 +86,7 @@ class NCEClient: app_url = self._nce_fan_url + f"/app-flows/apps/application={app_flow_name}" LOGGER.info(f'Deleting app: {app_flow_name} URL: {app_url}') requests.delete(app_url) + app_flow_url = self._nce_fan_url + f"/app-flows/app-flow={app_flow_name}" LOGGER.info(f'Deleting app flow: {app_flow_name} URL: {app_flow_url}') requests.delete(app_flow_url) -- GitLab