2
# pylint: disable=C0103
3
# vim: tabstop=4 shiftwidth=4 softtabstop=4
5
# Copyright 2010 United States Government as represented by the
6
# Administrator of the National Aeronautics and Space Administration.
9
# Licensed under the Apache License, Version 2.0 (the "License");
10
# you may not use this file except in compliance with the License.
11
# You may obtain a copy of the License at
13
# http://www.apache.org/licenses/LICENSE-2.0
15
# Unless required by applicable law or agreed to in writing, software
16
# distributed under the License is distributed on an "AS IS" BASIS,
17
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
# See the License for the specific language governing permissions and
19
# limitations under the License.
21
"""Starter script for Nova Direct API."""
24
eventlet.monkey_patch()
29
# If ../nova/__init__.py exists, add ../ to Python search path, so that
30
# it will override what happens to be installed in /usr/(local/)lib/python...
31
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
34
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
35
sys.path.insert(0, possible_topdir)
38
from nova import compute
39
from nova import flags
40
from nova import log as logging
41
from nova import network
42
from nova.openstack.common import cfg
43
from nova import service
44
from nova import utils
45
from nova import volume
47
from nova.api import direct
51
cfg.IntOpt('direct_port',
53
help='Direct API port'),
54
cfg.StrOpt('direct_host',
56
help='Direct API host'),
60
FLAGS.register_cli_opts(direct_api_opts)
63
# An example of an API that only exposes read-only methods.
64
# In this case we're just limiting which methods are exposed.
65
class ReadOnlyCompute(direct.Limited):
66
"""Read-only Compute API."""
68
_allowed = ['get', 'get_all', 'get_console_output']
71
# An example of an API that provides a backwards compatibility layer.
72
# In this case we're overwriting the implementation to ensure
73
# compatibility with an older version. In reality we would want the
74
# "description=None" to be part of the actual API so that code
75
# like this isn't even necessary, but this example shows what one can
76
# do if that isn't the situation.
77
class VolumeVersionOne(direct.Limited):
78
_allowed = ['create', 'delete', 'update', 'get']
80
def create(self, context, size, name):
81
self.proxy.create(context, size, name, description=None)
84
if __name__ == '__main__':
85
utils.default_flagfile()
89
direct.register_service('compute', compute.API())
90
direct.register_service('volume', volume.API())
91
direct.register_service('network', network.API())
92
direct.register_service('reflect', direct.Reflection())
94
# Here is how we could expose the code in the examples above.
95
#direct.register_service('compute-readonly',
96
# ReadOnlyCompute(compute.API()))
97
#direct.register_service('volume-v1', VolumeVersionOne(volume.API()))
99
router = direct.Router()
100
with_json = direct.JsonParamsMiddleware(router)
101
with_req = direct.PostParamsMiddleware(with_json)
102
with_auth = direct.DelegatedAuthMiddleware(with_req)
104
server = wsgi.Server("Direct API",
106
host=FLAGS.direct_host,
107
port=FLAGS.direct_port)
109
service.serve(server)