X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fapi%2Fsonata%2F__init__.py;h=14182c59de22744a1f0eb20fabd034e1c1f0e6db;hb=26455858b9ed9f84c2fc87a2df83ac13bbed1d09;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=53337bc9b5cd5b6c613453b04c4f9cd703a61344;p=osm%2Fvim-emu.git diff --git a/src/emuvim/api/sonata/__init__.py b/src/emuvim/api/sonata/__init__.py index e69de29..14182c5 100644 --- a/src/emuvim/api/sonata/__init__.py +++ b/src/emuvim/api/sonata/__init__.py @@ -0,0 +1,43 @@ +""" +This module implements a simple REST API that behaves like SONATA's gatekeeper. + +It is only used to support the development of SONATA's SDK tools and to demonstrate +the year 1 version of the emulator until the integration with WP4's orchestrator is done. +""" + +import logging +import threading +import dummygatekeeper as dgk + + +class SonataDummyGatekeeperEndpoint(object): + """ + Creates and starts a REST API based on Flask in an + additional thread. + + Can connect this API to data centers defined in an emulator + topology. + """ + + def __init__(self, listenip, port): + self.dcs = {} + self.ip = listenip + self.port = port + logging.debug("Created API endpoint %s" % self) + + def __repr__(self): + return "%s(%s:%d)" % (self.__class__.__name__, self.ip, self.port) + + def connectDatacenter(self, dc): + self.dcs[dc.label] = dc + logging.info("Connected DC(%s) to API endpoint %s" % ( + dc, self)) + + def start(self): + thread = threading.Thread(target=self._api_server_thread, args=()) + thread.daemon = True + thread.start() + logging.debug("Started API endpoint %s" % self) + + def _api_server_thread(self): + dgk.start_rest_api(self.ip, self.port)