summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-09-27 14:18:47 -0400
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-09-27 14:18:47 -0400
commit70516be4ff02cd82dce82ac1950fc55e87bab9ec (patch)
tree921fe29e9d73f8a3cf9eb83072d84afb1c31ba86
parentc62160eff79c082b6dc90be39229e9d8f9bf2fb1 (diff)
parent1d83acca365b13319bddbd628725d7b666879091 (diff)
downloadnova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.tar.gz
nova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.tar.xz
nova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.zip
Merge from upstream
-rw-r--r--nova/api/rackspace/base.py24
-rw-r--r--nova/api/rackspace/flavors.py3
-rw-r--r--nova/api/rackspace/images.py3
-rw-r--r--nova/api/rackspace/servers.py81
-rw-r--r--nova/api/rackspace/sharedipgroups.py4
-rw-r--r--nova/tests/api/rackspace/auth.py4
-rw-r--r--nova/tests/api/rackspace/flavors.py15
-rw-r--r--nova/tests/api/rackspace/servers.py42
-rw-r--r--nova/tests/api/rackspace/test_helper.py29
9 files changed, 128 insertions, 77 deletions
diff --git a/nova/api/rackspace/base.py b/nova/api/rackspace/base.py
deleted file mode 100644
index 5e5bd6f54..000000000
--- a/nova/api/rackspace/base.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# 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? """
- pass
diff --git a/nova/api/rackspace/flavors.py b/nova/api/rackspace/flavors.py
index 60b35c939..024011a71 100644
--- a/nova/api/rackspace/flavors.py
+++ b/nova/api/rackspace/flavors.py
@@ -17,9 +17,10 @@
from nova.api.rackspace import base
from nova.compute import instance_types
+from nova import wsgi
from webob import exc
-class Controller(base.Controller):
+class Controller(wsgi.Controller):
"""Flavor controller for the Rackspace API."""
_serialization_metadata = {
diff --git a/nova/api/rackspace/images.py b/nova/api/rackspace/images.py
index 2f3e928b9..9aaec52e2 100644
--- a/nova/api/rackspace/images.py
+++ b/nova/api/rackspace/images.py
@@ -16,11 +16,12 @@
# under the License.
import nova.image.service
+from nova import wsgi
from nova.api.rackspace import base
from nova.api.rackspace import _id_translator
from webob import exc
-class Controller(base.Controller):
+class Controller(wsgi.Controller):
_serialization_metadata = {
'application/xml': {
diff --git a/nova/api/rackspace/servers.py b/nova/api/rackspace/servers.py
index 3de419e6f..7973fa770 100644
--- a/nova/api/rackspace/servers.py
+++ b/nova/api/rackspace/servers.py
@@ -16,46 +16,53 @@
# under the License.
import time
+from nova import wsgi
from nova import db
from nova import flags
from nova import rpc
from nova import utils
from nova import compute
+from nova import flags
from nova.api.rackspace import base
+from nova.api.rackspace import _id_translator
from webob import exc
-from nova import flags
FLAGS = flags.FLAGS
-class Controller(base.Controller):
+class Controller(wsgi.Controller):
+
_serialization_metadata = {
'application/xml': {
"attributes": {
"server": [ "id", "imageId", "name", "flavorId", "hostId",
- "status", "progress", "addresses", "metadata",
- "progress" ]
+ "status", "progress", "progress" ]
}
}
}
- def __init__(self):
- self.instdir = None # TODO(cerberus): compute doesn't exist. compute.InstanceDirectory()
+ def __init__(self, db_driver=None):
+ if not db_driver:
+ db_driver = FLAGS.db_driver
+ self.db = utils.import_object(db_driver)
def index(self, req):
- allowed_keys = [ 'id', 'name']
- return [_entity_inst(inst, allowed_keys) for inst in instdir.all]
+ instance_list = self.db.instance_get_all(None)
+ res = [self._entity_inst(inst)['server'] for inst in instance_list]
+ return self._entity_list(res)
def detail(self, req):
- return [_entity_inst(inst) for inst in instdir.all]
+ res = [self._entity_detail(inst)['server'] for inst in \
+ self.db.instance_get_all(None)]
+ return self._entity_list(res)
def show(self, req, id):
- inst = self.instdir.get(id)
+ inst = self.db.instance_get(None, id)
if inst:
- return _entity_inst(inst)
+ return self._entity_detail(inst)
raise exc.HTTPNotFound()
def delete(self, req, id):
- instance = self.instdir.get(id)
+ instance = self.db.instance_get(None, id)
if not instance:
return exc.HTTPNotFound()
@@ -71,26 +78,34 @@ class Controller(base.Controller):
return _entity_inst(inst)
def update(self, req, id):
- instance = self.instdir.get(instance_id)
+ instance = self.db.instance_get(None, id)
if not instance:
return exc.HTTPNotFound()
instance.update(kwargs['server'])
instance.save()
return exc.HTTPNoContent()
+ def _id_translator(self):
+ service = nova.image.service.ImageService.load()
+ return _id_translator.RackspaceAPIIdTranslator(
+ "image", self.service.__class__.__name__)
+
def _build_server_instance(self, req):
"""Build instance data structure and save it to the data store."""
ltime = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
inst = {}
+
+ image_id = env['server']['imageId']
+ opaque_id = self._id_translator.from_rs_id(image_id)
+
inst['name'] = env['server']['name']
- inst['image_id'] = env['server']['imageId']
+ inst['image_id'] = opaque_id
inst['instance_type'] = env['server']['flavorId']
inst['user_id'] = env['user']['id']
inst['launch_time'] = ltime
inst['mac_address'] = utils.generate_mac()
- # TODO(dietz) Do we need any of these?
inst['project_id'] = env['project']['id']
inst['reservation_id'] = reservation
reservation = utils.generate_uid('r')
@@ -108,25 +123,31 @@ class Controller(base.Controller):
inst.save()
return _entity_inst(inst)
- def _entity_inst(self, inst, allowed_keys=None):
+ def _entity_list(self, entities):
+ return dict(servers=entities)
+
+ def _entity_detail(self, inst):
""" Maps everything to Rackspace-like attributes for return"""
+ inst_dir = {}
+
+ mapped_keys = dict(status='state_description', imageId='image_id',
+ flavorId='instance_type', name='name')
- translated_keys = dict(metadata={}, status=state_description,
- id=instance_id, imageId=image_id, flavorId=instance_type,)
+ for k,v in mapped_keys.iteritems():
+ inst_dir[k] = inst[v]
- for k,v in translated_keys.iteritems():
- inst[k] = inst[v]
+ inst_dir['addresses'] = dict(public=[], private=[])
+ inst_dir['metadata'] = {}
+ inst_dir['hostId'] = ''
- filtered_keys = ['instance_id', 'state_description', 'state',
- 'reservation_id', 'project_id', 'launch_time',
- 'bridge_name', 'mac_address', 'user_id']
+ return dict(server=inst_dir)
- for key in filtered_keys:
- del inst[key]
+ def _entity_inst(self, inst):
+ """ Filters all model attributes save for id and name """
+ return dict(server=dict(id=inst['id'], name=inst['name']))
- if allowed_keys:
- for key in inst.keys():
- if key not in allowed_keys:
- del inst[key]
+ def _to_rs_power_state(self, inst):
+ pass
- return dict(server=inst)
+ def _from_rs_power_state(self, inst):
+ pass
diff --git a/nova/api/rackspace/sharedipgroups.py b/nova/api/rackspace/sharedipgroups.py
index 986f11434..4d2d0ede1 100644
--- a/nova/api/rackspace/sharedipgroups.py
+++ b/nova/api/rackspace/sharedipgroups.py
@@ -15,4 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
-class Controller(object): pass
+from nova import wsgi
+
+class Controller(wsgi.Controller): pass
diff --git a/nova/tests/api/rackspace/auth.py b/nova/tests/api/rackspace/auth.py
index 429c22ad2..a6e10970f 100644
--- a/nova/tests/api/rackspace/auth.py
+++ b/nova/tests/api/rackspace/auth.py
@@ -15,8 +15,8 @@ class Test(unittest.TestCase):
'__init__', test_helper.fake_auth_init)
test_helper.FakeAuthManager.auth_data = {}
test_helper.FakeAuthDatabase.data = {}
- self.stubs.Set(nova.api.rackspace, 'RateLimitingMiddleware',
- test_helper.FakeRateLimiter)
+ test_helper.stub_out_rate_limiting(self.stubs)
+ test_helper.stub_for_testing(self.stubs)
def tearDown(self):
self.stubs.UnsetAll()
diff --git a/nova/tests/api/rackspace/flavors.py b/nova/tests/api/rackspace/flavors.py
index fb8ba94a5..7bd1ea1c4 100644
--- a/nova/tests/api/rackspace/flavors.py
+++ b/nova/tests/api/rackspace/flavors.py
@@ -16,19 +16,32 @@
# under the License.
import unittest
+import stubout
+import nova.api
from nova.api.rackspace import flavors
+from nova.tests.api.rackspace import test_helper
from nova.tests.api.test_helper import *
class FlavorsTest(unittest.TestCase):
def setUp(self):
self.stubs = stubout.StubOutForTesting()
+ test_helper.FakeAuthManager.auth_data = {}
+ test_helper.FakeAuthDatabase.data = {}
+ test_helper.stub_for_testing(self.stubs)
+ test_helper.stub_out_rate_limiting(self.stubs)
+ test_helper.stub_out_auth(self.stubs)
def tearDown(self):
self.stubs.UnsetAll()
def test_get_flavor_list(self):
- pass
+ req = webob.Request.blank('/v1.0/flavors')
+ res = req.get_response(nova.api.API())
+ print res
def test_get_flavor_by_id(self):
pass
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/nova/tests/api/rackspace/servers.py b/nova/tests/api/rackspace/servers.py
index 2cfb8d45f..0f3483207 100644
--- a/nova/tests/api/rackspace/servers.py
+++ b/nova/tests/api/rackspace/servers.py
@@ -17,36 +17,60 @@
import unittest
import stubout
-from nova.api.rackspace import servers
import nova.api.rackspace
+import nova.db.api
+from nova import flags
+from nova.api.rackspace import servers
+from nova.db.sqlalchemy.models import Instance
from nova.tests.api.test_helper import *
from nova.tests.api.rackspace import test_helper
+from nova import db
+
+FLAGS = flags.FLAGS
+
+def return_server(context, id):
+ return stub_instance(id)
+
+def return_servers(context):
+ return [stub_instance(i) for i in xrange(5)]
+
+def stub_instance(id):
+ return Instance(id=id, state=0, )
class ServersTest(unittest.TestCase):
def setUp(self):
self.stubs = stubout.StubOutForTesting()
test_helper.FakeAuthManager.auth_data = {}
test_helper.FakeAuthDatabase.data = {}
+ test_helper.stub_for_testing(self.stubs)
+ test_helper.stub_out_rate_limiting(self.stubs)
test_helper.stub_out_auth(self.stubs)
+ self.stubs.Set(nova.db.api, 'instance_get_all', return_servers)
+ self.stubs.Set(nova.db.api, 'instance_get', return_server)
def tearDown(self):
self.stubs.UnsetAll()
- def test_get_server_list(self):
- req = webob.Request.blank('/v1.0/servers')
- req.get_response(nova.api.API())
+ def test_get_server_by_id(self):
+ req = webob.Request.blank('/v1.0/servers/1')
+ res = req.get_response(nova.api.API())
+ print res
- def test_create_instance(self):
+ def test_get_backup_schedule(self):
pass
- def test_get_server_by_id(self):
- pass
+ def test_get_server_list(self):
+ req = webob.Request.blank('/v1.0/servers')
+ res = req.get_response(nova.api.API())
+ print res
- def test_get_backup_schedule(self):
+ def test_create_instance(self):
pass
def test_get_server_details(self):
- pass
+ req = webob.Request.blank('/v1.0/servers/detail')
+ res = req.get_response(nova.api.API())
+ print res
def test_get_server_ips(self):
pass
diff --git a/nova/tests/api/rackspace/test_helper.py b/nova/tests/api/rackspace/test_helper.py
index 1fb2a19cc..971eaf20a 100644
--- a/nova/tests/api/rackspace/test_helper.py
+++ b/nova/tests/api/rackspace/test_helper.py
@@ -1,9 +1,13 @@
+from nova import utils
import webob
import webob.dec
import datetime
from nova.wsgi import Router
from nova import auth
import nova.api.rackspace.auth
+from nova import flags
+
+FLAGS = flags.FLAGS
class Context(object):
pass
@@ -25,27 +29,36 @@ def fake_auth_init(self):
self.auth = FakeAuthManager()
self.host = 'foo'
+@webob.dec.wsgify
+def fake_wsgi(self, req):
+ return self.application
+
def stub_out_auth(stubs):
def fake_auth_init(self, app):
self.application = app
+
+ stubs.Set(nova.api.rackspace.AuthMiddleware,
+ '__init__', fake_auth_init)
+ stubs.Set(nova.api.rackspace.AuthMiddleware,
+ '__call__', fake_wsgi)
+def stub_out_rate_limiting(stubs):
def fake_rate_init(self, app):
super(nova.api.rackspace.RateLimitingMiddleware, self).__init__(app)
self.application = app
- @webob.dec.wsgify
- def fake_wsgi(self, req):
- return self.application
-
- stubs.Set(nova.api.rackspace.AuthMiddleware,
- '__init__', fake_auth_init)
stubs.Set(nova.api.rackspace.RateLimitingMiddleware,
'__init__', fake_rate_init)
- stubs.Set(nova.api.rackspace.AuthMiddleware,
- '__call__', fake_wsgi)
+
stubs.Set(nova.api.rackspace.RateLimitingMiddleware,
'__call__', fake_wsgi)
+def stub_for_testing(stubs):
+ def get_my_ip():
+ return '127.0.0.1'
+ stubs.Set(nova.utils, 'get_my_ip', get_my_ip)
+ FLAGS.FAKE_subdomain = 'rs'
+
class FakeAuthDatabase(object):
data = {}