~gandelman-a/ubuntu/precise/nova/UCA_2012.2.1

« back to all changes in this revision

Viewing changes to bin/nova-direct-api

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# pylint: disable=C0103
3
 
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
 
 
5
 
# Copyright 2010 United States Government as represented by the
6
 
# Administrator of the National Aeronautics and Space Administration.
7
 
# All Rights Reserved.
8
 
#
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
12
 
#
13
 
#        http://www.apache.org/licenses/LICENSE-2.0
14
 
#
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.
20
 
 
21
 
"""Starter script for Nova Direct API."""
22
 
 
23
 
import eventlet
24
 
eventlet.monkey_patch()
25
 
 
26
 
import os
27
 
import sys
28
 
 
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]),
32
 
                                   os.pardir,
33
 
                                   os.pardir))
34
 
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
35
 
    sys.path.insert(0, possible_topdir)
36
 
 
37
 
 
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
46
 
from nova import wsgi
47
 
from nova.api import direct
48
 
 
49
 
 
50
 
direct_api_opts = [
51
 
    cfg.IntOpt('direct_port',
52
 
               default=8001,
53
 
               help='Direct API port'),
54
 
    cfg.StrOpt('direct_host',
55
 
               default='0.0.0.0',
56
 
               help='Direct API host'),
57
 
    ]
58
 
 
59
 
FLAGS = flags.FLAGS
60
 
FLAGS.register_cli_opts(direct_api_opts)
61
 
 
62
 
 
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."""
67
 
 
68
 
    _allowed = ['get', 'get_all', 'get_console_output']
69
 
 
70
 
 
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']
79
 
 
80
 
    def create(self, context, size, name):
81
 
        self.proxy.create(context, size, name, description=None)
82
 
 
83
 
 
84
 
if __name__ == '__main__':
85
 
    utils.default_flagfile()
86
 
    FLAGS(sys.argv)
87
 
    logging.setup()
88
 
 
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())
93
 
 
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()))
98
 
 
99
 
    router = direct.Router()
100
 
    with_json = direct.JsonParamsMiddleware(router)
101
 
    with_req = direct.PostParamsMiddleware(with_json)
102
 
    with_auth = direct.DelegatedAuthMiddleware(with_req)
103
 
 
104
 
    server = wsgi.Server("Direct API",
105
 
                         with_auth,
106
 
                         host=FLAGS.direct_host,
107
 
                         port=FLAGS.direct_port)
108
 
 
109
 
    service.serve(server)
110
 
    service.wait()