summaryrefslogtreecommitdiffstats
path: root/nova/api
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 /nova/api
parentc62160eff79c082b6dc90be39229e9d8f9bf2fb1 (diff)
parent1d83acca365b13319bddbd628725d7b666879091 (diff)
downloadnova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.tar.gz
nova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.tar.xz
nova-70516be4ff02cd82dce82ac1950fc55e87bab9ec.zip
Merge from upstream
Diffstat (limited to 'nova/api')
-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
5 files changed, 58 insertions, 57 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