Merge "Port limits extension to work in v2.1/v3 framework"

This commit is contained in:
Jenkins 2014-09-03 03:41:26 +00:00 committed by Gerrit Code Review
commit cf04c13acb
4 changed files with 72 additions and 4 deletions

View File

@ -183,6 +183,7 @@
"compute_extension:v3:os-keypairs:show": "",
"compute_extension:v3:os-keypairs:create": "",
"compute_extension:v3:os-keypairs:delete": "",
"compute_extension:v3:limits:discoverable": "",
"compute_extension:v3:os-lock-server:discoverable": "",
"compute_extension:v3:os-lock-server:lock": "rule:admin_or_owner",
"compute_extension:v3:os-lock-server:unlock": "rule:admin_or_owner",

View File

@ -0,0 +1,59 @@
# Copyright 2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.api.openstack.compute.views import limits as limits_views
from nova.api.openstack import extensions
from nova import quota
QUOTAS = quota.QUOTAS
ALIAS = 'limits'
class LimitsController(object):
"""Controller for accessing limits in the OpenStack API."""
@extensions.expected_errors(())
def index(self, req):
"""Return all global and rate limit information."""
context = req.environ['nova.context']
project_id = req.params.get('tenant_id', context.project_id)
quotas = QUOTAS.get_project_quotas(context, project_id,
usages=False)
abs_limits = dict((k, v['limit']) for k, v in quotas.items())
rate_limits = req.environ.get("nova.limits", [])
builder = self._get_view_builder(req)
return builder.build(rate_limits, abs_limits)
def _get_view_builder(self, req):
return limits_views.ViewBuilder()
class Limits(extensions.V3APIExtensionBase):
"""Limits support."""
name = "Limits"
alias = ALIAS
version = 1
def get_resources(self):
resource = [extensions.ResourceExtension(ALIAS,
LimitsController())]
return resource
def get_controller_extensions(self):
return []

View File

@ -27,7 +27,9 @@ import six
import webob
from nova.api.openstack.compute import limits
from nova.api.openstack.compute.plugins.v3 import limits as limits_v3
from nova.api.openstack.compute import views
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
import nova.context
from nova.openstack.common import jsonutils
@ -74,14 +76,15 @@ class BaseLimitTestSuite(test.NoDBTestCase):
return self.time
class LimitsControllerTest(BaseLimitTestSuite):
class LimitsControllerTestV21(BaseLimitTestSuite):
"""Tests for `limits.LimitsController` class."""
limits_controller = limits_v3.LimitsController
def setUp(self):
"""Run before each test."""
super(LimitsControllerTest, self).setUp()
self.controller = limits.create_resource()
self.ctrler = limits.LimitsController()
super(LimitsControllerTestV21, self).setUp()
self.controller = wsgi.Resource(self.limits_controller())
self.ctrler = self.limits_controller()
def _get_index_request(self, accept_header="application/json",
tenant_id=None):
@ -211,6 +214,10 @@ class LimitsControllerTest(BaseLimitTestSuite):
get_project_quotas.assert_called_once_with(context, tenant_id,
usages=False)
class LimitsControllerTestV2(LimitsControllerTestV21):
limits_controller = limits.LimitsController
def _populate_limits_diff_regex(self, request):
"""Put limit info into a request."""
_limits = [

View File

@ -92,6 +92,7 @@ nova.api.v3.extensions =
instance_actions = nova.api.openstack.compute.plugins.v3.instance_actions:InstanceActions
ips = nova.api.openstack.compute.plugins.v3.ips:IPs
keypairs = nova.api.openstack.compute.plugins.v3.keypairs:Keypairs
limits = nova.api.openstack.compute.plugins.v3.limits:Limits
lock_server = nova.api.openstack.compute.plugins.v3.lock_server:LockServer
migrate_server = nova.api.openstack.compute.plugins.v3.migrate_server:MigrateServer
migrations = nova.api.openstack.compute.plugins.v3.migrations:Migrations