In an effort to keep new and old API code separate, I've created a nova.api to put all new API code under. This means nova.endpoint only contains the old Tornado implementation. I also cleaned up a few pep8 and other style nits in the new API code.
This commit is contained in:
@@ -18,17 +18,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
"""
|
||||
Daemon for the Rackspace API endpoint.
|
||||
Nova API daemon.
|
||||
"""
|
||||
|
||||
from nova import api
|
||||
from nova import flags
|
||||
from nova import utils
|
||||
from nova import wsgi
|
||||
from nova.endpoint import newapi
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_integer('cc_port', 8773, 'cloud controller port')
|
||||
flags.DEFINE_integer('api_port', 8773, 'API port')
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.default_flagfile()
|
||||
wsgi.run_server(newapi.APIVersionRouter(), FLAGS.cc_port)
|
||||
wsgi.run_server(api.API(), FLAGS.api_port)
|
||||
@@ -1,22 +0,0 @@
|
||||
import routes
|
||||
import webob.dec
|
||||
|
||||
from nova import wsgi
|
||||
|
||||
# TODO(gundlach): temp
|
||||
class API(wsgi.Router):
|
||||
"""WSGI entry point for all AWS API requests."""
|
||||
|
||||
def __init__(self):
|
||||
mapper = routes.Mapper()
|
||||
|
||||
mapper.connect(None, "{all:.*}", controller=self.dummy)
|
||||
|
||||
super(API, self).__init__(mapper)
|
||||
|
||||
@webob.dec.wsgify
|
||||
def dummy(self, req):
|
||||
#TODO(gundlach)
|
||||
msg = "dummy response -- please hook up __init__() to cloud.py instead"
|
||||
return repr({ 'dummy': msg,
|
||||
'kwargs': repr(req.environ['wsgiorg.routing_args'][1]) })
|
||||
@@ -1,51 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
:mod:`nova.endpoint` -- Main NOVA Api endpoints
|
||||
=====================================================
|
||||
|
||||
.. automodule:: nova.endpoint
|
||||
:platform: Unix
|
||||
:synopsis: REST APIs for all nova functions
|
||||
.. moduleauthor:: Jesse Andrews <jesse@ansolabs.com>
|
||||
.. moduleauthor:: Devin Carlen <devin.carlen@gmail.com>
|
||||
.. moduleauthor:: Vishvananda Ishaya <vishvananda@yahoo.com>
|
||||
.. moduleauthor:: Joshua McKenty <joshua@cognition.ca>
|
||||
.. moduleauthor:: Manish Singh <yosh@gimp.org>
|
||||
.. moduleauthor:: Andy Smith <andy@anarkystic.com>
|
||||
"""
|
||||
|
||||
from nova import wsgi
|
||||
import routes
|
||||
from nova.endpoint import rackspace
|
||||
from nova.endpoint import aws
|
||||
|
||||
class APIVersionRouter(wsgi.Router):
|
||||
"""Routes top-level requests to the appropriate API."""
|
||||
|
||||
def __init__(self):
|
||||
mapper = routes.Mapper()
|
||||
|
||||
rsapi = rackspace.API()
|
||||
mapper.connect(None, "/v1.0/{path_info:.*}", controller=rsapi)
|
||||
|
||||
mapper.connect(None, "/ec2/{path_info:.*}", controller=aws.API())
|
||||
|
||||
super(APIVersionRouter, self).__init__(mapper)
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2010 United States Government as represented by the
|
||||
# Administrator of the National Aeronautics and Space Administration.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Rackspace API Endpoint
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
import routes
|
||||
|
||||
from nova import flags
|
||||
from nova import wsgi
|
||||
from nova.auth import manager
|
||||
from nova.endpoint.rackspace import controllers
|
||||
|
||||
|
||||
class API(wsgi.Middleware):
|
||||
"""WSGI entry point for all Rackspace API requests."""
|
||||
|
||||
def __init__(self):
|
||||
app = AuthMiddleware(APIRouter())
|
||||
super(API, self).__init__(app)
|
||||
|
||||
|
||||
class AuthMiddleware(wsgi.Middleware):
|
||||
"""Authorize the rackspace API request or return an HTTP Forbidden."""
|
||||
|
||||
#TODO(gundlach): isn't this the old Nova API's auth? Should it be replaced
|
||||
#with correct RS API auth?
|
||||
|
||||
@webob.dec.wsgify
|
||||
def __call__(self, req):
|
||||
context = {}
|
||||
if "HTTP_X_AUTH_TOKEN" in req.environ:
|
||||
context['user'] = manager.AuthManager().get_user_from_access_key(
|
||||
req.environ['HTTP_X_AUTH_TOKEN'])
|
||||
if context['user']:
|
||||
context['project'] = manager.AuthManager().get_project(
|
||||
context['user'].name)
|
||||
if "user" not in context:
|
||||
return webob.exc.HTTPForbidden()
|
||||
req.environ['nova.context'] = context
|
||||
return self.application
|
||||
|
||||
|
||||
class APIRouter(wsgi.Router):
|
||||
"""
|
||||
Routes requests on the Rackspace API to the appropriate controller
|
||||
and method.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
mapper = routes.Mapper()
|
||||
|
||||
mapper.resource("server", "servers",
|
||||
controller=controllers.ServersController())
|
||||
mapper.resource("image", "images",
|
||||
controller=controllers.ImagesController())
|
||||
mapper.resource("flavor", "flavors",
|
||||
controller=controllers.FlavorsController())
|
||||
mapper.resource("sharedipgroup", "sharedipgroups",
|
||||
controller=controllers.SharedIpGroupsController())
|
||||
|
||||
super(APIRouter, self).__init__(mapper)
|
||||
@@ -1,5 +0,0 @@
|
||||
from nova.endpoint.rackspace.controllers.images import ImagesController
|
||||
from nova.endpoint.rackspace.controllers.flavors import FlavorsController
|
||||
from nova.endpoint.rackspace.controllers.servers import ServersController
|
||||
from nova.endpoint.rackspace.controllers.sharedipgroups import \
|
||||
SharedIpGroupsController
|
||||
@@ -1,9 +0,0 @@
|
||||
from nova import wsgi
|
||||
|
||||
class BaseController(wsgi.Controller):
|
||||
@classmethod
|
||||
def render(cls, instance):
|
||||
if isinstance(instance, list):
|
||||
return { cls.entity_name : cls.render(instance) }
|
||||
else:
|
||||
return { "TODO": "TODO" }
|
||||
@@ -1 +0,0 @@
|
||||
class FlavorsController(object): pass
|
||||
@@ -1 +0,0 @@
|
||||
class ImagesController(object): pass
|
||||
@@ -1,63 +0,0 @@
|
||||
from nova import rpc
|
||||
from nova.compute import model as compute
|
||||
from nova.endpoint.rackspace.controllers.base import BaseController
|
||||
|
||||
class ServersController(BaseController):
|
||||
entity_name = 'servers'
|
||||
|
||||
def index(self, **kwargs):
|
||||
return [instance_details(inst) for inst in compute.InstanceDirectory().all]
|
||||
|
||||
def show(self, **kwargs):
|
||||
instance_id = kwargs['id']
|
||||
return compute.InstanceDirectory().get(instance_id)
|
||||
|
||||
def delete(self, **kwargs):
|
||||
instance_id = kwargs['id']
|
||||
instance = compute.InstanceDirectory().get(instance_id)
|
||||
if not instance:
|
||||
raise ServerNotFound("The requested server was not found")
|
||||
instance.destroy()
|
||||
return True
|
||||
|
||||
def create(self, **kwargs):
|
||||
inst = self.build_server_instance(kwargs['server'])
|
||||
rpc.cast(
|
||||
FLAGS.compute_topic, {
|
||||
"method": "run_instance",
|
||||
"args": {"instance_id": inst.instance_id}})
|
||||
|
||||
def update(self, **kwargs):
|
||||
instance_id = kwargs['id']
|
||||
instance = compute.InstanceDirectory().get(instance_id)
|
||||
if not instance:
|
||||
raise ServerNotFound("The requested server was not found")
|
||||
instance.update(kwargs['server'])
|
||||
instance.save()
|
||||
|
||||
def build_server_instance(self, env):
|
||||
"""Build instance data structure and save it to the data store."""
|
||||
reservation = utils.generate_uid('r')
|
||||
ltime = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
|
||||
inst = self.instdir.new()
|
||||
inst['name'] = env['server']['name']
|
||||
inst['image_id'] = env['server']['imageId']
|
||||
inst['instance_type'] = env['server']['flavorId']
|
||||
inst['user_id'] = env['user']['id']
|
||||
inst['project_id'] = env['project']['id']
|
||||
inst['reservation_id'] = reservation
|
||||
inst['launch_time'] = ltime
|
||||
inst['mac_address'] = utils.generate_mac()
|
||||
address = self.network.allocate_ip(
|
||||
inst['user_id'],
|
||||
inst['project_id'],
|
||||
mac=inst['mac_address'])
|
||||
inst['private_dns_name'] = str(address)
|
||||
inst['bridge_name'] = network.BridgedNetwork.get_network_for_project(
|
||||
inst['user_id'],
|
||||
inst['project_id'],
|
||||
'default')['bridge_name']
|
||||
# key_data, key_name, ami_launch_index
|
||||
# TODO(todd): key data or root password
|
||||
inst.save()
|
||||
return inst
|
||||
@@ -1 +0,0 @@
|
||||
class SharedIpGroupsController(object): pass
|
||||
Reference in New Issue
Block a user