Added prototpye of SONATA gatekeeper API. Can already accept uploaded packages and...
[osm/vim-emu.git] / src / emuvim / api / sonata / __init__.py
1 """
2 This module implements a simple REST API that behaves like SONATA's gatekeeper.
3
4 It is only used to support the development of SONATA's SDK tools and to demonstrate
5 the year 1 version of the emulator until the integration with WP4's orchestrator is done.
6 """
7
8 import logging
9 import threading
10 import dummygatekeeper as dgk
11
12
13 class SonataDummyGatekeeperEndpoint(object):
14
15 def __init__(self, listenip, port):
16 self.dcs = {}
17 self.ip = listenip
18 self.port = port
19 logging.debug("Created API endpoint %s" % self)
20
21 def __repr__(self):
22 return "%s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)
23
24 def connectDatacenter(self, dc):
25 self.dcs[dc.label] = dc
26 logging.info("Connected DC(%s) to API endpoint %s" % (
27 dc, self))
28
29 def start(self):
30 thread = threading.Thread(target=self._api_server_thread, args=())
31 thread.daemon = True
32 thread.start()
33 logging.debug("Started API endpoint %s" % self)
34
35 def _api_server_thread(self):
36 dgk.start_rest_api(self.ip, self.port)