Skip to content
Snippets Groups Projects
Commit 948e9589 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent a392d2e0
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!225Resolve "Integrate Support for IP-E2E-Optical SDN controllers to manage hierarchical virtual topologies"
......@@ -52,6 +52,8 @@ include:
- local: '/src/telemetry/.gitlab-ci.yml'
- local: '/src/analytics/.gitlab-ci.yml'
- local: '/src/qos_profile/.gitlab-ci.yml'
- local: '/src/vnt_manager/.gitlab-ci.yml'
- local: '/src/e2e_orchestrator/.gitlab-ci.yml'
# This should be last one: end-to-end integration tests
- local: '/src/tests/.gitlab-ci.yml'
......@@ -16,8 +16,10 @@ import logging, signal, sys, threading
from prometheus_client import start_http_server
from common.Constants import ServiceNameEnum
from common.Settings import (
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, get_log_level, get_metrics_port,
wait_for_environment_variables)
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC,
get_env_var_name, get_log_level, get_metrics_port,
wait_for_environment_variables
)
from .DeviceService import DeviceService
from .driver_api.DriverFactory import DriverFactory
from .driver_api.DriverInstanceCache import DriverInstanceCache, preload_drivers
......
......@@ -81,8 +81,7 @@ COPY src/context/__init__.py context/__init__.py
COPY src/context/client/. context/client/
COPY src/device/__init__.py device/__init__.py
COPY src/device/client/. device/client/
COPY src/vnt_manager/__init__.py vnt_manager/__init__.py
COPY src/vnt_manager/client/. vnt_manager/client/
COPY src/vnt_manager/. vnt_manager/
# Start the service
ENTRYPOINT ["python", "-m", "vnt_manager.service"]
......@@ -12,5 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
networkx
websockets==12.0
......@@ -12,37 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import networkx as nx
import grpc
import json
import logging
import threading
import time
from websockets.sync.client import connect
from common.method_wrappers.Decorator import (MetricsPool, MetricTypeEnum, safe_and_metered_rpc_method)
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import ContextId, Empty, Link, LinkId, LinkList, TopologyId
from common.proto.vnt_manager_pb2 import VNTSubscriptionRequest, VNTSubscriptionReply
from common.proto.vnt_manager_pb2_grpc import VNTManagerServiceServicer
from context.client.ContextClient import ContextClient
from common.proto.context_pb2 import (
Empty,
Event, EventTypeEnum,
Link, LinkEvent, LinkId, LinkIdList, LinkList,
)
from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology_id
from common.proto.context_pb2 import ContextId, TopologyId
import threading
from common.proto.context_pb2 import (
ConnectionEvent, ContextEvent, DeviceEvent, EventTypeEnum, ServiceEvent, TopologyEvent)
from context.client.ContextClient import ContextClient
from context.client.EventsCollector import EventsCollector
from common.tests.EventTools import EVENT_CREATE, EVENT_UPDATE, check_events
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME
from typing import Any, Dict, Set
from common.proto.dlt_gateway_pb2 import DltRecordEvent, DltRecordOperationEnum, DltRecordTypeEnum
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.grpc.Tools import grpc_message_to_json
from .vntm_config_device import configure, deconfigure
import json
LOGGER = logging.getLogger(__name__)
......@@ -140,7 +126,6 @@ class VNTManagerServiceServicerImpl(VNTManagerServiceServicer):
LOGGER.debug("Servicer Created")
self.links = []
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def VNTSubscript(self, request: VNTSubscriptionRequest, context: grpc.ServicerContext) -> VNTSubscriptionReply:
LOGGER.info("Subscript request: {:s}".format(str(grpc_message_to_json(request))))
......@@ -148,14 +133,11 @@ class VNTManagerServiceServicerImpl(VNTManagerServiceServicer):
reply.subscription = "OK"
self.event_dispatcher = VNTMEventDispatcher(request.host, int(request.port))
self.host = request.host
self.port = request.port
self.event_dispatcher.start()
return reply
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def ListVirtualLinks(self, request : Empty, context : grpc.ServicerContext) -> LinkList:
return [link for link in context_client.ListLinks(Empty()).links if link.virtual]
......@@ -165,13 +147,12 @@ class VNTManagerServiceServicerImpl(VNTManagerServiceServicer):
link = context_client.GetLink(request)
return link if link.virtual else Empty()
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def SetVirtualLink(self, request : Link, context : grpc.ServicerContext) -> LinkId:
try:
LOGGER.info('SETTING virtual link')
self.event_dispatcher.send_msg(grpc_message_to_json_string(request))
# configure('CSGW1', 'xe5', 'CSGW2', 'xe5', 'ecoc2024-1')
# configure('CSGW1', 'xe5', 'CSGW2', 'xe5', 'ecoc2024-1')
response = self.event_dispatcher.recv_msg()
message_json = json.loads(response)
link = Link(**message_json)
......@@ -200,4 +181,3 @@ class VNTManagerServiceServicerImpl(VNTManagerServiceServicer):
LOGGER.info('Removed')
return Empty()
......@@ -12,43 +12,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import signal
import sys
import threading
import logging, signal, sys, threading
from prometheus_client import start_http_server
from common.Constants import ServiceNameEnum
from common.Settings import (ENVVAR_SUFIX_SERVICE_HOST,
ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name,
get_log_level, get_metrics_port,
wait_for_environment_variables)
from common.Settings import (
ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC,
get_env_var_name, get_log_level, get_metrics_port,
wait_for_environment_variables
)
from .VNTManagerService import VNTManagerService
terminate = threading.Event()
LOGGER = None
LOG_LEVEL = get_log_level()
logging.basicConfig(level=LOG_LEVEL, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s")
LOGGER = logging.getLogger(__name__)
terminate = threading.Event()
def signal_handler(signal, frame): # pylint: disable=redefined-outer-name
def signal_handler(signal, frame): # pylint: disable=redefined-outer-name,unused-argument
LOGGER.warning("Terminate signal received")
terminate.set()
def main():
global LOGGER # pylint: disable=global-statement
log_level = get_log_level()
logging.basicConfig(level=log_level)
LOGGER = logging.getLogger(__name__)
LOGGER.info("Starting...")
wait_for_environment_variables([
get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_HOST ),
get_env_var_name(ServiceNameEnum.CONTEXT, ENVVAR_SUFIX_SERVICE_PORT_GRPC),
])
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
LOGGER.info("Starting...")
# Start metrics server
metrics_port = get_metrics_port()
start_http_server(metrics_port)
......@@ -56,12 +50,9 @@ def main():
# Starting VNTManager service
grpc_service = VNTManagerService()
grpc_service.start()
LOGGER.info("Started...")
# Wait for Ctrl+C or termination signal
while not terminate.wait(timeout=1):
pass
# Wait for Ctrl+C or termination signal
while not terminate.wait(timeout=1): pass
LOGGER.info("Terminating...")
grpc_service.stop()
......@@ -69,6 +60,5 @@ def main():
LOGGER.info("Bye")
return 0
if __name__ == "__main__":
sys.exit(main())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment