From 24a6fd40f657896fb20249392be6ed41c30ca679 Mon Sep 17 00:00:00 2001 From: Michael Gundlach Date: Wed, 18 Aug 2010 11:19:40 -0400 Subject: Image API work --- nova/endpoint/newapi.py | 4 --- nova/endpoint/rackspace/controllers/base.py | 9 +++++ nova/endpoint/rackspace/controllers/images.py | 48 ++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/nova/endpoint/newapi.py b/nova/endpoint/newapi.py index 9aae933af..7836be582 100644 --- a/nova/endpoint/newapi.py +++ b/nova/endpoint/newapi.py @@ -41,11 +41,7 @@ class APIVersionRouter(wsgi.Router): 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) - diff --git a/nova/endpoint/rackspace/controllers/base.py b/nova/endpoint/rackspace/controllers/base.py index 8cd44f62e..88922280b 100644 --- a/nova/endpoint/rackspace/controllers/base.py +++ b/nova/endpoint/rackspace/controllers/base.py @@ -7,3 +7,12 @@ class BaseController(wsgi.Controller): return { cls.entity_name : cls.render(instance) } else: return { "TODO": "TODO" } + + def serialize(self, data, request): + """ + Serialize the given dict to the response type requested in request. + Uses self._serialization_metadata if it exists, which is a dict mapping + MIME types to information needed to serialize to that type. + """ + _metadata = getattr(type(self), "_serialization_metadata", {}) + return Serializer(request.environ, _metadata).to_content_type(data) diff --git a/nova/endpoint/rackspace/controllers/images.py b/nova/endpoint/rackspace/controllers/images.py index ae2a08849..197d8375c 100644 --- a/nova/endpoint/rackspace/controllers/images.py +++ b/nova/endpoint/rackspace/controllers/images.py @@ -1 +1,47 @@ -class ImagesController(object): pass +from nova.endpoint.rackspace.controllers.base import BaseController +from nova.endpoint import images +from webob import exc + +#TODO(gundlach): Serialize return values +class ImagesController(BaseController): + + _serialization_metadata = { + 'application/xml': { + "attributes": { + "image": [ "id", "name", "updated", "created", "status", + "serverId", "progress" ] + } + } + } + + def index(self, req): + context = req.environ['nova.api_request_context'] + return images.list(context) + + def show(self, req, id): + context = req.environ['nova.api_request_context'] + return images.list(context, filter_list=[id]) + + def delete(self, req, id): + context = req.environ['nova.api_request_context'] + # TODO(gundlach): make sure it's an image they may delete? + return images.deregister(context, id) + + def create(self, **kwargs): + # TODO(gundlach): no idea how to hook this up. code below + # is from servers.py. + 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): + # TODO (gundlach): no idea how to hook this up. code below + # is from servers.py. + 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() -- cgit