From b93abf52587da04f8079be9be1ed0f9a473a9613 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 21 Apr 2011 11:48:47 -0500 Subject: commit to push for testing --- nova/api/openstack/views/addresses.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/addresses.py b/nova/api/openstack/views/addresses.py index 2810cce39..dc9e23450 100644 --- a/nova/api/openstack/views/addresses.py +++ b/nova/api/openstack/views/addresses.py @@ -41,8 +41,9 @@ class ViewBuilderV10(ViewBuilder): class ViewBuilderV11(ViewBuilder): def build(self, inst): - private_ips = utils.get_from_path(inst, 'fixed_ip/address') + private_ips = utils.get_from_path(inst, 'fixed_ips/address') private_ips = [dict(version=4, addr=a) for a in private_ips] - public_ips = utils.get_from_path(inst, 'fixed_ip/floating_ips/address') + public_ips = utils.get_from_path(inst, + 'fixed_ips/floating_ips/address') public_ips = [dict(version=4, addr=a) for a in public_ips] return dict(public=public_ips, private=private_ips) -- cgit From 08a22883fd5bf58b5b74645d1b2065a0be8c733b Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 19 May 2011 10:40:49 -0500 Subject: updated the hypervisors and ec2 api to support receiving lists from pluralized mac_addresses and fixed_ips --- nova/api/ec2/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 0e74089be..42ade8dca 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -723,7 +723,7 @@ class CloudController(object): if instance['fixed_ip']['network'] and 'use_v6' in kwargs: i['dnsNameV6'] = utils.to_global_ipv6( instance['fixed_ip']['network']['cidr_v6'], - instance['mac_address']) + instance['fixed_ip']['mac_address']['address']) i['privateDnsName'] = fixed_addr i['privateIpAddress'] = fixed_addr -- cgit From 0438855659d89133e588dd4201956a901ed85787 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Wed, 8 Jun 2011 12:41:09 -0500 Subject: removed network_info shims in vmops --- nova/api/ec2/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 117611d4b..bd8ca813c 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -793,7 +793,7 @@ class CloudController(object): if instance['fixed_ip']['network'] and 'use_v6' in kwargs: i['dnsNameV6'] = ipv6.to_global( instance['fixed_ip']['network']['cidr_v6'], - instance['fixed_ip']['mac_address']['address'], + instance['fixed_ip']['virtual_interface']['address'], instance['project_id']) i['privateDnsName'] = fixed_addr -- cgit From 9ef64c8ccbcdacfef642b2c203ffcc45b2deaf36 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Tue, 14 Jun 2011 17:52:49 -0500 Subject: fixed instance[fixed_ip] in ec2 api, removed fixed_ip shim --- nova/api/ec2/cloud.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 14a18c330..e74256dfa 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -121,8 +121,8 @@ class CloudController(object): result = {} for instance in self.compute_api.get_all(context, project_id=project_id): - if instance['fixed_ip']: - line = '%s slots=%d' % (instance['fixed_ip']['address'], + if instance['fixed_ips']: + line = '%s slots=%d' % (instance['fixed_ips'][0]['address'], instance['vcpus']) key = str(instance['key_name']) if key in result: @@ -793,15 +793,15 @@ class CloudController(object): 'name': instance['state_description']} fixed_addr = None floating_addr = None - if instance['fixed_ip']: - fixed_addr = instance['fixed_ip']['address'] - if instance['fixed_ip']['floating_ips']: - fixed = instance['fixed_ip'] + if instance['fixed_ips']: + fixed = instance['fixed_ips'][0] + fixed_addr = fixed['address'] + if fixed['floating_ips']: floating_addr = fixed['floating_ips'][0]['address'] - if instance['fixed_ip']['network'] and 'use_v6' in kwargs: + if fixed['network'] and 'use_v6' in kwargs: i['dnsNameV6'] = ipv6.to_global( - instance['fixed_ip']['network']['cidr_v6'], - instance['fixed_ip']['virtual_interface']['address'], + fixed['network']['cidr_v6'], + fixed['virtual_interface']['address'], instance['project_id']) i['privateDnsName'] = fixed_addr -- cgit From 25009974df913c3e5c071b53a6004ae35e37d26b Mon Sep 17 00:00:00 2001 From: Eldar Nugaev Date: Thu, 16 Jun 2011 17:37:45 +0400 Subject: First implementation of FloatingIpController --- nova/api/openstack/contrib/floating_ips.py | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 nova/api/openstack/contrib/floating_ips.py (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py new file mode 100644 index 000000000..b67b8b4ec --- /dev/null +++ b/nova/api/openstack/contrib/floating_ips.py @@ -0,0 +1,54 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# Copyright 2011 Grid Dynamics +# +# 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 webob import exc + +from nova import exception +from nova import network +from nova.api.openstack import faults + +def _translate_floating_ip_detail_view(context, floating_ip): + #TODO(enugaev) implement view + return None + +class FloatingIPController(object): + """The Volumes API controller for the OpenStack API.""" + + _serialization_metadata = { + 'application/xml': { + "attributes": { + "floating_ip": [ + "id", + "ip", + "instance_id", + "fixed_ip", + ]}}} + + def __init__(self): + self.network_api = network.API() + super(FloatingIPController, self).__init__() + + def show(self, req, id): + """Return data about the given volume.""" + context = req.environ['nova.context'] + + try: + floating_ip = self.network_api.get(context, id) + except exception.NotFound: + return faults.Fault(exc.HTTPNotFound()) + + return {'volume': _translate_floating_ip_detail_view(context, + floating_ip)} \ No newline at end of file -- cgit From a1e310aaa9f0ef829e2857c524be140541f3a13d Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Thu, 16 Jun 2011 20:31:09 +0400 Subject: floating_ips extension is loading to api now --- nova/api/openstack/contrib/floating_ips.py | 45 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index b67b8b4ec..6c08f52e5 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -19,11 +19,16 @@ from webob import exc from nova import exception from nova import network from nova.api.openstack import faults +from nova.api.openstack import extensions def _translate_floating_ip_detail_view(context, floating_ip): #TODO(enugaev) implement view return None +def _translate_floating_ips_view(context, floating_ips): + #TODO(adiantum) implement view + return [] + class FloatingIPController(object): """The Volumes API controller for the OpenStack API.""" @@ -50,5 +55,41 @@ class FloatingIPController(object): except exception.NotFound: return faults.Fault(exc.HTTPNotFound()) - return {'volume': _translate_floating_ip_detail_view(context, - floating_ip)} \ No newline at end of file + return {'floating_ips': _translate_floating_ip_detail_view(context, + floating_ip)} + + def index(self, req): + context = req.environ['nova.context'] + + floating_ips = self.network_api.list(context) + + return {'floating_ips' : _translate_floating_ips_view(context, + floating_ips)} + + +class Floating_ips(extensions.ExtensionDescriptor): + def get_name(self): + return "Floating_ips" + + def get_alias(self): + return "FLOATING_IPS" + + def get_description(self): + return "Floating IPs support" + + def get_namespace(self): + return "http://docs.openstack.org/ext/floating_ips/api/v1.1" + + def get_updated(self): + return "2011-06-16T00:00:00+00:00" + + def get_resources(self): + resources = [] + + res = extensions.ResourceExtension('floating_ips', + FloatingIPController(), + collection_actions={}) + resources.append(res) + + return resources + -- cgit From 971efd1b5568c324c91e826fc347c49ceea3790c Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Fri, 17 Jun 2011 17:27:06 +0400 Subject: stub api methods --- nova/api/openstack/contrib/floating_ips.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index 6c08f52e5..f7a939ddd 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -66,6 +66,25 @@ class FloatingIPController(object): return {'floating_ips' : _translate_floating_ips_view(context, floating_ips)} + def create(self, req, body): + context = req.environ['nova.context'] + + return {'allocate': None} + + def delete(self,req, id): + context = req.environ['nova.context'] + + return {'release': None } + + def associate(self, req, id, body): + context = req.environ['nova.context'] + + return {'associate': None} + + def disassociate(self, req, id, body): + context = req.environ['nova.context'] + + return {'disassociate': None} class Floating_ips(extensions.ExtensionDescriptor): def get_name(self): @@ -88,7 +107,9 @@ class Floating_ips(extensions.ExtensionDescriptor): res = extensions.ResourceExtension('floating_ips', FloatingIPController(), - collection_actions={}) + member_actions={ + 'associate' : 'POST', + 'disassociate' : 'POST'}) resources.append(res) return resources -- cgit From 8bd0296224b70e318e208a4570b4acaa599f62c8 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 17 Jun 2011 18:26:31 +0400 Subject: Made hostname independent from ec2 id. Add generation of hostnames based on display name. --- nova/api/ec2/cloud.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index e1c65ae40..95d14ce9f 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -86,8 +86,7 @@ class CloudController(object): self.volume_api = volume.API() self.compute_api = compute.API( network_api=self.network_api, - volume_api=self.volume_api, - hostname_factory=ec2utils.id_to_ec2_id) + volume_api=self.volume_api) self.setup() def __str__(self): -- cgit From 843644aed6477b4411ec3f07d1a5271df41c9798 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Sat, 18 Jun 2011 23:10:41 -0400 Subject: General cleanup and refactor of a lot of the API/WSGI service code. --- nova/api/openstack/wsgi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index a57b7f72b..6033c1f5b 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -356,7 +356,7 @@ class Resource(wsgi.Application): def __call__(self, request): """WSGI method that controls (de)serialization and method dispatch.""" - LOG.debug("%(method)s %(url)s" % {"method": request.method, + LOG.info("%(method)s %(url)s" % {"method": request.method, "url": request.url}) try: @@ -384,7 +384,7 @@ class Resource(wsgi.Application): msg_dict = dict(url=request.url, e=e) msg = _("%(url)s returned a fault: %(e)s" % msg_dict) - LOG.debug(msg) + LOG.info(msg) return response -- cgit From 3f2c0521f1c8462380c68d5245b5754867738fa1 Mon Sep 17 00:00:00 2001 From: John Tran Date: Tue, 21 Jun 2011 18:14:31 -0700 Subject: ec2 api describe_security_groups allow group_id param , added tests for create/delete security group in test_cloud although also exists in test_api this tests directly the ec2 method. --- nova/api/ec2/cloud.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 97875f1f5..9364b0bdd 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -391,15 +391,20 @@ class CloudController(object): pass return True - def describe_security_groups(self, context, group_name=None, **kwargs): + def describe_security_groups(self, context, group_name=None, group_id=None, **kwargs): self.compute_api.ensure_default_security_group(context) - if group_name: + if group_name or group_id: groups = [] - for name in group_name: - group = db.security_group_get_by_name(context, - context.project_id, - name) - groups.append(group) + if group_name: + for name in group_name: + group = db.security_group_get_by_name(context, + context.project_id, + name) + groups.append(group) + if group_id: + for gid in group_id: + group = db.security_group_get(context, context.project_id, name) + groups.append(group) elif context.is_admin: groups = db.security_group_get_all(context) else: @@ -568,7 +573,7 @@ class CloudController(object): return source_project_id - def create_security_group(self, context, group_name, group_description): + def create_security_group(self, context, group_name, group_description, group_id=None): LOG.audit(_("Create Security Group %s"), group_name, context=context) self.compute_api.ensure_default_security_group(context) if db.security_group_exists(context, context.project_id, group_name): -- cgit From 1f99e500a99a4d66639f04f2c723058c4d1dfc1d Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 22 Jun 2011 13:45:24 -0700 Subject: Check API request for min_count/max_count for number of instances to build --- nova/api/openstack/create_instance_helper.py | 6 ++++++ nova/api/openstack/servers.py | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 436e524c1..3e055936c 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -114,6 +114,12 @@ class CreateInstanceHelper(object): name = name.strip() reservation_id = body['server'].get('reservation_id') + min_count = body['server'].get('min_count') + max_count = body['server'].get('max_count') + if min_count: + min_count = int(min_count) + if max_count: + max_count = int(max_count) try: inst_type = \ diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index b82a6de19..31ec46e8e 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -111,14 +111,15 @@ class Controller(object): extra_values = None result = None try: - extra_values, result = self.helper.create_instance( + extra_values, instances = self.helper.create_instance( req, body, self.compute_api.create) except faults.Fault, f: return f - instances = result - - (inst, ) = instances + # We can only return 1 instance via the API, if we happen to + # build more than one... instances is a list, so we'll just + # use the first one.. + inst = instances[0] for key in ['instance_type', 'image_ref']: inst[key] = extra_values[key] -- cgit From b7684e0d36010050ce8254bbbf4573a6a624fa69 Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Thu, 23 Jun 2011 04:28:42 +0400 Subject: allocate and release implementation --- nova/api/openstack/contrib/floating_ips.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index f7a939ddd..9bad6806c 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -18,6 +18,7 @@ from webob import exc from nova import exception from nova import network +from nova import rpc from nova.api.openstack import faults from nova.api.openstack import extensions @@ -69,12 +70,27 @@ class FloatingIPController(object): def create(self, req, body): context = req.environ['nova.context'] - return {'allocate': None} + try: + ip = self.network_api.allocate_floating_ip(context) + except rpc.RemoteError as ex: + if ex.exc_type == 'NoMoreAddresses': + raise exception.NoMoreFloatingIps() + else: + raise + + return {'allocated': ip} def delete(self,req, id): context = req.environ['nova.context'] - return {'release': None } + if id.isdigit(): + ip = self.network_api.get(id) + else: + ip = id + + self.network_api.release_floating_ip(context, address=ip) + + return {'released': ip } def associate(self, req, id, body): context = req.environ['nova.context'] -- cgit From a9de2c26432b0b6c77e941db0199fd72a54e2d69 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Wed, 22 Jun 2011 22:40:00 -0400 Subject: Added flavor extra specs controller --- nova/api/openstack/__init__.py | 6 ++ nova/api/openstack/flavor_extra_specs.py | 106 +++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 nova/api/openstack/flavor_extra_specs.py (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index ddd9580d7..464ba1a9a 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -32,6 +32,7 @@ from nova.api.openstack import faults from nova.api.openstack import backup_schedules from nova.api.openstack import consoles from nova.api.openstack import flavors +from nova.api.openstack import flavor_extra_specs from nova.api.openstack import images from nova.api.openstack import image_metadata from nova.api.openstack import ips @@ -178,3 +179,8 @@ class APIRouterV11(APIRouter): controller=server_metadata.create_resource(), parent_resource=dict(member_name='server', collection_name='servers')) + + mapper.resource("flavor_extra_specs", "extra", + controller=flavor_extra_specs.create_resource(), + parent_resource=dict(member_name='flavor', + collection_name='flavors')) diff --git a/nova/api/openstack/flavor_extra_specs.py b/nova/api/openstack/flavor_extra_specs.py new file mode 100644 index 000000000..2dcd85688 --- /dev/null +++ b/nova/api/openstack/flavor_extra_specs.py @@ -0,0 +1,106 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 University of Southern California +# 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 webob import exc + +from nova import db +from nova import quota +from nova.api.openstack import faults +from nova.api.openstack import wsgi + + +class Controller(object): + """ The flavor extra specs API controller for the Openstack API """ + + def __init__(self): + self.compute_api = compute.API() + super(Controller, self).__init__() + + def _get_extra_specs(self, context, flavor_id): + extra_specs = self.db.instance_type_extra_specs_get(context, flavor_id) + specs_dict = {} + for key, value in specs.iteritems(): + specs_dict[key] = value + return dict(extra=specs_dict) + + def _check_body(self, body): + if body == None or body == "": + expl = _('No Request Body') + raise exc.HTTPBadRequest(explanation=expl) + + def index(self, req, flavor_id): + """ Returns the list of extra specs for a givenflavor """ + context = req.environ['nova.context'] + return self._get_extra_specs(context, flavor_id) + + def create(self, req, flavor_id, body): + self._check_body(body) + context = req.environ['nova.context'] + specs = body.get('extra') + try: + self.db.instance_type_extra_specs_update_or_create(context, + flavor_id, + specs) + except quota.QuotaError as error: + self._handle_quota_error(error) + return body + + def update(self, req, flavor_id, id, body): + self._check_body(body) + context = req.environ['nova.context'] + if not id in body: + expl = _('Request body and URI mismatch') + raise exc.HTTPBadRequest(explanation=expl) + if len(body) > 1: + expl = _('Request body contains too many items') + raise exc.HTTPBadRequest(explanation=expl) + try: + self.db.instance_type_extra_specs_update_or_create(context, + flavor_id, + body) + except quota.QuotaError as error: + self._handle_quota_error(error) + + return body + + def show(self, req, flavor_id, id): + """ Return a single extra spec item """ + context = req.environ['nova.context'] + specs = self._get_extra_specs(context, flavor_id) + if id in specs['extra']: + return {id: specs['extra'][id]} + else: + return faults.Fault(exc.HTTPNotFound()) + + def delete(self, req, flavor_id, id): + """ Deletes an existing extra spec """ + context = req.environ['nova.context'] + self.instance_type_extra_specs_delete(context, flavor_id, id) + + def _handle_quota_error(self, error): + """Reraise quota errors as api-specific http exceptions.""" + if error.code == "MetadataLimitExceeded": + raise exc.HTTPBadRequest(explanation=error.message) + raise error + + +def create_resource(): + serializers = { + 'application/xml': wsgi.XMLDictSerializer(xmlns=wsgi.XMLNS_V11), + } + + return wsgi.Resource(Controller(), serializers=serializers) -- cgit From 173bb3c54b7ce9874f6bf880a5df8966fd508c38 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Wed, 22 Jun 2011 22:43:44 -0400 Subject: Bug fixing --- nova/api/openstack/flavor_extra_specs.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/flavor_extra_specs.py b/nova/api/openstack/flavor_extra_specs.py index 2dcd85688..d14bed813 100644 --- a/nova/api/openstack/flavor_extra_specs.py +++ b/nova/api/openstack/flavor_extra_specs.py @@ -26,14 +26,10 @@ from nova.api.openstack import wsgi class Controller(object): """ The flavor extra specs API controller for the Openstack API """ - def __init__(self): - self.compute_api = compute.API() - super(Controller, self).__init__() - def _get_extra_specs(self, context, flavor_id): - extra_specs = self.db.instance_type_extra_specs_get(context, flavor_id) + extra_specs = db.instance_type_extra_specs_get(context, flavor_id) specs_dict = {} - for key, value in specs.iteritems(): + for key, value in extra_specs.iteritems(): specs_dict[key] = value return dict(extra=specs_dict) -- cgit From 6afcabac7442aa2e3944a3fef3d3452c189c1901 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Wed, 22 Jun 2011 23:14:39 -0400 Subject: Now passing unit tests --- nova/api/openstack/flavor_extra_specs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/flavor_extra_specs.py b/nova/api/openstack/flavor_extra_specs.py index d14bed813..6a6d2f7a1 100644 --- a/nova/api/openstack/flavor_extra_specs.py +++ b/nova/api/openstack/flavor_extra_specs.py @@ -27,7 +27,7 @@ class Controller(object): """ The flavor extra specs API controller for the Openstack API """ def _get_extra_specs(self, context, flavor_id): - extra_specs = db.instance_type_extra_specs_get(context, flavor_id) + extra_specs = db.api.instance_type_extra_specs_get(context, flavor_id) specs_dict = {} for key, value in extra_specs.iteritems(): specs_dict[key] = value @@ -48,9 +48,9 @@ class Controller(object): context = req.environ['nova.context'] specs = body.get('extra') try: - self.db.instance_type_extra_specs_update_or_create(context, - flavor_id, - specs) + db.api.instance_type_extra_specs_update_or_create(context, + flavor_id, + specs) except quota.QuotaError as error: self._handle_quota_error(error) return body @@ -65,7 +65,7 @@ class Controller(object): expl = _('Request body contains too many items') raise exc.HTTPBadRequest(explanation=expl) try: - self.db.instance_type_extra_specs_update_or_create(context, + db.api.instance_type_extra_specs_update_or_create(context, flavor_id, body) except quota.QuotaError as error: @@ -85,7 +85,7 @@ class Controller(object): def delete(self, req, flavor_id, id): """ Deletes an existing extra spec """ context = req.environ['nova.context'] - self.instance_type_extra_specs_delete(context, flavor_id, id) + db.api.instance_type_extra_specs_delete(context, flavor_id, id) def _handle_quota_error(self, error): """Reraise quota errors as api-specific http exceptions.""" -- cgit From b9a861d72f1a98510dd4b68e547b434388ab9a64 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 23 Jun 2011 05:20:50 -0700 Subject: add support for compute_api.get_all() recursing zones for more than just reservation_id --- nova/api/openstack/servers.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index b82a6de19..8c93ce230 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -76,10 +76,19 @@ class Controller(object): builder - the response model builder """ - reservation_id = req.str_GET.get('reservation_id') + query_str = req.str_GET() + reservation_id = query_str.get('reservation_id') + project_id = query_str.get('project_id') + fixed_ip = query_str.get('fixed_ip') + recurse_zones = query_str.get('recurse_zones') + if recurse_zones is not None: + recurse_zones = True instance_list = self.compute_api.get_all( req.environ['nova.context'], - reservation_id=reservation_id) + reservation_id=reservation_id, + project_id=project_id, + fixed_ip=fixed_ip, + recurse_zones=recurse_zones) limited_list = self._limit_items(instance_list, req) builder = self._get_view_builder(req) servers = [builder.build(inst, is_detail)['server'] -- cgit From 07404e266a4a6b690c62624a9a5e47d60cab7d5b Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 23 Jun 2011 06:33:25 -0700 Subject: fixes for recurse_zones and None instances with compute's get_all --- nova/api/openstack/servers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 8c93ce230..9e861359a 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -81,8 +81,7 @@ class Controller(object): project_id = query_str.get('project_id') fixed_ip = query_str.get('fixed_ip') recurse_zones = query_str.get('recurse_zones') - if recurse_zones is not None: - recurse_zones = True + recurse_zones = recurse_zones and True or False instance_list = self.compute_api.get_all( req.environ['nova.context'], reservation_id=reservation_id, -- cgit From e241f5301621e66360bb884193884f9f98bc8832 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 23 Jun 2011 07:02:49 -0700 Subject: str_GET is a property --- nova/api/openstack/servers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 9e861359a..d499066be 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -76,7 +76,7 @@ class Controller(object): builder - the response model builder """ - query_str = req.str_GET() + query_str = req.str_GET reservation_id = query_str.get('reservation_id') project_id = query_str.get('project_id') fixed_ip = query_str.get('fixed_ip') -- cgit From 9044733fb0aff698875080caf1ffd9e44470ec0e Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 23 Jun 2011 10:53:09 -0400 Subject: adding metadata container to /images/detail and /images/ calls --- nova/api/openstack/views/images.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'nova/api') diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 2773c9c13..e7472b5cd 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -109,6 +109,9 @@ class ViewBuilderV11(ViewBuilder): image = ViewBuilder.build(self, image_obj, detail) href = self.generate_href(image_obj["id"]) + if detail: + image["metadata"] = image_obj.get("properties", {}) + image["links"] = [{ "rel": "self", "href": href, -- cgit From b186f7ae1515b8296f5fdb7f86b67c07973bb463 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 23 Jun 2011 12:41:57 -0400 Subject: fixing 500 on None metadata value --- nova/api/openstack/image_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/image_metadata.py b/nova/api/openstack/image_metadata.py index 90cbfe04c..639e4320d 100644 --- a/nova/api/openstack/image_metadata.py +++ b/nova/api/openstack/image_metadata.py @@ -111,7 +111,7 @@ class ImageMetadataXMLSerializer(wsgi.XMLDictSerializer): def _meta_item_to_xml(self, doc, key, value): node = doc.createElement('meta') node.setAttribute('key', key) - text = doc.createTextNode(value) + text = doc.createTextNode(str(value)) node.appendChild(text) return node -- cgit From d5206c7f41c435fd39c1bb9c0fd7ec53c9685f43 Mon Sep 17 00:00:00 2001 From: John Tran Date: Thu, 23 Jun 2011 11:31:22 -0700 Subject: altho security_group authorize & revoke tests already exist in test_api, adding some direct ec2 api method tests. added group_id param support to the pertinent security group methods --- nova/api/ec2/cloud.py | 78 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 20 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 9364b0bdd..75b1fb2a7 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -391,7 +391,8 @@ class CloudController(object): pass return True - def describe_security_groups(self, context, group_name=None, group_id=None, **kwargs): + def describe_security_groups(self, context, group_name=None, group_id=None, + **kwargs): self.compute_api.ensure_default_security_group(context) if group_name or group_id: groups = [] @@ -403,7 +404,7 @@ class CloudController(object): groups.append(group) if group_id: for gid in group_id: - group = db.security_group_get(context, context.project_id, name) + group = db.security_group_get(context, gid) groups.append(group) elif context.is_admin: groups = db.security_group_get_all(context) @@ -502,13 +503,26 @@ class CloudController(object): return True return False - def revoke_security_group_ingress(self, context, group_name, **kwargs): - LOG.audit(_("Revoke security group ingress %s"), group_name, - context=context) + def revoke_security_group_ingress(self, context, group_name=None, + group_id=None, **kwargs): + if not group_name and not group_id: + err = "Not enough parameters, need group_name or group_id" + raise exception.ApiError(_(err)) self.compute_api.ensure_default_security_group(context) - security_group = db.security_group_get_by_name(context, - context.project_id, - group_name) + notfound = exception.SecurityGroupNotFound + if group_name: + security_group = db.security_group_get_by_name(context, + context.project_id, + group_name) + if not security_group: + raise notfound(security_group_id=group_name) + if group_id: + security_group = db.security_group_get(context, group_id) + if not security_group: + raise notfound(security_group_id=group_id) + + msg = "Revoke security group ingress %s" + LOG.audit(_(msg), security_group['name'], context=context) criteria = self._revoke_rule_args_to_dict(context, **kwargs) if criteria is None: @@ -531,14 +545,26 @@ class CloudController(object): # Unfortunately, it seems Boto is using an old API # for these operations, so support for newer API versions # is sketchy. - def authorize_security_group_ingress(self, context, group_name, **kwargs): - LOG.audit(_("Authorize security group ingress %s"), group_name, - context=context) + def authorize_security_group_ingress(self, context, group_name=None, + group_id=None, **kwargs): + if not group_name and not group_id: + err = "Not enough parameters, need group_name or group_id" + raise exception.ApiError(_(err)) self.compute_api.ensure_default_security_group(context) - security_group = db.security_group_get_by_name(context, - context.project_id, - group_name) - + notfound = exception.SecurityGroupNotFound + if group_name: + security_group = db.security_group_get_by_name(context, + context.project_id, + group_name) + if not security_group: + raise notfound(security_group_id=group_name) + if group_id: + security_group = db.security_group_get(context, group_id) + if not security_group: + raise notfound(security_group_id=group_id) + + msg = "Authorize security group ingress %s" + LOG.audit(_(msg), security_group['name'], context=context) values = self._revoke_rule_args_to_dict(context, **kwargs) if values is None: raise exception.ApiError(_("Not enough parameters to build a " @@ -573,7 +599,7 @@ class CloudController(object): return source_project_id - def create_security_group(self, context, group_name, group_description, group_id=None): + def create_security_group(self, context, group_name, group_description): LOG.audit(_("Create Security Group %s"), group_name, context=context) self.compute_api.ensure_default_security_group(context) if db.security_group_exists(context, context.project_id, group_name): @@ -588,11 +614,23 @@ class CloudController(object): return {'securityGroupSet': [self._format_security_group(context, group_ref)]} - def delete_security_group(self, context, group_name, **kwargs): + def delete_security_group(self, context, group_name=None, group_id=None, + **kwargs): + if not group_name and not group_id: + err = "Not enough parameters, need group_name or group_id" + raise exception.ApiError(_(err)) + notfound = exception.SecurityGroupNotFound + if group_name: + security_group = db.security_group_get_by_name(context, + context.project_id, + group_name) + if not security_group: + raise notfound(security_group_id=group_name) + elif group_id: + security_group = db.security_group_get(context, group_id) + if not security_group: + raise notfound(security_group_id=group_id) LOG.audit(_("Delete security group %s"), group_name, context=context) - security_group = db.security_group_get_by_name(context, - context.project_id, - group_name) db.security_group_destroy(context, security_group.id) return True -- cgit From f6964aadc5b073152d221bb0a4e899c2b17d174c Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 23 Jun 2011 14:27:13 -0500 Subject: Small refactoring around getting params --- nova/api/openstack/images.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 5ffd8e96a..54f8e05a9 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -88,28 +88,53 @@ class Controller(object): return webob.exc.HTTPNoContent() def create(self, req, body): - """Snapshot a server instance and save the image. + """Snapshot or backup a server instance and save the image. + + Images now have an `image_type` associated with them, which can be + 'snapshot' or the backup type, like 'daily' or 'weekly'. + + If the image_type is backup-like, then the rotation factor can be + included and that will cause the oldest backups that exceed the + rotation factor to be deleted. :param req: `wsgi.Request` object """ + def get_param(param): + try: + return body["image"][param] + except KeyError: + raise webob.exc.HTTPBadRequest() + context = req.environ['nova.context'] content_type = req.get_content_type() if not body: raise webob.exc.HTTPBadRequest() + image_type = body["image"].get("image_type", "snapshot") + try: server_id = self._server_id_from_req_data(body) - image_name = body["image"]["name"] except KeyError: raise webob.exc.HTTPBadRequest() - image = self._compute_service.snapshot(context, server_id, image_name) + if image_type == "snapshot": + image_name = get_param("name") + image = self._compute_service.snapshot(context, server_id, + image_name) + else: + if not FLAGS.allow_admin_api: + raise webob.exc.HTTPBadRequest() + + rotation = get_param("rotation") + image = self._compute_service.backup(context, server_id, + image_type, rotation) + return dict(image=self.get_builder(req).build(image, detail=True)) def get_builder(self, request): """Indicates that you must use a Controller subclass.""" - raise NotImplementedError + raise NotImplementedError() def _server_id_from_req_data(self, data): raise NotImplementedError() -- cgit From 1b5cde761bd699f6fec207f4b1b41d8c63ea1ec7 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Thu, 23 Jun 2011 15:48:49 -0400 Subject: fixing 500 error on v1.0 images xml --- nova/api/openstack/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 31b2e1c37..ed1811779 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -262,7 +262,7 @@ def create_resource(version='1.0'): } xml_serializer = { - '1.0': wsgi.XMLDictSerializer(wsgi.XMLNS_V10, metadata), + '1.0': wsgi.XMLDictSerializer(metadata, wsgi.XMLNS_V10), '1.1': ImageXMLSerializer(), }[version] -- cgit From c2216547d0c55e32a4f8203129f4604f4ba004c7 Mon Sep 17 00:00:00 2001 From: Eldar Nugaev Date: Fri, 24 Jun 2011 00:39:37 +0400 Subject: Implemented view and added tests --- nova/api/openstack/contrib/floating_ips.py | 57 ++++++++++++++++++------------ 1 file changed, 35 insertions(+), 22 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index 9bad6806c..dc048869c 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -22,13 +22,25 @@ from nova import rpc from nova.api.openstack import faults from nova.api.openstack import extensions -def _translate_floating_ip_detail_view(context, floating_ip): - #TODO(enugaev) implement view - return None -def _translate_floating_ips_view(context, floating_ips): - #TODO(adiantum) implement view - return [] +def _translate_floating_ip_view(floating_ip): + result = {'id': floating_ip['id'], + 'ip': floating_ip['address']} + if 'fixed_ip' in floating_ip: + result['fixed_ip'] = floating_ip['fixed_ip']['address'] + else: + result['fixed_ip'] = None + if 'instance' in floating_ip: + result['instance_id'] = floating_ip['instance']['id'] + else: + result['instance_id'] = None + return {'floating_ip': result} + + +def _translate_floating_ips_view(floating_ips): + return {'floating_ips': [_translate_floating_ip_view(floating_ip) + for floating_ip in floating_ips]} + class FloatingIPController(object): """The Volumes API controller for the OpenStack API.""" @@ -48,7 +60,7 @@ class FloatingIPController(object): super(FloatingIPController, self).__init__() def show(self, req, id): - """Return data about the given volume.""" + """Return data about the given floating ip.""" context = req.environ['nova.context'] try: @@ -56,16 +68,14 @@ class FloatingIPController(object): except exception.NotFound: return faults.Fault(exc.HTTPNotFound()) - return {'floating_ips': _translate_floating_ip_detail_view(context, - floating_ip)} + return _translate_floating_ip_view(floating_ip) def index(self, req): context = req.environ['nova.context'] floating_ips = self.network_api.list(context) - return {'floating_ips' : _translate_floating_ips_view(context, - floating_ips)} + return _translate_floating_ips_view(floating_ips) def create(self, req, body): context = req.environ['nova.context'] @@ -80,17 +90,13 @@ class FloatingIPController(object): return {'allocated': ip} - def delete(self,req, id): + def delete(self, req, id): context = req.environ['nova.context'] - - if id.isdigit(): - ip = self.network_api.get(id) - else: - ip = id - + + ip = self._get_ip_by_id(context, id) self.network_api.release_floating_ip(context, address=ip) - return {'released': ip } + return {'released': ip} def associate(self, req, id, body): context = req.environ['nova.context'] @@ -102,6 +108,14 @@ class FloatingIPController(object): return {'disassociate': None} + def _get_ip_by_id(self, context, value): + """Checks that value is id and then returns its address. + If value is ip then return value.""" + if value.isdigit(): + return self.network_api.get(context, value)['address'] + return value + + class Floating_ips(extensions.ExtensionDescriptor): def get_name(self): return "Floating_ips" @@ -124,9 +138,8 @@ class Floating_ips(extensions.ExtensionDescriptor): res = extensions.ResourceExtension('floating_ips', FloatingIPController(), member_actions={ - 'associate' : 'POST', - 'disassociate' : 'POST'}) + 'associate': 'POST', + 'disassociate': 'POST'}) resources.append(res) return resources - -- cgit From 2d0d1e179dd8870967ebf00a82fbc7d21bed6116 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Thu, 23 Jun 2011 16:28:59 -0500 Subject: Cast rotation to int. --- nova/api/openstack/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 54f8e05a9..d8dbd2360 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -126,7 +126,7 @@ class Controller(object): if not FLAGS.allow_admin_api: raise webob.exc.HTTPBadRequest() - rotation = get_param("rotation") + rotation = int(get_param("rotation")) image = self._compute_service.backup(context, server_id, image_type, rotation) -- cgit From 5004736930c0c9619ba3efd48910a47fd58e0921 Mon Sep 17 00:00:00 2001 From: John Tran Date: Thu, 23 Jun 2011 15:42:57 -0700 Subject: specify keyword, or direct_api proxy method blows up --- nova/api/ec2/cloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 75b1fb2a7..c6d286fb3 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -537,7 +537,7 @@ class CloudController(object): if match: db.security_group_rule_destroy(context, rule['id']) self.compute_api.trigger_security_group_rules_refresh(context, - security_group['id']) + security_group_id=security_group['id']) return True raise exception.ApiError(_("No rule for the specified parameters.")) @@ -578,7 +578,7 @@ class CloudController(object): security_group_rule = db.security_group_rule_create(context, values) self.compute_api.trigger_security_group_rules_refresh(context, - security_group['id']) + security_group_id=security_group['id']) return True -- cgit From 188dd9117318cc4f5ebe0be9d19b9737a43ce68b Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Thu, 23 Jun 2011 23:42:44 -0400 Subject: Starting to transition instance type extra specs API to an extension API --- nova/api/openstack/__init__.py | 5 - nova/api/openstack/contrib/flavorextraspecs.py | 123 +++++++++++++++++++++++++ nova/api/openstack/flavor_extra_specs.py | 102 -------------------- 3 files changed, 123 insertions(+), 107 deletions(-) create mode 100644 nova/api/openstack/contrib/flavorextraspecs.py delete mode 100644 nova/api/openstack/flavor_extra_specs.py (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 857a5431b..859cac669 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -178,8 +178,3 @@ class APIRouterV11(APIRouter): controller=server_metadata.create_resource(), parent_resource=dict(member_name='server', collection_name='servers')) - - mapper.resource("flavor_extra_specs", "extra", - controller=flavor_extra_specs.create_resource(), - parent_resource=dict(member_name='flavor', - collection_name='flavors')) diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py new file mode 100644 index 000000000..24c5da7b2 --- /dev/null +++ b/nova/api/openstack/contrib/flavorextraspecs.py @@ -0,0 +1,123 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 University of Southern California +# 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. + +""" The instance type extra specs extension""" + +from webob import exc + +from nova import db +from nova import quota +from nova.api.openstack import extensions +from nova.api.openstack import faults +from nova.api.openstack import wsgi + + +class FlavorExtraSpecsController(object): + """ The flavor extra specs API controller for the Openstack API """ + + def _get_extra_specs(self, context, flavor_id): + extra_specs = db.api.instance_type_extra_specs_get(context, flavor_id) + specs_dict = {} + for key, value in extra_specs.iteritems(): + specs_dict[key] = value + return dict(extra=specs_dict) + + def _check_body(self, body): + if body == None or body == "": + expl = _('No Request Body') + raise exc.HTTPBadRequest(explanation=expl) + + def index(self, req, flavor_id): + """ Returns the list of extra specs for a givenflavor """ + context = req.environ['nova.context'] + return self._get_extra_specs(context, flavor_id) + + def create(self, req, flavor_id, body): + self._check_body(body) + context = req.environ['nova.context'] + specs = body.get('extra') + try: + db.api.instance_type_extra_specs_update_or_create(context, + flavor_id, + specs) + except quota.QuotaError as error: + self._handle_quota_error(error) + return body + + def update(self, req, flavor_id, id, body): + self._check_body(body) + context = req.environ['nova.context'] + if not id in body: + expl = _('Request body and URI mismatch') + raise exc.HTTPBadRequest(explanation=expl) + if len(body) > 1: + expl = _('Request body contains too many items') + raise exc.HTTPBadRequest(explanation=expl) + try: + db.api.instance_type_extra_specs_update_or_create(context, + flavor_id, + body) + except quota.QuotaError as error: + self._handle_quota_error(error) + + return body + + def show(self, req, flavor_id, id): + """ Return a single extra spec item """ + context = req.environ['nova.context'] + specs = self._get_extra_specs(context, flavor_id) + if id in specs['extra']: + return {id: specs['extra'][id]} + else: + return faults.Fault(exc.HTTPNotFound()) + + def delete(self, req, flavor_id, id): + """ Deletes an existing extra spec """ + context = req.environ['nova.context'] + db.api.instance_type_extra_specs_delete(context, flavor_id, id) + + def _handle_quota_error(self, error): + """Reraise quota errors as api-specific http exceptions.""" + if error.code == "MetadataLimitExceeded": + raise exc.HTTPBadRequest(explanation=error.message) + raise error + +class Flavorextraspecs(extensions.ExtensionDescriptor): + def get_name(self): + return "FlavorExtraSpecs" + + def get_alias(self): + return "flavor-extra-specs" + + def get_description(self): + return "Instance type (flavor) extra specs" + + def get_namespace(self): + return \ + "http://docs.openstack.org/ext/flavor-extra-specs/api/v1.1" + + def get_updated(self): + return "2011-06-23T00:00:00+00:00" + + def get_resources(self): + resources = [] + + res = extensions.ResourceExtension('flavor-extra-specs', + FlavorExtraSpecsController()) + resources.append(res) + + return resources diff --git a/nova/api/openstack/flavor_extra_specs.py b/nova/api/openstack/flavor_extra_specs.py deleted file mode 100644 index 6a6d2f7a1..000000000 --- a/nova/api/openstack/flavor_extra_specs.py +++ /dev/null @@ -1,102 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 University of Southern California -# 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 webob import exc - -from nova import db -from nova import quota -from nova.api.openstack import faults -from nova.api.openstack import wsgi - - -class Controller(object): - """ The flavor extra specs API controller for the Openstack API """ - - def _get_extra_specs(self, context, flavor_id): - extra_specs = db.api.instance_type_extra_specs_get(context, flavor_id) - specs_dict = {} - for key, value in extra_specs.iteritems(): - specs_dict[key] = value - return dict(extra=specs_dict) - - def _check_body(self, body): - if body == None or body == "": - expl = _('No Request Body') - raise exc.HTTPBadRequest(explanation=expl) - - def index(self, req, flavor_id): - """ Returns the list of extra specs for a givenflavor """ - context = req.environ['nova.context'] - return self._get_extra_specs(context, flavor_id) - - def create(self, req, flavor_id, body): - self._check_body(body) - context = req.environ['nova.context'] - specs = body.get('extra') - try: - db.api.instance_type_extra_specs_update_or_create(context, - flavor_id, - specs) - except quota.QuotaError as error: - self._handle_quota_error(error) - return body - - def update(self, req, flavor_id, id, body): - self._check_body(body) - context = req.environ['nova.context'] - if not id in body: - expl = _('Request body and URI mismatch') - raise exc.HTTPBadRequest(explanation=expl) - if len(body) > 1: - expl = _('Request body contains too many items') - raise exc.HTTPBadRequest(explanation=expl) - try: - db.api.instance_type_extra_specs_update_or_create(context, - flavor_id, - body) - except quota.QuotaError as error: - self._handle_quota_error(error) - - return body - - def show(self, req, flavor_id, id): - """ Return a single extra spec item """ - context = req.environ['nova.context'] - specs = self._get_extra_specs(context, flavor_id) - if id in specs['extra']: - return {id: specs['extra'][id]} - else: - return faults.Fault(exc.HTTPNotFound()) - - def delete(self, req, flavor_id, id): - """ Deletes an existing extra spec """ - context = req.environ['nova.context'] - db.api.instance_type_extra_specs_delete(context, flavor_id, id) - - def _handle_quota_error(self, error): - """Reraise quota errors as api-specific http exceptions.""" - if error.code == "MetadataLimitExceeded": - raise exc.HTTPBadRequest(explanation=error.message) - raise error - - -def create_resource(): - serializers = { - 'application/xml': wsgi.XMLDictSerializer(xmlns=wsgi.XMLNS_V11), - } - - return wsgi.Resource(Controller(), serializers=serializers) -- cgit From 7a9dc4adc343aa9cf8c21cef741b3bfe409fc41e Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 24 Jun 2011 00:45:53 -0400 Subject: Committing some broken code in advance of trying a different strategy for specifying args to extensions.ResoruceExtensions, using parent --- nova/api/openstack/contrib/flavorextraspecs.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py index 24c5da7b2..f2f740bff 100644 --- a/nova/api/openstack/contrib/flavorextraspecs.py +++ b/nova/api/openstack/contrib/flavorextraspecs.py @@ -34,7 +34,7 @@ class FlavorExtraSpecsController(object): specs_dict = {} for key, value in extra_specs.iteritems(): specs_dict[key] = value - return dict(extra=specs_dict) + return dict(extra_specs=specs_dict) def _check_body(self, body): if body == None or body == "": @@ -43,13 +43,14 @@ class FlavorExtraSpecsController(object): def index(self, req, flavor_id): """ Returns the list of extra specs for a givenflavor """ + print req.environ context = req.environ['nova.context'] return self._get_extra_specs(context, flavor_id) def create(self, req, flavor_id, body): self._check_body(body) context = req.environ['nova.context'] - specs = body.get('extra') + specs = body.get('extra_specs') try: db.api.instance_type_extra_specs_update_or_create(context, flavor_id, @@ -80,8 +81,8 @@ class FlavorExtraSpecsController(object): """ Return a single extra spec item """ context = req.environ['nova.context'] specs = self._get_extra_specs(context, flavor_id) - if id in specs['extra']: - return {id: specs['extra'][id]} + if id in specs['extra_specs']: + return {id: specs['extra_specs'][id]} else: return faults.Fault(exc.HTTPNotFound()) @@ -108,16 +109,18 @@ class Flavorextraspecs(extensions.ExtensionDescriptor): def get_namespace(self): return \ - "http://docs.openstack.org/ext/flavor-extra-specs/api/v1.1" + "http://docs.openstack.org/ext/flavor_extra_specs/api/v1.1" def get_updated(self): return "2011-06-23T00:00:00+00:00" def get_resources(self): resources = [] - - res = extensions.ResourceExtension('flavor-extra-specs', - FlavorExtraSpecsController()) + res = extensions.ResourceExtension('flavor_extra_specs/:(flavor_id)', + FlavorExtraSpecsController(), + member_actions={ + 'show' : 'flavor_extra_specs/:(flavor_id)/extra/:(id)' }) resources.append(res) - return resources + + -- cgit From 4a0fcd6c1d5540c4bec29ef2585987300654c8b7 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 24 Jun 2011 01:01:30 -0400 Subject: All tests passing --- nova/api/openstack/contrib/flavorextraspecs.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py index f2f740bff..ac67fbf43 100644 --- a/nova/api/openstack/contrib/flavorextraspecs.py +++ b/nova/api/openstack/contrib/flavorextraspecs.py @@ -43,7 +43,6 @@ class FlavorExtraSpecsController(object): def index(self, req, flavor_id): """ Returns the list of extra specs for a givenflavor """ - print req.environ context = req.environ['nova.context'] return self._get_extra_specs(context, flavor_id) @@ -97,7 +96,9 @@ class FlavorExtraSpecsController(object): raise exc.HTTPBadRequest(explanation=error.message) raise error + class Flavorextraspecs(extensions.ExtensionDescriptor): + def get_name(self): return "FlavorExtraSpecs" @@ -116,11 +117,11 @@ class Flavorextraspecs(extensions.ExtensionDescriptor): def get_resources(self): resources = [] - res = extensions.ResourceExtension('flavor_extra_specs/:(flavor_id)', - FlavorExtraSpecsController(), - member_actions={ - 'show' : 'flavor_extra_specs/:(flavor_id)/extra/:(id)' }) - resources.append(res) - return resources + res = extensions.ResourceExtension( + 'flavor_extra_specs', + FlavorExtraSpecsController(), + parent=dict(member_name='flavor', collection_name='flavors')) + resources.append(res) + return resources -- cgit From 52319f7e4e55e78f4fdd9c76b3ab593322edc875 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 24 Jun 2011 01:02:28 -0400 Subject: Renamed from flavor_extra_specs to extra_specs --- nova/api/openstack/contrib/flavorextraspecs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py index ac67fbf43..7fc8e7954 100644 --- a/nova/api/openstack/contrib/flavorextraspecs.py +++ b/nova/api/openstack/contrib/flavorextraspecs.py @@ -118,7 +118,7 @@ class Flavorextraspecs(extensions.ExtensionDescriptor): def get_resources(self): resources = [] res = extensions.ResourceExtension( - 'flavor_extra_specs', + 'extra_specs', FlavorExtraSpecsController(), parent=dict(member_name='flavor', collection_name='flavors')) -- cgit From 48f3bccc3372023c35a75671e25e9089dd4ed836 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 24 Jun 2011 01:34:47 -0400 Subject: pep8 fixes --- nova/api/openstack/contrib/flavorextraspecs.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py index 7fc8e7954..8518bf2bd 100644 --- a/nova/api/openstack/contrib/flavorextraspecs.py +++ b/nova/api/openstack/contrib/flavorextraspecs.py @@ -122,6 +122,5 @@ class Flavorextraspecs(extensions.ExtensionDescriptor): FlavorExtraSpecsController(), parent=dict(member_name='flavor', collection_name='flavors')) - resources.append(res) return resources -- cgit From 2c303bcc8f47aaa5cdeee0ee91e3f4b434176f15 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 23 Jun 2011 22:45:58 -0700 Subject: missed passing in min/max_count into the create/create_all_at_once calls --- nova/api/openstack/create_instance_helper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 3e055936c..4c6cc0f83 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -120,6 +120,8 @@ class CreateInstanceHelper(object): min_count = int(min_count) if max_count: max_count = int(max_count) + if min_count > max_count: + min_count = max_count try: inst_type = \ @@ -143,7 +145,9 @@ class CreateInstanceHelper(object): injected_files=injected_files, admin_password=password, zone_blob=zone_blob, - reservation_id=reservation_id)) + reservation_id=reservation_id, + min_count=min_count, + max_count=max_count)) except quota.QuotaError as error: self._handle_quota_error(error) except exception.ImageNotFound as error: -- cgit From 4c46c44d7c1458ccaa3919110de12dfceef406c1 Mon Sep 17 00:00:00 2001 From: Lorin Hochstein Date: Fri, 24 Jun 2011 10:37:43 -0400 Subject: Removed an import --- nova/api/openstack/__init__.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/__init__.py b/nova/api/openstack/__init__.py index 859cac669..f24017df0 100644 --- a/nova/api/openstack/__init__.py +++ b/nova/api/openstack/__init__.py @@ -32,7 +32,6 @@ from nova.api.openstack import faults from nova.api.openstack import backup_schedules from nova.api.openstack import consoles from nova.api.openstack import flavors -from nova.api.openstack import flavor_extra_specs from nova.api.openstack import images from nova.api.openstack import image_metadata from nova.api.openstack import ips -- cgit From cbf9f1bef113d54be57e2bb9a79990226afcd90f Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 24 Jun 2011 11:55:43 -0500 Subject: Adding tests for backup no rotation, invalid image type --- nova/api/openstack/images.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index d8dbd2360..2287ca0f7 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -122,13 +122,17 @@ class Controller(object): image_name = get_param("name") image = self._compute_service.snapshot(context, server_id, image_name) - else: + elif image_type in ("daily", "weekly"): if not FLAGS.allow_admin_api: raise webob.exc.HTTPBadRequest() rotation = int(get_param("rotation")) image = self._compute_service.backup(context, server_id, image_type, rotation) + else: + LOG.error(_("Invalid image_type '%s' passed" % image_type)) + raise webob.exc.HTTPBadRequest() + return dict(image=self.get_builder(req).build(image, detail=True)) -- cgit From 1d3960e3b76e3f75c68f919278a2a227e1f96e48 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 24 Jun 2011 11:56:15 -0500 Subject: Pep8 fix --- nova/api/openstack/images.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 2287ca0f7..5f88ede96 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -133,7 +133,6 @@ class Controller(object): LOG.error(_("Invalid image_type '%s' passed" % image_type)) raise webob.exc.HTTPBadRequest() - return dict(image=self.get_builder(req).build(image, detail=True)) def get_builder(self, request): -- cgit From c5745c0cb61bb6ab375a1e52d5e203a7a0a76366 Mon Sep 17 00:00:00 2001 From: Kirill Shileev Date: Fri, 24 Jun 2011 20:59:32 +0400 Subject: associate diassociate untested, first attept to test --- nova/api/openstack/contrib/floating_ips.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index dc048869c..23864c352 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -43,7 +43,7 @@ def _translate_floating_ips_view(floating_ips): class FloatingIPController(object): - """The Volumes API controller for the OpenStack API.""" + """The Floating IPs API controller for the OpenStack API.""" _serialization_metadata = { 'application/xml': { @@ -98,15 +98,32 @@ class FloatingIPController(object): return {'released': ip} - def associate(self, req, id, body): + def associate(self, req, id_ip, body): + """ /floating_ips/ip or id/associate fixed ip in body """ context = req.environ['nova.context'] + floating_ip = self._get_ip_by_id(context, id_ip) - return {'associate': None} + fixed_ip = body['associate_address']['fixed_ip'] - def disassociate(self, req, id, body): + try: + self.network_api.associate_floating_ip(context, floating_ip, fixed_ip) + except rpc.RemoteError: + raise + + return {'associated': [floating_ip, fixed_ip]} + + def disassociate(self, req, id_ip, body): + """ POST /floating_ips/{ip | ip_id}/disassociate """ context = req.environ['nova.context'] - return {'disassociate': None} + floating_ip = self._get_ip_by_id(context, id_ip) + + try: + self.network_api.disassociate_floating_ip(context, floating_ip) + except rpc.RemoteError: + raise + + return {'disassociated': floating_ip} def _get_ip_by_id(self, context, value): """Checks that value is id and then returns its address. -- cgit From 09d439cd74290a6b2532376afc94d2c8e23cdda6 Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Fri, 24 Jun 2011 23:55:18 +0400 Subject: stub tests --- nova/api/openstack/contrib/floating_ips.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index 23864c352..924b504a8 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -2,6 +2,7 @@ # Copyright 2011 OpenStack LLC. # Copyright 2011 Grid Dynamics +# Copyright 2011 Eldar Nugaev, Kirill Shileev, Ilya Alekseyev # # 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 -- cgit From 594d5c7a98f2b4e6ea2d866f10c67cbdaa88ce0c Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Fri, 24 Jun 2011 15:03:01 -0500 Subject: Refactored backup rotate. --- nova/api/openstack/images.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 5f88ede96..c535e4e26 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -118,19 +118,25 @@ class Controller(object): except KeyError: raise webob.exc.HTTPBadRequest() + image_name = get_param("name") + if image_type == "snapshot": - image_name = get_param("name") - image = self._compute_service.snapshot(context, server_id, - image_name) - elif image_type in ("daily", "weekly"): + image = self._compute_service.snapshot( + context, server_id, image_name) + elif image_type == "backup": + # NOTE(sirp): Unlike snapshot, backup is not a customer facing + # API call; rather, it's used by the internal backup scheduler if not FLAGS.allow_admin_api: raise webob.exc.HTTPBadRequest() + backup_type = get_param("backup_type") rotation = int(get_param("rotation")) - image = self._compute_service.backup(context, server_id, - image_type, rotation) + + image = self._compute_service.backup( + context, server_id, image_name, + backup_type, rotation) else: - LOG.error(_("Invalid image_type '%s' passed" % image_type)) + LOG.error(_("Invalid image_type '%s' passed") % image_type) raise webob.exc.HTTPBadRequest() return dict(image=self.get_builder(req).build(image, detail=True)) -- cgit From a770864d308242bfcfa8dadb210595785d8fa71f Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Sat, 25 Jun 2011 02:42:27 +0400 Subject: tests --- nova/api/openstack/contrib/floating_ips.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index c6bc85c61..95502a5c5 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -104,10 +104,10 @@ class FloatingIPController(object): "id": ip['id'], "floating_ip": ip['address']}} - def associate(self, req, id_ip, body): + def associate(self, req, id, body): """ /floating_ips/{id}/associate fixed ip in body """ context = req.environ['nova.context'] - floating_ip = self._get_ip_by_id(context, id_ip) + floating_ip = self._get_ip_by_id(context, id) fixed_ip = body['associate_address']['fixed_ip'] @@ -117,13 +117,17 @@ class FloatingIPController(object): except rpc.RemoteError: raise - return {'associated': [floating_ip, fixed_ip]} + return {'associated': + { + "floating_ip_id": id, + "floating_ip": floating_ip, + "fixed_ip": fixed_ip}} - def disassociate(self, req, id_ip, body): + def disassociate(self, req, id, body): """ POST /floating_ips/{id}/disassociate """ context = req.environ['nova.context'] - floating_ip = self._get_ip_by_id(context, id_ip) + floating_ip = self._get_ip_by_id(context, id) try: self.network_api.disassociate_floating_ip(context, floating_ip) -- cgit From 5e4d90b33ddb993294232eea168a768486ba0bf4 Mon Sep 17 00:00:00 2001 From: Eldar Nugaev Date: Sat, 25 Jun 2011 03:05:09 +0400 Subject: added disassociate method to tests --- nova/api/openstack/contrib/floating_ips.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index 95502a5c5..467b46712 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -91,7 +91,7 @@ class FloatingIPController(object): raise return {'allocated': { - "id" : ip['id'], + "id": ip['id'], "floating_ip": ip['address']}} def delete(self, req, id): @@ -126,15 +126,17 @@ class FloatingIPController(object): def disassociate(self, req, id, body): """ POST /floating_ips/{id}/disassociate """ context = req.environ['nova.context'] - - floating_ip = self._get_ip_by_id(context, id) + floating_ip = self.network_api.get(context, id) + address = floating_ip['address'] + fixed_ip = floating_ip['fixed_ip']['address'] try: - self.network_api.disassociate_floating_ip(context, floating_ip) + self.network_api.disassociate_floating_ip(context, address) except rpc.RemoteError: raise - return {'disassociated': floating_ip} + return {'disassociated': {'floating_ip': address, + 'fixed_ip': fixed_ip}} def _get_ip_by_id(self, context, value): """Checks that value is id and then returns its address.""" -- cgit From ef1f4d33fa5763ea602c2fc1098a4b230b86e82b Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Mon, 27 Jun 2011 16:33:01 +0400 Subject: review issues fixed --- nova/api/openstack/contrib/floating_ips.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index 467b46712..ca192f501 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -65,7 +65,7 @@ class FloatingIPController(object): context = req.environ['nova.context'] try: - floating_ip = self.network_api.get(context, id) + floating_ip = self.network_api.get_floating_ip(context, id) except exception.NotFound: return faults.Fault(exc.HTTPNotFound()) @@ -74,7 +74,7 @@ class FloatingIPController(object): def index(self, req): context = req.environ['nova.context'] - floating_ips = self.network_api.list(context) + floating_ips = self.network_api.list_floating_ips(context) return _translate_floating_ips_view(floating_ips) @@ -97,7 +97,7 @@ class FloatingIPController(object): def delete(self, req, id): context = req.environ['nova.context'] - ip = self.network_api.get(context, id) + ip = self.network_api.get_floating_ip(context, id) self.network_api.release_floating_ip(context, address=ip) return {'released': { @@ -126,7 +126,7 @@ class FloatingIPController(object): def disassociate(self, req, id, body): """ POST /floating_ips/{id}/disassociate """ context = req.environ['nova.context'] - floating_ip = self.network_api.get(context, id) + floating_ip = self.network_api.get_floating_ip(context, id) address = floating_ip['address'] fixed_ip = floating_ip['fixed_ip']['address'] @@ -140,7 +140,7 @@ class FloatingIPController(object): def _get_ip_by_id(self, context, value): """Checks that value is id and then returns its address.""" - return self.network_api.get(context, value)['address'] + return self.network_api.get_floating_ip(context, value)['address'] class Floating_ips(extensions.ExtensionDescriptor): @@ -148,7 +148,7 @@ class Floating_ips(extensions.ExtensionDescriptor): return "Floating_ips" def get_alias(self): - return "FLOATING_IPS" + return "os-floating-ips" def get_description(self): return "Floating IPs support" @@ -163,10 +163,10 @@ class Floating_ips(extensions.ExtensionDescriptor): resources = [] res = extensions.ResourceExtension('floating_ips', - FloatingIPController(), - member_actions={ - 'associate': 'POST', - 'disassociate': 'POST'}) + FloatingIPController(), + member_actions={ + 'associate': 'POST', + 'disassociate': 'POST'}) resources.append(res) return resources -- cgit From 8df250af09b6319d5dc70d42469121f04401548f Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 27 Jun 2011 11:29:29 -0400 Subject: making key in images metadata xml serialization test null as well --- nova/api/openstack/image_metadata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/image_metadata.py b/nova/api/openstack/image_metadata.py index 7b138dc27..d72a9e0a4 100644 --- a/nova/api/openstack/image_metadata.py +++ b/nova/api/openstack/image_metadata.py @@ -117,7 +117,7 @@ class ImageMetadataXMLSerializer(wsgi.XMLDictSerializer): def _meta_item_to_xml(self, doc, key, value): node = doc.createElement('meta') - node.setAttribute('key', key) + node.setAttribute('key', str(key)) text = doc.createTextNode(str(value)) node.appendChild(text) return node -- cgit From 7c4f83bc8f119ff4486f913bd3e5ef7eff5b338f Mon Sep 17 00:00:00 2001 From: Eldar Nugaev Date: Mon, 27 Jun 2011 20:36:53 +0400 Subject: changed extension alias to os-floating-ips --- nova/api/openstack/contrib/floating_ips.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/floating_ips.py b/nova/api/openstack/contrib/floating_ips.py index ca192f501..914ec5bfb 100644 --- a/nova/api/openstack/contrib/floating_ips.py +++ b/nova/api/openstack/contrib/floating_ips.py @@ -162,7 +162,7 @@ class Floating_ips(extensions.ExtensionDescriptor): def get_resources(self): resources = [] - res = extensions.ResourceExtension('floating_ips', + res = extensions.ResourceExtension('os-floating-ips', FloatingIPController(), member_actions={ 'associate': 'POST', -- cgit From 2ba837877344bc791d7361f622be288c1870ffda Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 28 Jun 2011 11:59:46 -0400 Subject: adding unicode support to image metadata --- nova/api/openstack/image_metadata.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/image_metadata.py b/nova/api/openstack/image_metadata.py index d72a9e0a4..638b1ec15 100644 --- a/nova/api/openstack/image_metadata.py +++ b/nova/api/openstack/image_metadata.py @@ -117,8 +117,9 @@ class ImageMetadataXMLSerializer(wsgi.XMLDictSerializer): def _meta_item_to_xml(self, doc, key, value): node = doc.createElement('meta') - node.setAttribute('key', str(key)) - text = doc.createTextNode(str(value)) + doc.appendChild(node) + node.setAttribute('key', '%s' % key) + text = doc.createTextNode('%s' % value) node.appendChild(text) return node @@ -133,8 +134,9 @@ class ImageMetadataXMLSerializer(wsgi.XMLDictSerializer): xml_doc = minidom.Document() items = metadata_dict['metadata'].items() container_node = self.meta_list_to_xml(xml_doc, items) + xml_doc.appendChild(container_node) self._add_xmlns(container_node) - return container_node.toprettyxml(indent=' ') + return xml_doc.toprettyxml(indent=' ', encoding='UTF-8') def index(self, metadata_dict): return self._meta_list_to_xml_string(metadata_dict) @@ -146,8 +148,9 @@ class ImageMetadataXMLSerializer(wsgi.XMLDictSerializer): xml_doc = minidom.Document() item_key, item_value = meta_item_dict.items()[0] item_node = self._meta_item_to_xml(xml_doc, item_key, item_value) + xml_doc.appendChild(item_node) self._add_xmlns(item_node) - return item_node.toprettyxml(indent=' ') + return xml_doc.toprettyxml(indent=' ', encoding='UTF-8') def show(self, meta_item_dict): return self._meta_item_to_xml_string(meta_item_dict['meta']) -- cgit From 2916aa40f6dc0b06217ff7d3750ecdd3bb03e4fd Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Tue, 28 Jun 2011 16:03:41 -0500 Subject: Review feedback. --- nova/api/openstack/images.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index 44d8c94a4..7ebf58023 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -105,7 +105,8 @@ class Controller(object): try: return body["image"][param] except KeyError: - raise webob.exc.HTTPBadRequest() + raise webob.exc.HTTPBadRequest(explanation="Missing required " + "param: %s" % param) context = req.environ['nova.context'] content_type = req.get_content_type() @@ -131,7 +132,8 @@ class Controller(object): # NOTE(sirp): Unlike snapshot, backup is not a customer facing # API call; rather, it's used by the internal backup scheduler if not FLAGS.allow_admin_api: - raise webob.exc.HTTPBadRequest() + raise webob.exc.HTTPBadRequest( + explanation="Admin API Required") backup_type = get_param("backup_type") rotation = int(get_param("rotation")) @@ -141,7 +143,8 @@ class Controller(object): backup_type, rotation, extra_properties=props) else: LOG.error(_("Invalid image_type '%s' passed") % image_type) - raise webob.exc.HTTPBadRequest() + raise webob.exc.HTTPBadRequest(explanation="Invalue image_type: " + "%s" % image_type) return dict(image=self.get_builder(req).build(image, detail=True)) -- cgit From 74c222b6b4042053cc8c2d0038f37b3f8ee8b9fc Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Wed, 29 Jun 2011 14:52:56 -0400 Subject: don't pass zero in to glance image service if no limit or marker are present --- nova/api/openstack/common.py | 37 +++++++++++++++++-------------------- nova/api/openstack/images.py | 12 ++++++------ 2 files changed, 23 insertions(+), 26 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 4da7ec0ef..aa8911b62 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -45,23 +45,20 @@ def get_pagination_params(request): exc.HTTPBadRequest() exceptions to be raised. """ - try: - marker = int(request.GET.get('marker', 0)) - except ValueError: - raise webob.exc.HTTPBadRequest(_('marker param must be an integer')) - - try: - limit = int(request.GET.get('limit', 0)) - except ValueError: - raise webob.exc.HTTPBadRequest(_('limit param must be an integer')) - - if limit < 0: - raise webob.exc.HTTPBadRequest(_('limit param must be positive')) - - if marker < 0: - raise webob.exc.HTTPBadRequest(_('marker param must be positive')) - - return(marker, limit) + params = {} + for param in ['marker', 'limit']: + if not param in request.GET: + continue + try: + params[param] = int(request.GET[param]) + except ValueError: + msg = _('%s param must be an integer') % param + raise webob.exc.HTTPBadRequest(msg) + if params[param] < 0: + msg = _('%s param must be positive') % param + raise webob.exc.HTTPBadRequest(msg) + + return params def limited(items, request, max_limit=FLAGS.osapi_max_limit): @@ -100,10 +97,10 @@ def limited(items, request, max_limit=FLAGS.osapi_max_limit): def limited_by_marker(items, request, max_limit=FLAGS.osapi_max_limit): """Return a slice of items according to the requested marker and limit.""" - (marker, limit) = get_pagination_params(request) + params = get_pagination_params(request) - if limit == 0: - limit = max_limit + limit = params.get('limit', max_limit) + marker = params.get('marker') limit = min(max_limit, limit) start_index = 0 diff --git a/nova/api/openstack/images.py b/nova/api/openstack/images.py index d43340e10..64d003a0f 100644 --- a/nova/api/openstack/images.py +++ b/nova/api/openstack/images.py @@ -181,9 +181,9 @@ class ControllerV11(Controller): """ context = req.environ['nova.context'] filters = self._get_filters(req) - (marker, limit) = common.get_pagination_params(req) - images = self._image_service.index( - context, filters=filters, marker=marker, limit=limit) + page_params = common.get_pagination_params(req) + images = self._image_service.index(context, filters=filters, + **page_params) builder = self.get_builder(req).build return dict(images=[builder(image, detail=False) for image in images]) @@ -195,9 +195,9 @@ class ControllerV11(Controller): """ context = req.environ['nova.context'] filters = self._get_filters(req) - (marker, limit) = common.get_pagination_params(req) - images = self._image_service.detail( - context, filters=filters, marker=marker, limit=limit) + page_params = common.get_pagination_params(req) + images = self._image_service.detail(context, filters=filters, + **page_params) builder = self.get_builder(req).build return dict(images=[builder(image, detail=True) for image in images]) -- cgit From 851802e772095b646a7570bf0cc0c6d32be4643c Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 29 Jun 2011 12:23:26 -0700 Subject: Fixed indentation issues Fixed min/max_count checking issues Fixed a wrongly log message when zone aware scheduler finds no suitable hosts --- nova/api/openstack/create_instance_helper.py | 11 +++++++++-- nova/api/openstack/servers.py | 12 ++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 4c6cc0f83..2cc38911a 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -116,9 +116,16 @@ class CreateInstanceHelper(object): reservation_id = body['server'].get('reservation_id') min_count = body['server'].get('min_count') max_count = body['server'].get('max_count') - if min_count: + # min_count and max_count are optional. If they exist, they come + # in as strings. We want to default 'min_count' to 1, and default + # 'max_count' to be 'min_count'. + if not min_count: + min_count = 1 + else: min_count = int(min_count) - if max_count: + if not max_count: + max_count = min_count + else: max_count = int(max_count) if min_count > max_count: min_count = max_count diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index decbfd6e6..66ef97af0 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -83,11 +83,11 @@ class Controller(object): recurse_zones = query_str.get('recurse_zones') recurse_zones = recurse_zones and True or False instance_list = self.compute_api.get_all( - req.environ['nova.context'], - reservation_id=reservation_id, - project_id=project_id, - fixed_ip=fixed_ip, - recurse_zones=recurse_zones) + req.environ['nova.context'], + reservation_id=reservation_id, + project_id=project_id, + fixed_ip=fixed_ip, + recurse_zones=recurse_zones) limited_list = self._limit_items(instance_list, req) builder = self._get_view_builder(req) servers = [builder.build(inst, is_detail)['server'] @@ -120,7 +120,7 @@ class Controller(object): result = None try: extra_values, instances = self.helper.create_instance( - req, body, self.compute_api.create) + req, body, self.compute_api.create) except faults.Fault, f: return f -- cgit From 7555aca28a5ab1ba4dd1be04a91bf6347eaac84f Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Wed, 29 Jun 2011 15:22:56 -0700 Subject: fix issue of recurse_zones not being converted to bool properly add bool_from_str util call add test for bool_from_str slight rework of min/max_count check --- nova/api/openstack/create_instance_helper.py | 10 ++-------- nova/api/openstack/servers.py | 3 +-- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 2cc38911a..1066713a3 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -119,14 +119,8 @@ class CreateInstanceHelper(object): # min_count and max_count are optional. If they exist, they come # in as strings. We want to default 'min_count' to 1, and default # 'max_count' to be 'min_count'. - if not min_count: - min_count = 1 - else: - min_count = int(min_count) - if not max_count: - max_count = min_count - else: - max_count = int(max_count) + min_count = int(min_count) if min_count else 1 + max_count = int(max_count) if max_count else min_count if min_count > max_count: min_count = max_count diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index 66ef97af0..fc1ab8d46 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -80,8 +80,7 @@ class Controller(object): reservation_id = query_str.get('reservation_id') project_id = query_str.get('project_id') fixed_ip = query_str.get('fixed_ip') - recurse_zones = query_str.get('recurse_zones') - recurse_zones = recurse_zones and True or False + recurse_zones = utils.bool_from_str(query_str.get('recurse_zones')) instance_list = self.compute_api.get_all( req.environ['nova.context'], reservation_id=reservation_id, -- cgit From 81ea3d5fc47bed84c5f4bf722b02dfa58792e19e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 29 Jun 2011 18:26:51 -0400 Subject: Updated v1.1 links in flavors to represent the curret spec --- nova/api/openstack/views/flavors.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 462890ab2..beef67a88 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -79,12 +79,10 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", "href": href, }, { "rel": "bookmark", - "type": "application/xml", "href": href, }, ] -- cgit From d1c5b8c9a5c54a7000d21451ff4649b1a772dfad Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Wed, 29 Jun 2011 22:50:39 -0400 Subject: Update the ec2 get_metadata handler so it works with the most recent version of the compute API get_all call which now returns a list if there is only a single record. --- nova/api/ec2/cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 9aaf37a2d..25aeceea6 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -152,7 +152,7 @@ class CloudController(object): # This ensures that all attributes of the instance # are populated. - instance_ref = db.instance_get(ctxt, instance_ref['id']) + instance_ref = db.instance_get(ctxt, instance_ref[0]['id']) mpi = self._get_mpi_data(ctxt, instance_ref['project_id']) if instance_ref['key_name']: -- cgit From 8133b9af105f7924f03b710b30cf4f0acb52f143 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 10:29:31 -0400 Subject: refactored flavors viewbuilder --- nova/api/openstack/views/flavors.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index beef67a88..4e609930c 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -71,6 +71,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, flavor_obj): """Generate a container of links that refer to the provided flavor.""" href = self.generate_href(flavor_obj["id"]) + bookmark = self.generate_bookmark(flavor_obj["id"]) links = [ { @@ -79,11 +80,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "href": href, - }, - { - "rel": "bookmark", - "href": href, + "href": bookmark, }, ] @@ -92,3 +89,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, flavor_id): """Create an url that refers to a specific flavor id.""" return "%s/flavors/%s" % (self.base_url, flavor_id) + + def generate_bookmark(self, flavor_id): + """Create an url that refers to a specific flavor id.""" + return "%s/flavors/%s" % (self._remove_version(self.base_url), + flavor_id) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) -- cgit From 5f772ea10c22549a7149f608cfc2ff932878d6fe Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:18:19 -0400 Subject: updated servers --- nova/api/openstack/views/servers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index cbfa5aae7..1c6dbf87d 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -156,6 +156,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, response, inst): href = self.generate_href(inst["id"]) + bookmark = self.generate_bookmark(inst["id"]) links = [ { @@ -164,13 +165,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }, ] @@ -179,3 +174,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, server_id): """Create an url that refers to a specific server id.""" return os.path.join(self.base_url, "servers", str(server_id)) + + def generate_bookmark(self, server_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self.base_url), + "servers", str(server_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) -- cgit From 386e2a28f2d92dea30a726722b49e97e1c7ebba7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:29:45 -0400 Subject: updated images --- nova/api/openstack/views/images.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index d6a054102..175bcb109 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -104,6 +104,7 @@ class ViewBuilderV11(ViewBuilder): """Return a standardized image structure for display by the API.""" image = ViewBuilder.build(self, image_obj, detail) href = self.generate_href(image_obj["id"]) + bookmark = self.generate_bookmark(image_obj["id"]) image["links"] = [{ "rel": "self", @@ -111,13 +112,15 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }] return image + + def generate_bookmark(self, image_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self._url), + "images", str(image_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) -- cgit From bad24563babf34668a4a2fcbd883c3e2c6fee5f2 Mon Sep 17 00:00:00 2001 From: Trey Morris Date: Thu, 30 Jun 2011 14:42:51 -0500 Subject: updated osapi 1.0 addresses view to work with multiple fixed ips --- nova/api/openstack/views/addresses.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/views/addresses.py b/nova/api/openstack/views/addresses.py index dc9e23450..b59eb4751 100644 --- a/nova/api/openstack/views/addresses.py +++ b/nova/api/openstack/views/addresses.py @@ -33,14 +33,15 @@ class ViewBuilderV10(ViewBuilder): return dict(public=public_ips, private=private_ips) def build_public_parts(self, inst): - return utils.get_from_path(inst, 'fixed_ip/floating_ips/address') + return utils.get_from_path(inst, 'fixed_ips/floating_ips/address') def build_private_parts(self, inst): - return utils.get_from_path(inst, 'fixed_ip/address') + return utils.get_from_path(inst, 'fixed_ips/address') class ViewBuilderV11(ViewBuilder): def build(self, inst): + # TODO(tr3buchet) - this shouldn't be hard coded to 4... private_ips = utils.get_from_path(inst, 'fixed_ips/address') private_ips = [dict(version=4, addr=a) for a in private_ips] public_ips = utils.get_from_path(inst, -- cgit From 7ca20797496947c0bdd60e77b4962fd360e01f55 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 13:44:12 +0000 Subject: after trunk merge --- nova/api/openstack/auth.py | 1 + nova/api/openstack/wsgi.py | 1 + 2 files changed, 2 insertions(+) (limited to 'nova/api') diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/auth.py index 7c3e683d6..6231216c9 100644 --- a/nova/api/openstack/auth.py +++ b/nova/api/openstack/auth.py @@ -100,6 +100,7 @@ class AuthMiddleware(wsgi.Middleware): token, user = self._authorize_user(username, key, req) if user and token: + print "TOKEN:", token['token_hash'] res = webob.Response() res.headers['X-Auth-Token'] = token['token_hash'] res.headers['X-Server-Management-Url'] = \ diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index 5b6e3cb1d..ba8ee8bfd 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -362,6 +362,7 @@ class Resource(wsgi.Application): "url": request.url}) try: + print "BODY: >%s<"%request.body action, action_args, accept = self.deserializer.deserialize( request) except exception.InvalidContentType: -- cgit From 49c8202f43b9f606d9bd0a362b5805be98460326 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 19:53:06 +0000 Subject: removed debugging output --- nova/api/openstack/wsgi.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index ba8ee8bfd..5b6e3cb1d 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -362,7 +362,6 @@ class Resource(wsgi.Application): "url": request.url}) try: - print "BODY: >%s<"%request.body action, action_args, accept = self.deserializer.deserialize( request) except exception.InvalidContentType: -- cgit From 2dc2a5f66dc039ff1755981374f4065d048bcc26 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Fri, 1 Jul 2011 20:33:00 +0000 Subject: removed more stray debug output --- nova/api/openstack/auth.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/api') diff --git a/nova/api/openstack/auth.py b/nova/api/openstack/auth.py index 6231216c9..7c3e683d6 100644 --- a/nova/api/openstack/auth.py +++ b/nova/api/openstack/auth.py @@ -100,7 +100,6 @@ class AuthMiddleware(wsgi.Middleware): token, user = self._authorize_user(username, key, req) if user and token: - print "TOKEN:", token['token_hash'] res = webob.Response() res.headers['X-Auth-Token'] = token['token_hash'] res.headers['X-Server-Management-Url'] = \ -- cgit From 7307f17edeb284a6b2da076ffa16b2ef5c82a4f4 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Mon, 4 Jul 2011 15:41:37 +0000 Subject: Added missing extension file and tests. Also modified the get_host_list() docstring to be more accurate about the return value. --- nova/api/openstack/contrib/hosts.py | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 nova/api/openstack/contrib/hosts.py (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py new file mode 100644 index 000000000..40a260c20 --- /dev/null +++ b/nova/api/openstack/contrib/hosts.py @@ -0,0 +1,112 @@ +# Copyright (c) 2011 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. + +"""The hosts admin extension.""" + +from webob import exc + +from nova import compute +from nova import exception +from nova import flags +from nova import log as logging +from nova.api.openstack import common +from nova.api.openstack import extensions +from nova.api.openstack import faults +from nova.scheduler import api as scheduler_api + + +LOG = logging.getLogger("nova.api.hosts") +FLAGS = flags.FLAGS + + +def _list_hosts(req, service=None): + """Returns a summary list of hosts, optionally filtering + by service type. + """ + context = req.environ['nova.context'] + hosts = scheduler_api.get_host_list(context) + if service: + hosts = [host for host in hosts + if host["service"] == service] + return hosts + + +def check_host(fn): + """Makes sure that the host exists.""" + def wrapped(self, req, id, service=None, *args, **kwargs): + listed_hosts = _list_hosts(req, service) + hosts = [h["host_name"] for h in listed_hosts] + if id in hosts: + return fn(self, req, id, *args, **kwargs) + else: + raise exception.HostNotFound(host=id) + return wrapped + + +class HostController(object): + """The Hosts API controller for the OpenStack API.""" + def __init__(self): + self.compute_api = compute.API() + super(HostController, self).__init__() + + def index(self, req): + return {'hosts': _list_hosts(req)} + + @check_host + def update(self, req, id, body): + for raw_key, raw_val in body.iteritems(): + key = raw_key.lower().strip() + val = raw_val.lower().strip() + # NOTE: (dabo) Right now only 'status' can be set, but other + # actions may follow. + if key == "status": + if val in ("enable", "disable"): + return self._set_enabled_status(req, id, + enabled=(val == "enable")) + else: + raise ValueError(_("Invalid status: '%s'") % raw_val) + else: + raise ValueError(_("Invalid update setting: '%s'") % raw_key) + + def _set_enabled_status(self, req, host, enabled): + """Sets the specified host's ability to accept new instances.""" + context = req.environ['nova.context'] + state = "enabled" if enabled else "disabled" + LOG.audit(_("Setting host %(host)s to %(state)s.") % locals()) + result = self.compute_api.set_host_enabled(context, host=host, + enabled=enabled) + return {"host": host, "status": result} + + +class Hosts(extensions.ExtensionDescriptor): + def get_name(self): + return "Hosts" + + def get_alias(self): + return "os-hosts" + + def get_description(self): + return "Host administration" + + def get_namespace(self): + return "http://docs.openstack.org/ext/hosts/api/v1.1" + + def get_updated(self): + return "2011-06-29T00:00:00+00:00" + + def get_resources(self): + resources = [extensions.ResourceExtension('os-hosts', HostController(), + collection_actions={'update': 'PUT'}, member_actions={})] + return resources -- cgit From 6435ba27edea7e525305d349cafea3d08f5db2c6 Mon Sep 17 00:00:00 2001 From: Ed Leafe Date: Wed, 6 Jul 2011 16:53:08 +0000 Subject: Changed the exception type for invalid requests to webob.exc.HTTPBadRequest. --- nova/api/openstack/contrib/hosts.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py index 40a260c20..55e57e1a4 100644 --- a/nova/api/openstack/contrib/hosts.py +++ b/nova/api/openstack/contrib/hosts.py @@ -15,7 +15,7 @@ """The hosts admin extension.""" -from webob import exc +import webob.exc from nova import compute from nova import exception @@ -72,13 +72,15 @@ class HostController(object): # NOTE: (dabo) Right now only 'status' can be set, but other # actions may follow. if key == "status": - if val in ("enable", "disable"): + if val[:6] in ("enable", "disabl"): return self._set_enabled_status(req, id, - enabled=(val == "enable")) + enabled=(val.startswith("enable"))) else: - raise ValueError(_("Invalid status: '%s'") % raw_val) + explanation = _("Invalid status: '%s'") % raw_val + raise webob.exc.HTTPBadRequest(explanation=explanation) else: - raise ValueError(_("Invalid update setting: '%s'") % raw_key) + explanation = _("Invalid update setting: '%s'") % raw_key + raise webob.exc.HTTPBadRequest(explanation=explanation) def _set_enabled_status(self, req, host, enabled): """Sets the specified host's ability to accept new instances.""" -- cgit From a92158cee2a57316252ec6fd0d6c0c4f1e7a1fcf Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:26:25 -0400 Subject: moved remove_version to common.py --- nova/api/openstack/common.py | 3 +++ nova/api/openstack/views/flavors.py | 5 +---- nova/api/openstack/views/images.py | 7 +++---- nova/api/openstack/views/servers.py | 5 +---- 4 files changed, 8 insertions(+), 12 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index aa8911b62..8794bca6d 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -134,3 +134,6 @@ def get_id_from_href(href): except: LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) + +def remove_version(base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 4e609930c..d967c2af0 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,8 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (self._remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version(self.base_url), flavor_id) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 5ab02671c..9d6722326 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -17,6 +17,8 @@ import os.path +from nova.api.openstack import common + class ViewBuilder(object): """Base class for generating responses to OpenStack API image requests.""" @@ -122,8 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self._url), + return os.path.join(common.remove_version(self._url), "images", str(image_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 1c6dbf87d..b85fceb19 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,8 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self.base_url), + return os.path.join(common.remove_version(self.base_url), "servers", str(server_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) -- cgit From bf851c7f403c7be8d8f27274fa5216cfa6eaf4f4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:42:13 -0400 Subject: Renamed function --- nova/api/openstack/common.py | 9 ++++++++- nova/api/openstack/views/flavors.py | 2 +- nova/api/openstack/views/images.py | 2 +- nova/api/openstack/views/servers.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 8794bca6d..48773291c 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -135,5 +135,12 @@ def get_id_from_href(href): LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) -def remove_version(base_url): + +def remove_version_from_href(base_url): + """Removes the api version from the href. + + Given: 'http://www.nova.com/v1.1/123' + Returns: 'http://www.nova.com/123' + + """ return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d967c2af0..d2f7e3e56 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), flavor_id) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 9d6722326..005341c62 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -124,5 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self._url), + return os.path.join(common.remove_version_from_href(self._url), "images", str(image_id)) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index b85fceb19..67fb6a84e 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,5 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self.base_url), + return os.path.join(common.remove_version_from_href(self.base_url), "servers", str(server_id)) -- cgit From 19e4cef2518e2c1e02e27137cadea55861d092c4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 10:02:06 -0400 Subject: pep8 --- nova/api/openstack/common.py | 2 +- nova/api/openstack/views/flavors.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 48773291c..9aa384f33 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -138,7 +138,7 @@ def get_id_from_href(href): def remove_version_from_href(base_url): """Removes the api version from the href. - + Given: 'http://www.nova.com/v1.1/123' Returns: 'http://www.nova.com/123' diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d2f7e3e56..0403ece1b 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,7 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), - flavor_id) + return "%s/flavors/%s" % ( + common.remove_version_from_href(self.base_url), + flavor_id, + ) -- cgit