From a225fa6acf9ea8689f66b5e415c4680795bac465 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Wed, 26 Oct 2011 14:16:01 -0500 Subject: Too much information is returned from POST /servers Currently we're returning a lot of information in the POST /servers response. This isn't according to spec and is misleading to other projects that might try and implement the OpenStack API specification. The example on docs.openstack.com for the v1.1 API says: "Note that when creating a server only the server ID, its links, and the admin password are guaranteed to be returned in the request. Additional attributes may be retrieved by performing subsequent GETs on the server." We're returning too much right now and this patch addresses that. Further patches should be submitted to refactor the 'view builder' concept as using keyword arguments like this patch does is not ideal and I recognize that. (Patch Set 2) Merged with master + conflict fix (Patch Set 3) Reverted non-nova-standard superclass call Change-Id: If246e51dbf84f1db3d2905694235692ab027859d --- nova/api/openstack/contrib/createserverext.py | 10 ++++++---- nova/api/openstack/servers.py | 8 +++++--- nova/api/openstack/views/servers.py | 10 +++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/createserverext.py b/nova/api/openstack/contrib/createserverext.py index da95164e8..ab5037304 100644 --- a/nova/api/openstack/contrib/createserverext.py +++ b/nova/api/openstack/contrib/createserverext.py @@ -21,10 +21,12 @@ from nova.api.openstack import wsgi class CreateServerController(servers.Controller): - def _build_view(self, req, instance, is_detail=False): - server = super(CreateServerController, self)._build_view(req, - instance, - is_detail) + def _build_view(self, req, instance, is_detail=False, is_create=False): + server = super(CreateServerController, self).\ + _build_view(req, + instance, + is_detail=is_detail, + is_create=is_create) if is_detail: self._build_security_groups(server['server'], instance) return server diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 29160c5ce..8c1eaae9d 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -497,7 +497,7 @@ class Controller(object): instance['instance_type'] = inst_type instance['image_ref'] = image_href - server = self._build_view(req, instance, is_detail=True) + server = self._build_view(req, instance, is_create=True) if '_is_precooked' in server['server']: del server['server']['_is_precooked'] else: @@ -748,7 +748,7 @@ class Controller(object): return common.get_id_from_href(flavor_ref) - def _build_view(self, req, instance, is_detail=False): + def _build_view(self, req, instance, is_detail=False, is_create=False): context = req.environ['nova.context'] project_id = getattr(context, 'project_id', '') base_url = req.application_url @@ -757,7 +757,9 @@ class Controller(object): addresses_builder = views_addresses.ViewBuilder() builder = views_servers.ViewBuilder(context, addresses_builder, flavor_builder, image_builder, base_url, project_id) - return builder.build(instance, is_detail=is_detail) + return builder.build(instance, + is_detail=is_detail, + is_create=is_create) def _build_list(self, req, instances, is_detail=False): params = req.GET.copy() diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 288730efe..4a0be46c1 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -41,13 +41,15 @@ class ViewBuilder(object): self.base_url = base_url self.project_id = project_id - def build(self, inst, is_detail=False): + def build(self, inst, is_detail=False, is_create=False): """Return a dict that represenst a server.""" if inst.get('_is_precooked', False): server = dict(server=inst) else: if is_detail: server = self._build_detail(inst) + elif is_create: + server = self._build_create(inst) else: server = self._build_simple(inst) @@ -59,6 +61,12 @@ class ViewBuilder(object): """Return a simple model of a server.""" return dict(server=dict(id=inst['uuid'], name=inst['display_name'])) + def _build_create(self, inst): + """Return data that should be returned from a server create.""" + server = dict(server=dict(id=inst['uuid'])) + self._build_links(server['server'], inst) + return server + def _build_detail(self, inst): """Returns a detailed model of a server.""" vm_state = inst.get('vm_state', vm_states.BUILDING) -- cgit