ea3bc545060dc35bbcc1aca0c5f32fe80b104058
[osm/vim-emu.git] / src / emuvim / api / tango / __init__.py
1 # Copyright (c) 2018 SONATA-NFV, 5GTANGO 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, 5GTANGO, 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 #
27 # This work has also been performed in the framework of the 5GTANGO project,
28 # funded by the European Commission under Grant number 761493 through
29 # the Horizon 2020 and 5G-PPP programmes. The authors would like to
30 # acknowledge the contributions of their colleagues of the 5GTANGO
31 # partner consortium (www.5gtango.eu).
32 import logging
33 import threading
34 import llcm
35
36
37 LOG = logging.getLogger("5gtango.llcm")
38
39
40 class TangoLLCMEndpoint(object):
41 """
42 Creates and starts the 5GTANGO lightweight life cycle manager to simply
43 deploy 5GTANGO service packages on the emulator.
44 The code is based on SONATA's dummygatekeeper.
45 """
46
47 def __init__(self, listenip, port, deploy_sap=False, docker_management=False,
48 auto_deploy=False, auto_delete=False, sap_vnfd_path=None):
49 self.dcs = {}
50 self.ip = listenip
51 self.port = port
52 llcm.DEPLOY_SAP = deploy_sap
53 llcm.USE_DOCKER_MGMT = docker_management
54 llcm.AUTO_DEPLOY = auto_deploy
55 llcm.AUTO_DELETE = auto_delete
56 llcm.SAP_VNFD = sap_vnfd_path
57 LOG.info("Created 5GTANGO LLCM API endpoint %s" % self)
58
59 def __repr__(self):
60 return "%s(%s:%d)" % (self.__class__.__name__, self.ip, self.port)
61
62 def connectDatacenter(self, dc):
63 self.dcs[dc.label] = dc
64 LOG.debug("Connected DC(%s) to API endpoint %s" % (
65 dc, self))
66
67 def start(self):
68 thread = threading.Thread(target=self._api_server_thread, args=())
69 thread.daemon = True
70 thread.start()
71 LOG.info("Started API endpoint %s" % self)
72
73 def _api_server_thread(self):
74 llcm.start_rest_api(self.ip, self.port, self.dcs)
75
76 def stop(self):
77 llcm.stop_rest_api()