merge master and fix SDN chaining unit test
[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 Creates and starts a REST API based on Flask in an
16 additional thread.
17
18 Can connect this API to data centers defined in an emulator
19 topology.
20 """
21
22 def __init__(self, listenip, port):
23 self.dcs = {}
24 self.ip = listenip
25 self.port = port
26 logging.debug("Created API endpoint %s" % self)
27
28 def __repr__(self):
29 return "%s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)
30
31 def connectDatacenter(self, dc):
32 self.dcs[dc.label] = dc
33 logging.info("Connected DC(%s) to API endpoint %s" % (
34 dc, self))
35
36 def start(self):
37 thread = threading.Thread(target=self._api_server_thread, args=())
38 thread.daemon = True
39 thread.start()
40 logging.debug("Started API endpoint %s" % self)
41
42 def _api_server_thread(self):
43 dgk.start_rest_api(self.ip, self.port, self.dcs)