diff --git a/src/device/service/drivers/ietf_actn/IetfActnDriver.py b/src/device/service/drivers/ietf_actn/IetfActnDriver.py index 6d0aada4e2ae512192ac79799cdebe1cb4b14fac..e432a41cee60a87bac92c1a066c43b541eb67151 100644 --- a/src/device/service/drivers/ietf_actn/IetfActnDriver.py +++ b/src/device/service/drivers/ietf_actn/IetfActnDriver.py @@ -16,45 +16,40 @@ import json, logging, requests, threading from typing import Any, Iterator, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.type_checkers.Checkers import chk_string, chk_type -from device.service.driver_api._Driver import _Driver -from device.service.drivers.ietf_actn.Tools import create_resource, delete_resource, get_resource -from . import ALL_RESOURCE_KEYS -#from .Tools import create_connectivity_service, find_key, config_getter, delete_connectivity_service +from device.service.driver_api._Driver import _Driver, RESOURCE_SERVICES +from .handlers.EthtServiceHandler import EthtServiceHandler +from .handlers.OsuTunnelHandler import OsuTunnelHandler +from .handlers.RestApiClient import RestApiClient LOGGER = logging.getLogger(__name__) +ALL_RESOURCE_KEYS = [ + RESOURCE_SERVICES, +] + DRIVER_NAME = 'ietf_actn' METRICS_POOL = MetricsPool('Device', 'Driver', labels={'driver': DRIVER_NAME}) - class IetfActnDriver(_Driver): def __init__(self, address: str, port: int, **settings) -> None: super().__init__(DRIVER_NAME, address, port, **settings) self.__lock = threading.Lock() self.__started = threading.Event() self.__terminate = threading.Event() - - username = self.settings.get('username') - password = self.settings.get('password') - self.__auth = HTTPBasicAuth(username, password) if username is not None and password is not None else None - - scheme = self.settings.get('scheme', 'http') - base_url = self.settings.get('base_url', DEFAULT_BASE_URL) - self.__base_url = '{:s}://{:s}:{:d}{:s}'.format(scheme, address, int(port), base_url) - - self.__timeout = int(self.settings.get('timeout', DEFAULT_TIMEOUT)) + self._rest_api_client = RestApiClient(address, port, settings=settings) + self._handler_osu_tunnel = OsuTunnelHandler(self._rest_api_client) + self._handler_etht_service = EthtServiceHandler(self._rest_api_client) def Connect(self) -> bool: - url = self.__base_url + '/tapi-common:context' with self.__lock: if self.__started.is_set(): return True try: - requests.get(url, timeout=self.__timeout, verify=False, auth=self.__auth) + self._rest_api_client.get('Check Credentials', '', []) except requests.exceptions.Timeout: - LOGGER.exception('Timeout connecting {:s}'.format(str(self.__base_url))) + LOGGER.exception('Timeout exception checking connectivity') return False except Exception: # pylint: disable=broad-except - LOGGER.exception('Exception connecting {:s}'.format(str(self.__base_url))) + LOGGER.exception('Unhandled exception checking connectivity') return False else: self.__started.set() @@ -78,25 +73,24 @@ class IetfActnDriver(_Driver): if len(resource_keys) == 0: resource_keys = ALL_RESOURCE_KEYS for i, resource_key in enumerate(resource_keys): chk_string('resource_key[#{:d}]'.format(i), resource_key, allow_empty=False) - results.extend(get_resource( - self.__base_url, resource_key, - timeout=self.__timeout, auth=self.__auth - )) + etht_service = self._handler_etht_service.get(etht_service_name) + osu_tunnel = self._handler_osu_tunnel.get(osu_tunnel_name) + service_data = {} + results.extend(('/service/service[...]', service_data)) 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 + if len(resources) == 0: return results with self.__lock: for resource_key, resource_value in resources: LOGGER.info('resource: key({:s}) => value({:s})'.format(str(resource_key), str(resource_value))) - if isinstance(value, str): value = json.loads(value) - results.extend(create_resource( - self.__base_url, resource_key, resource_value, - timeout=self.__timeout, auth=self.__auth - )) + if isinstance(resource_value, str): resource_value = json.loads(resource_value) + succeeded = self._handler_osu_tunnel.update(resource_value) + if succeeded: + succeeded = self._handler_etht_service.update(resource_value) + results.extend(succeeded) return results @metered_subclass_method(METRICS_POOL) @@ -106,11 +100,11 @@ class IetfActnDriver(_Driver): with self.__lock: for resource_key, resource_value in resources: LOGGER.info('resource: key({:s}) => value({:s})'.format(str(resource_key), str(resource_value))) - if isinstance(value, str): value = json.loads(value) - results.extend(delete_resource( - self.__base_url, resource_key, resource_value, - timeout=self.__timeout, auth=self.__auth - )) + if isinstance(resource_value, str): resource_value = json.loads(resource_value) + succeeded = self._handler_etht_service.delete(etht_service_name) + if succeeded: + succeeded = self._handler_osu_tunnel.delete(osu_tunnel_name) + results.extend(succeeded) return results @metered_subclass_method(METRICS_POOL) diff --git a/src/device/service/drivers/ietf_actn/__init__.py b/src/device/service/drivers/ietf_actn/__init__.py index d5073c330b89bed63f08b0da86c4a7649c87b3dd..38d04994fb0fa1951fb465bc127eb72659dc2eaf 100644 --- a/src/device/service/drivers/ietf_actn/__init__.py +++ b/src/device/service/drivers/ietf_actn/__init__.py @@ -11,10 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_SERVICES - -ALL_RESOURCE_KEYS = [ - RESOURCE_ENDPOINTS, - RESOURCE_SERVICES, -] diff --git a/src/device/service/drivers/ietf_actn/data.txt b/src/device/service/drivers/ietf_actn/data.txt new file mode 100644 index 0000000000000000000000000000000000000000..7248933e60abc52bc059cd9ec40e4799372ca377 --- /dev/null +++ b/src/device/service/drivers/ietf_actn/data.txt @@ -0,0 +1,14 @@ + +osu_tunnel_1: + delay = 20 + te_odu_number = 40 + src_ttp_channel_name = 'och:1-odu2:1-oduflex:1-osuflex:2' + dst_ttp_channel_name = 'och:1-odu2:1-oduflex:3-osuflex:1' + +etht_service_1: + etht_svc_type = 'op-mp2mp-svc' + src_endpoint_static_route_list: + dst='128.32.10.5', mask=24 => next_hop='128.32.33.5' + dst='128.32.20.5', mask=24 => next_hop='128.32.33.5' + dst_endpoint_static_route_list: + dst='172.1.101.22', mask=24 => next_hop='172.10.33.5'