From 5ddadb6a5f2e4ee1e60be0b0988bf12287f84c3e Mon Sep 17 00:00:00 2001 From: hajipour <shajipour@cttc.es> Date: Sat, 18 Jan 2025 21:39:48 +0100 Subject: [PATCH] minor polish --- .../service/drivers/ietf_slice/Constants.py | 2 +- .../service/drivers/ietf_slice/Tools.py | 2 +- .../service/drivers/ietf_slice/__init__.py | 2 +- .../service/drivers/ietf_slice/driver.py | 20 ++++++++++++------- .../ietf_slice/tfs_slice_nbi_client.py | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/device/service/drivers/ietf_slice/Constants.py b/src/device/service/drivers/ietf_slice/Constants.py index df66eb16b..172c328ae 100644 --- a/src/device/service/drivers/ietf_slice/Constants.py +++ b/src/device/service/drivers/ietf_slice/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/ietf_slice/Tools.py b/src/device/service/drivers/ietf_slice/Tools.py index fddfd8940..bd976927e 100644 --- a/src/device/service/drivers/ietf_slice/Tools.py +++ b/src/device/service/drivers/ietf_slice/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/ietf_slice/__init__.py b/src/device/service/drivers/ietf_slice/__init__.py index bbfc943b6..6242c89c7 100644 --- a/src/device/service/drivers/ietf_slice/__init__.py +++ b/src/device/service/drivers/ietf_slice/__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/ietf_slice/driver.py b/src/device/service/drivers/ietf_slice/driver.py index a7e91925c..e8b6e7d0e 100644 --- a/src/device/service/drivers/ietf_slice/driver.py +++ b/src/device/service/drivers/ietf_slice/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. @@ -200,15 +200,16 @@ class IetfSliceDriver(_Driver): continue results.extend(dump_subtree(resource_node)) return results - return results @metered_subclass_method(METRICS_POOL) def SetConfig( 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 @@ -225,26 +226,33 @@ class IetfSliceDriver(_Driver): continue try: resource_value = json.loads(resource_value) + slice_name = resource_value["network-slice-services"][ "slice-service" ][0]["id"] + if operation_type == "create": self.tac.create_slice(resource_value) + elif operation_type == "update": connection_groups = resource_value["network-slice-services"][ "slice-service" ][0]["connection-groups"]["connection-group"] + if len(connection_groups) != 1: raise Exception("only one connection group is supported") + connection_group = connection_groups[0] + self.tac.update_slice( slice_name, connection_group["id"], connection_group ) + elif operation_type == "delete": self.tac.delete_slice(slice_name) + results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except - raise e LOGGER.exception( "Unhandled error processing resource_key({:s})".format( str(resource_key) @@ -258,17 +266,15 @@ class IetfSliceDriver(_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: 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_slice(service_uuid) results.append((resource_key, True)) except Exception as e: # pylint: disable=broad-except LOGGER.exception( diff --git a/src/device/service/drivers/ietf_slice/tfs_slice_nbi_client.py b/src/device/service/drivers/ietf_slice/tfs_slice_nbi_client.py index 5716982af..596e3d903 100644 --- a/src/device/service/drivers/ietf_slice/tfs_slice_nbi_client.py +++ b/src/device/service/drivers/ietf_slice/tfs_slice_nbi_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. @@ -23,7 +23,7 @@ TIMEOUT = 30 LOGGER = logging.getLogger(__name__) -HEADERS = {'Content-Type': 'application/json'} +HEADERS = {"Content-Type": "application/json"} class TfsApiClient: -- GitLab