Revert "Remove flavor API"

Story: 2008309
Task: 41201

This reverts commit 910519127d.

Change-Id: I77b72a965153e9583d93dee1f3a77d01a57e4ca2
This commit is contained in:
Sam Morrison
2020-11-03 18:16:43 +11:00
committed by Lingxian Kong
parent 71d99e2c56
commit 3aa0c32815
5 changed files with 74 additions and 2 deletions

View File

@@ -102,7 +102,10 @@ class ClusterView(object):
return None
def _build_flavor_info(self, flavor_id):
return {"id": flavor_id}
return {
"id": flavor_id,
"links": create_links("flavors", self.req, flavor_id)
}
class ClusterInstanceDetailView(InstanceDetailView):

View File

@@ -21,6 +21,7 @@ from trove.common import wsgi
from trove.configuration.service import ConfigurationsController
from trove.configuration.service import ParametersController
from trove.datastore.service import DatastoreController
from trove.flavor.service import FlavorController
from trove.instance.service import InstanceController
from trove.limits.service import LimitsController
from trove.module.service import ModuleController
@@ -35,6 +36,7 @@ class API(wsgi.Router):
self._instance_router(mapper)
self._cluster_router(mapper)
self._datastore_router(mapper)
self._flavor_router(mapper)
self._versions_router(mapper)
self._limits_router(mapper)
self._backups_router(mapper)
@@ -168,6 +170,17 @@ class API(wsgi.Router):
action="delete",
conditions={'method': ['DELETE']})
def _flavor_router(self, mapper):
flavor_resource = FlavorController().create_resource()
mapper.connect("/{tenant_id}/flavors",
controller=flavor_resource,
action="index",
conditions={'method': ['GET']})
mapper.connect("/{tenant_id}/flavors/{id}",
controller=flavor_resource,
action="show",
conditions={'method': ['GET']})
def _limits_router(self, mapper):
limits_resource = LimitsController().create_resource()
mapper.connect("/{tenant_id}/limits",

51
trove/flavor/service.py Normal file
View File

@@ -0,0 +1,51 @@
# Copyright 2010-2012 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 trove.common import exception
from trove.common import policy
from trove.common import wsgi
from trove.flavor import models
from trove.flavor import views
class FlavorController(wsgi.Controller):
"""Controller for flavor functionality."""
def show(self, req, tenant_id, id):
"""Return a single flavor."""
context = req.environ[wsgi.CONTEXT_KEY]
self._validate_flavor_id(id)
flavor = models.Flavor(context=context, flavor_id=id)
# Flavors do not bind to a particular tenant.
# Only authorize the current tenant.
policy.authorize_on_tenant(context, 'flavor:show')
# Pass in the request to build accurate links.
return wsgi.Result(views.FlavorView(flavor, req).data(), 200)
def index(self, req, tenant_id):
"""Return all flavors."""
context = req.environ[wsgi.CONTEXT_KEY]
policy.authorize_on_tenant(context, 'flavor:index')
flavors = models.Flavors(context=context)
return wsgi.Result(views.FlavorsView(flavors, req).data(), 200)
def _validate_flavor_id(self, id):
if isinstance(id, str):
return
try:
if int(id) != float(id):
raise exception.NotFound(uuid=id)
except ValueError:
raise exception.NotFound(uuid=id)

View File

@@ -86,8 +86,13 @@ class InstanceView(object):
def _build_flavor_info(self):
return {
"id": self.instance.flavor_id,
"links": self._build_flavor_links()
}
def _build_flavor_links(self):
return create_links("flavors", self.req,
self.instance.flavor_id)
def _build_master_info(self):
return {
"id": self.instance.slave_of_id,

View File

@@ -195,7 +195,7 @@ class CheckInstance(AttrCheck):
if 'flavor' not in self.instance:
self.fail("'flavor' not found in instance.")
else:
allowed_attrs = ['id']
allowed_attrs = ['id', 'links']
self.contains_allowed_attrs(
self.instance['flavor'], allowed_attrs,
msg="Flavor")