Commit bc2f917a authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component - Optical TFS Driver:

- Revert removal of configurable context/topology UUIDs
parent 1c9bfe19
Loading
Loading
Loading
Loading
+5 −1
Changes for src/device/service/drivers/optical_tfs/OpticalTfsDriver.py: 5 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import json, logging, 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 common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from device.service.driver_api._Driver import _Driver, RESOURCE_ENDPOINTS, RESOURCE_SERVICES
from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get_import_topology
from .TfsApiClient import TfsApiClient
@@ -42,9 +43,12 @@ class OpticalTfsDriver(_Driver):
        password = self.settings.get('password')
        scheme   = self.settings.get('scheme', 'http')
        timeout  = int(self.settings.get('timeout', 60))
        self.__context_uuid = self.settings.get('context_uuid', DEFAULT_CONTEXT_NAME)
        self.__topology_uuid = self.settings.get('topology_uuid', DEFAULT_TOPOLOGY_NAME)
        self.tac = TfsApiClient(
            self.address, self.port, scheme=scheme, username=username,
            password=password, timeout=timeout
            password=password, timeout=timeout,
            context_uuid=self.__context_uuid, topology_uuid=self.__topology_uuid
        )
        #self.toc = TfsOpticalClient(
        #    self.address, int(self.port), scheme=scheme, username=username,
+13 −9
Changes for src/device/service/drivers/optical_tfs/TfsApiClient.py: 13 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -71,12 +71,16 @@ class TfsApiClient(RestApiClient):
    def __init__(
        self, address : str, port : int, scheme : str = 'http',
        username : Optional[str] = None, password : Optional[str] = None,
        timeout : Optional[int] = 30
        timeout : Optional[int] = 30,
        context_uuid : str = DEFAULT_CONTEXT_NAME,
        topology_uuid : str = DEFAULT_TOPOLOGY_NAME
    ) -> None:
        super().__init__(
            address, port, scheme=scheme, username=username, password=password,
            timeout=timeout, verify_certs=False, allow_redirects=True, logger=LOGGER
        )
        self.context_uuid = context_uuid
        self.topology_uuid = topology_uuid


    def check_credentials(self, raise_if_fail : bool = True) -> None:
@@ -111,7 +115,7 @@ class TfsApiClient(RestApiClient):
            raise Exception(MSG.format(str(import_topology)))

        topology = self.get(TOPOLOGY_URL.format(
            context_uuid=DEFAULT_CONTEXT_NAME, topology_uuid=DEFAULT_TOPOLOGY_NAME
            context_uuid=self.context_uuid, topology_uuid=self.topology_uuid
        ))

        result = list()
@@ -211,11 +215,11 @@ class TfsApiClient(RestApiClient):
        service_add = json_service(
            service_uuid,
            ServiceTypeEnum.Name(ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY),
            context_id = json_context_id(DEFAULT_CONTEXT_NAME),
            context_id = json_context_id(self.context_uuid),
            name = service_name,
            status = ServiceStatusEnum.Name(ServiceStatusEnum.SERVICESTATUS_PLANNED),
        )
        services_url = SERVICES_URL.format(context_uuid=DEFAULT_CONTEXT_NAME)
        services_url = SERVICES_URL.format(context_uuid=self.context_uuid)
        service_ids = self.post(services_url, body=service_add)
        assert len(service_ids) == 1
        service_id = service_ids[0]
@@ -224,18 +228,18 @@ class TfsApiClient(RestApiClient):
        service_upd = json_service(
            service_uuid,
            ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY,
            context_id = json_context_id(DEFAULT_CONTEXT_NAME),
            context_id = json_context_id(self.context_uuid),
            name = service_name, endpoint_ids = endpoint_ids, constraints = constraints,
            status = ServiceStatusEnum.Name(ServiceStatusEnum.SERVICESTATUS_PLANNED),
        )
        service_url = SERVICE_URL.format(context_uuid=DEFAULT_CONTEXT_NAME, service_uuid=service_uuid)
        service_url = SERVICE_URL.format(context_uuid=self.context_uuid, service_uuid=service_uuid)
        self.put(service_url, body=service_upd)

    def teardown_service(self, resource_value : Dict) -> None:
        service_uuid = resource_value['service_uuid']
        service_name = resource_value['service_name']

        service_url = SERVICE_URL.format(context_uuid=DEFAULT_CONTEXT_NAME, service_uuid=service_uuid)
        service_url = SERVICE_URL.format(context_uuid=self.context_uuid, service_uuid=service_uuid)
        self.delete(service_url)
        if service_name == 'IP1/PORT-xe1==IP2/PORT-xe1':
            self.delete(service_url)
@@ -269,7 +273,7 @@ class TfsApiClient(RestApiClient):
        return resource_key, parsed_service

    def get_services(self) -> List[Tuple[str, Dict]]:
        services_url = SERVICES_URL.format(context_uuid=DEFAULT_CONTEXT_NAME)
        services_url = SERVICES_URL.format(context_uuid=self.context_uuid)
        _services = self.get(services_url)
        OPTICAL_CONNECTIVITY_SERVICE_TYPES = {
            'SERVICETYPE_OPTICAL_CONNECTIVITY',
@@ -282,6 +286,6 @@ class TfsApiClient(RestApiClient):
        ]

    def get_service(self, service_uuid : str) -> Tuple[str, Dict]:
        service_url = SERVICE_URL.format(context_uuid=DEFAULT_CONTEXT_NAME, service_uuid=service_uuid)
        service_url = SERVICE_URL.format(context_uuid=self.context_uuid, service_uuid=service_uuid)
        service = self.get(service_url)
        return TfsApiClient.parse_service(service)