Merge "Spec for elastic API exposure"
[multicloud/framework.git] / multivimbroker / multivimbroker / api_v2 / service.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #       http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from oslo_concurrency import processutils
14 from oslo_config import cfg
15 from oslo_service import service
16 from oslo_service import wsgi
17
18 from multivimbroker.api_v2 import app
19
20
21 CONF = cfg.CONF
22
23
24 class WSGIService(service.ServiceBase):
25     """Provides ability to launch API from wsgi app."""
26
27     def __init__(self):
28         self.app = app.setup_app()
29
30         self.workers = processutils.get_worker_count()
31
32         self.server = wsgi.Server(
33             CONF,
34             "multivimbroker",
35             self.app,
36             # TODO(xiaohhui): these should be configurable.
37             host="0.0.0.0",
38             port="9002",
39             use_ssl=False
40         )
41
42     def start(self):
43         self.server.start()
44
45     def stop(self):
46         self.server.stop()
47
48     def wait(self):
49         self.server.wait()
50
51     def reset(self):
52         self.server.reset()