e340a3ae907fc9e8aa90aa8815d48fe8df823607
2 Copyright (c) 2017 SONATA-NFV and Paderborn University
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
9 http://www.apache.org/licenses/LICENSE-2.0
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.
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
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).
28 from manage
import OpenstackManage
29 from openstack_dummies
import *
38 class OpenstackApiEndpoint():
40 Base class for an OpenStack datacenter.
41 It holds information about all connected endpoints.
45 def __init__(self
, listenip
, port
):
48 self
.compute
= compute
.OpenstackCompute()
49 self
.openstack_endpoints
= dict()
50 self
.openstack_endpoints
['keystone'] = KeystoneDummyApi(self
.ip
, self
.port
)
51 self
.openstack_endpoints
['neutron'] = NeutronDummyApi(self
.ip
, self
.port
+ 4696, self
.compute
)
52 self
.openstack_endpoints
['nova'] = NovaDummyApi(self
.ip
, self
.port
+ 3774, self
.compute
)
53 self
.openstack_endpoints
['heat'] = HeatDummyApi(self
.ip
, self
.port
+ 3004, self
.compute
)
54 self
.openstack_endpoints
['glance'] = GlanceDummyApi(self
.ip
, self
.port
+ 4242, self
.compute
)
56 self
.rest_threads
= list()
57 self
.manage
= OpenstackManage()
58 self
.manage
.add_endpoint(self
)
59 OpenstackApiEndpoint
.dc_apis
.append(self
)
61 def connect_datacenter(self
, dc
):
63 Connect a datacenter to this endpoint.
64 An endpoint can only be connected to a single datacenter.
66 :param dc: Datacenter object
70 for ep
in self
.openstack_endpoints
.values():
71 ep
.manage
= self
.manage
73 ("Connected DC(%s) to API endpoint %s(%s:%d)" % (dc
.label
, self
.__class
__.__name
__, self
.ip
, self
.port
))
75 def connect_dc_network(self
, dc_network
):
77 Connect the datacenter network to the endpoint.
79 :param dc_network: Datacenter network reference
80 :type dc_network: :class:`.net`
82 self
.manage
.net
= dc_network
83 self
.compute
.nets
[self
.manage
.floating_network
.id] = self
.manage
.floating_network
84 logging
.info("Connected DCNetwork to API endpoint %s(%s:%d)" % (
85 self
.__class
__.__name
__, self
.ip
, self
.port
))
87 def start(self
, wait_for_port
=False):
89 Start all connected OpenStack endpoints that are connected to this API endpoint.
91 for c
in self
.openstack_endpoints
.values():
92 c
.compute
= self
.compute
93 c
.manage
= self
.manage
94 c
.server_thread
= threading
.Thread(target
=c
._start
_flask
, args
=())
95 c
.server_thread
.daemon
= True
96 c
.server_thread
.name
= c
.__class
__.__name
__
97 c
.server_thread
.start()
99 self
._wait
_for
_port
(c
.ip
, c
.port
)
103 Stop all connected OpenStack endpoints that are connected to this API endpoint.
105 for c
in self
.openstack_endpoints
.values():
107 #for c in self.openstack_endpoints.values():
108 # if c.server_thread:
109 # print("Waiting for WSGIServers to be stopped ...")
110 # c.server_thread.join()
112 def _wait_for_port(self
, ip
, port
):
113 for i
in range(0, 10):
114 s
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
115 s
.settimeout(1) # 1 Second Timeout
116 r
= s
.connect_ex((ip
, port
))
118 break # port is open proceed
120 logging
.warning("Waiting for {}:{} ... ({}/10)".format(ip
, port
, i
+ 1))