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