Fixed missing license headers
[osm/vim-emu.git] / src / emuvim / api / sonata / __init__.py
1 """
2 Copyright (c) 2015 SONATA-NFV and Paderborn University
3 ALL RIGHTS RESERVED.
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 Neither the name of the SONATA-NFV, Paderborn University
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
20 permission.
21
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
27 """
28 """
29 This module implements a simple REST API that behaves like SONATA's gatekeeper.
30
31 It is only used to support the development of SONATA's SDK tools and to demonstrate
32 the year 1 version of the emulator until the integration with WP4's orchestrator is done.
33 """
34
35 import logging
36 import threading
37 import dummygatekeeper as dgk
38
39
40 class SonataDummyGatekeeperEndpoint(object):
41 """
42 Creates and starts a REST API based on Flask in an
43 additional thread.
44
45 Can connect this API to data centers defined in an emulator
46 topology.
47 """
48
49 def __init__(self, listenip, port, deploy_sap=False, docker_management=False,
50 auto_deploy=False, auto_delete=False, sap_vnfd_path=None):
51 self.dcs = {}
52 self.ip = listenip
53 self.port = port
54 dgk.DEPLOY_SAP = deploy_sap
55 dgk.USE_DOCKER_MGMT = docker_management
56 dgk.AUTO_DEPLOY = auto_deploy
57 dgk.AUTO_DELETE = auto_delete
58 dgk.SAP_VNFD = sap_vnfd_path
59 logging.debug("Created API endpoint %s" % self)
60
61 def __repr__(self):
62 return "%s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)
63
64 def connectDatacenter(self, dc):
65 self.dcs[dc.label] = dc
66 logging.info("Connected DC(%s) to API endpoint %s" % (
67 dc, self))
68
69 def start(self):
70 thread = threading.Thread(target=self._api_server_thread, args=())
71 thread.daemon = True
72 thread.start()
73 logging.debug("Started API endpoint %s" % self)
74
75 def _api_server_thread(self):
76 dgk.start_rest_api(self.ip, self.port, self.dcs)