Permalink
Browse files

In an effort to keep new and old API code separate, I've created a no…

…va.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.
  • Loading branch information...
1 parent 018ce9a commit 1e403e56dc1147ce3feea1b8931948bc35f23a44 Eric Day committed Aug 17, 2010
@@ -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)
View
@@ -0,0 +1,38 @@
+# 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.
+
+"""
+Root WSGI middleware for all API controllers.
+"""
+
+import routes
+
+from nova import wsgi
+from nova.api import ec2
+from nova.api import rackspace
+
+
+class API(wsgi.Router):
+ """Routes top-level requests to the appropriate controller."""
+
+ def __init__(self):
+ mapper = routes.Mapper()
+ mapper.connect(None, "/v1.0/{path_info:.*}",
+ controller=rackspace.API())
+ mapper.connect(None, "/ec2/{path_info:.*}", controller=ec2.API())
+ super(API, self).__init__(mapper)
View
@@ -0,0 +1,42 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
+"""
+WSGI middleware for EC2 API controllers.
+"""
+
+import routes
+import webob.dec
+
+from nova import wsgi
+
+
+class API(wsgi.Router):
+ """Routes EC2 requests to the appropriate controller."""
+
+ def __init__(self):
+ mapper = routes.Mapper()
+ mapper.connect(None, "{all:.*}", controller=self.dummy)
+ super(API, self).__init__(mapper)
+
+ @staticmethod
+ @webob.dec.wsgify
+ def dummy(req):
+ """Temporary dummy controller."""
+ msg = "dummy response -- please hook up __init__() to cloud.py instead"
+ return repr({'dummy': msg,
+ 'kwargs': repr(req.environ['wsgiorg.routing_args'][1])})
@@ -17,20 +17,23 @@
# under the License.
"""
-Rackspace API Endpoint
+WSGI middleware for Rackspace API controllers.
"""
import json
import time
+import routes
import webob.dec
import webob.exc
-import routes
from nova import flags
from nova import wsgi
+from nova.api.rackspace.controllers import flavors
+from nova.api.rackspace.controllers import images
+from nova.api.rackspace.controllers import servers
+from nova.api.rackspace.controllers import sharedipgroups
from nova.auth import manager
-from nova.endpoint.rackspace import controllers
class API(wsgi.Middleware):
@@ -70,14 +73,9 @@ class APIRouter(wsgi.Router):
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("server", "servers", controller=servers.Controller())
+ mapper.resource("image", "images", controller=images.Controller())
+ mapper.resource("flavor", "flavors", controller=flavors.Controller())
mapper.resource("sharedipgroup", "sharedipgroups",
- controller=controllers.SharedIpGroupsController())
-
+ controller=sharedipgroups.Controller())
super(APIRouter, self).__init__(mapper)
No changes.
@@ -0,0 +1,30 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
+from nova import wsgi
+
+
+class Controller(wsgi.Controller):
+ """TODO(eday): Base controller for all rackspace controllers. What is this
+ for? Is this just Rackspace specific? """
+
+ @classmethod
+ def render(cls, instance):
+ if isinstance(instance, list):
+ return {cls.entity_name: cls.render(instance)}
+ else:
+ return {"TODO": "TODO"}
@@ -0,0 +1,18 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
+class Controller(object): pass
@@ -0,0 +1,18 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
+class Controller(object): pass
@@ -1,12 +1,32 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
from nova import rpc
from nova.compute import model as compute
-from nova.endpoint.rackspace.controllers.base import BaseController
+from nova.api.rackspace.controllers import base
+
-class ServersController(BaseController):
+class Controller(base.Controller):
entity_name = 'servers'
def index(self, **kwargs):
- return [instance_details(inst) for inst in compute.InstanceDirectory().all]
+ instanmces = []
+ for inst in compute.InstanceDirectory().all:
+ instances.append(instance_details(inst))
def show(self, **kwargs):
instance_id = kwargs['id']
@@ -0,0 +1,18 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 OpenStack LLC.
+# 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.
+
+class Controller(object): pass
@@ -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]) })
View
@@ -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,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 +0,0 @@
-class SharedIpGroupsController(object): pass

0 comments on commit 1e403e5

Please sign in to comment.