This website requires JavaScript.
c64c7691127702131959e57f830c1cd977954e24
nova /bin /nova-direct-api
105 lines
3.6 KiB
Plaintext
2010年12月27日 15:15:24 -08:00
#!/usr/bin/env python
2011年03月18日 09:56:05 -04:00
# pylint: disable=C0103
2010年12月27日 15:15:24 -08:00
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2011年01月04日 14:39:48 -08:00
"""Starter script for Nova Direct API."""
2010年12月27日 15:15:24 -08:00
2011年08月18日 10:55:39 -07:00
import eventlet
2010年12月27日 15:15:24 -08:00
import os
# If ../nova/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
sys.path.insert(0, possible_topdir)
2011年03月24日 12:42:46 -07:00
from nova import compute
2010年12月27日 15:15:24 -08:00
from nova import flags
2011年02月21日 13:46:41 -08:00
from nova import log as logging
2011年03月24日 12:42:46 -07:00
from nova import network
2011年08月18日 10:55:39 -07:00
from nova import service
2010年12月27日 15:15:24 -08:00
from nova import utils
2011年03月24日 12:42:46 -07:00
from nova import volume
2010年12月27日 15:15:24 -08:00
from nova import wsgi
2011年01月04日 14:07:46 -08:00
from nova.api import direct
2010年12月27日 15:15:24 -08:00
2011年01月04日 14:07:46 -08:00
flags.DEFINE_integer('direct_port', 8001, 'Direct API port')
flags.DEFINE_string('direct_host', '0.0.0.0', 'Direct API host')
2011年02月23日 15:26:52 -08:00
flags.DEFINE_flag(flags.HelpFlag())
flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
2010年12月27日 15:15:24 -08:00
2011年03月24日 12:42:47 -07:00
# An example of an API that only exposes read-only methods.
2011年03月24日 12:42:47 -07:00
# In this case we're just limiting which methods are exposed.
2011年03月24日 12:42:46 -07:00
class ReadOnlyCompute(direct.Limited):
"""Read-only Compute API."""
_allowed = ['get', 'get_all', 'get_console_output']
2011年03月24日 12:42:47 -07:00
2011年03月24日 12:42:47 -07:00
# An example of an API that provides a backwards compatibility layer.
2011年03月24日 12:42:47 -07:00
# In this case we're overwriting the implementation to ensure
# compatibility with an older version. In reality we would want the
# "description=None" to be part of the actual API so that code
# like this isn't even necessary, but this example shows what one can
# do if that isn't the situation.
2011年03月24日 12:42:47 -07:00
class VolumeVersionOne(direct.Limited):
_allowed = ['create', 'delete', 'update', 'get']
def create(self, context, size, name):
self.proxy.create(context, size, name, description=None)
2011年03月24日 12:42:46 -07:00
2010年12月27日 15:15:24 -08:00
if __name__ == '__main__':
2011年02月21日 13:46:41 -08:00
logging.setup()
2010年12月27日 15:15:24 -08:00
2011年03月24日 12:42:46 -07:00
direct.register_service('compute', compute.API())
direct.register_service('volume', volume.API())
direct.register_service('network', network.API())
2011年01月04日 14:07:46 -08:00
direct.register_service('reflect', direct.Reflection())
2011年03月24日 12:42:47 -07:00
# Here is how we could expose the code in the examples above.
#direct.register_service('compute-readonly',
# ReadOnlyCompute(compute.API()))
#direct.register_service('volume-v1', VolumeVersionOne(volume.API()))
2011年01月04日 14:07:46 -08:00
router = direct.Router()
with_json = direct.JsonParamsMiddleware(router)
with_req = direct.PostParamsMiddleware(with_json)
with_auth = direct.DelegatedAuthMiddleware(with_req)
2010年12月27日 15:15:24 -08:00
2011年06月21日 12:03:27 -04:00
server = wsgi.Server("Direct API",
2011年06月21日 11:25:44 -04:00
host=FLAGS.direct_host,
2011年08月18日 10:55:39 -07:00