From fa4dbed251f8ec0b0a44407005feaa86539a7823 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 10:21:45 -0500 Subject: remove unused import, make call to network api to get vifs for the instance --- nova/api/openstack/contrib/virtual_interfaces.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/virtual_interfaces.py b/nova/api/openstack/contrib/virtual_interfaces.py index dab61efc8..8c25ba285 100644 --- a/nova/api/openstack/contrib/virtual_interfaces.py +++ b/nova/api/openstack/contrib/virtual_interfaces.py @@ -16,11 +16,11 @@ """The virtual interfaces extension.""" from webob import exc -import webob from nova import compute from nova import exception from nova import log as logging +from nova import network from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import faults @@ -51,6 +51,7 @@ class ServerVirtualInterfaceController(object): def __init__(self): self.compute_api = compute.API() + self.network_api = network.API() super(ServerVirtualInterfaceController, self).__init__() def _items(self, req, server_id, entity_maker): @@ -62,7 +63,8 @@ class ServerVirtualInterfaceController(object): except exception.NotFound: return faults.Fault(exc.HTTPNotFound()) - vifs = instance['virtual_interfaces'] + vifs = self.network_api.get_vifs_by_instance(context, + instance['id']) limited_list = common.limited(vifs, req) res = [entity_maker(context, vif) for vif in limited_list] return {'virtual_interfaces': res} -- cgit From 4f27ce297ac74ac1c11f959cb44eb4bb3cd4b81a Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Wed, 14 Sep 2011 10:29:46 -0500 Subject: no need for the instance at all or compute --- nova/api/openstack/contrib/virtual_interfaces.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/virtual_interfaces.py b/nova/api/openstack/contrib/virtual_interfaces.py index 8c25ba285..1981cd372 100644 --- a/nova/api/openstack/contrib/virtual_interfaces.py +++ b/nova/api/openstack/contrib/virtual_interfaces.py @@ -15,15 +15,10 @@ """The virtual interfaces extension.""" -from webob import exc - -from nova import compute -from nova import exception from nova import log as logging from nova import network from nova.api.openstack import common from nova.api.openstack import extensions -from nova.api.openstack import faults from nova.api.openstack import wsgi @@ -50,7 +45,6 @@ class ServerVirtualInterfaceController(object): """ def __init__(self): - self.compute_api = compute.API() self.network_api = network.API() super(ServerVirtualInterfaceController, self).__init__() @@ -58,13 +52,7 @@ class ServerVirtualInterfaceController(object): """Returns a list of VIFs, transformed through entity_maker.""" context = req.environ['nova.context'] - try: - instance = self.compute_api.get(context, server_id) - except exception.NotFound: - return faults.Fault(exc.HTTPNotFound()) - - vifs = self.network_api.get_vifs_by_instance(context, - instance['id']) + vifs = self.network_api.get_vifs_by_instance(context, server_id) limited_list = common.limited(vifs, req) res = [entity_maker(context, vif) for vif in limited_list] return {'virtual_interfaces': res} -- cgit From 340c0dd5250d6cdee08ccf86cf7a1e88cfbeea07 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Sun, 18 Sep 2011 16:01:28 -0400 Subject: catching AttributeError and adding tests --- nova/api/openstack/servers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 0ef246852..9152d92bf 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -151,6 +151,7 @@ class Controller(object): def create(self, req, body): """ Creates a new server for a given user """ + if 'server' in body: body['server']['key_name'] = self._get_key_name(req, body) @@ -656,7 +657,11 @@ class ControllerV11(Controller): def _get_key_name(self, req, body): if 'server' in body: - return body['server'].get('key_name') + try: + return body['server'].get('key_name') + except AttributeError: + msg = _("Malformed server entity") + raise exc.HTTPBadRequest(explanation=msg) def _image_ref_from_req_data(self, data): try: -- cgit From 4c29835b6e5bd89460846588994f75543e5c235a Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Sun, 18 Sep 2011 17:01:44 -0400 Subject: removing extra newline --- nova/api/openstack/servers.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 9152d92bf..856c3c613 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -151,7 +151,6 @@ class Controller(object): def create(self, req, body): """ Creates a new server for a given user """ - if 'server' in body: body['server']['key_name'] = self._get_key_name(req, body) -- cgit