Delete dead API v2 router code
This code is no longer used now that we have switched to Pecan and have no option to switch to the legacy API framework. Change-Id: I0701dfe13024132cf5b9696560b0d027712e7739
This commit is contained in:
parent
db1058a499
commit
a3dff9769b
@ -13,54 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_config import cfg
|
||||
from oslo_service import wsgi as base_wsgi
|
||||
import routes as routes_mapper
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import webob
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base
|
||||
from neutron import manager
|
||||
from neutron.pecan_wsgi import app as pecan_app
|
||||
from neutron import policy
|
||||
from neutron.quota import resource_registry
|
||||
from neutron import wsgi
|
||||
|
||||
|
||||
RESOURCES = attributes.CORE_RESOURCES
|
||||
SUB_RESOURCES = {}
|
||||
COLLECTION_ACTIONS = ['index', 'create']
|
||||
MEMBER_ACTIONS = ['show', 'update', 'delete']
|
||||
REQUIREMENTS = {'id': constants.UUID_PATTERN, 'format': 'json'}
|
||||
|
||||
|
||||
class Index(wsgi.Application):
|
||||
def __init__(self, resources):
|
||||
self.resources = resources
|
||||
|
||||
@webob.dec.wsgify(RequestClass=wsgi.Request)
|
||||
def __call__(self, req):
|
||||
metadata = {}
|
||||
|
||||
layout = []
|
||||
for name, collection in self.resources.items():
|
||||
href = urlparse.urljoin(req.path_url, collection)
|
||||
resource = {'name': name,
|
||||
'collection': collection,
|
||||
'links': [{'rel': 'self',
|
||||
'href': href}]}
|
||||
layout.append(resource)
|
||||
response = dict(resources=layout)
|
||||
content_type = req.best_match_content_type()
|
||||
body = wsgi.Serializer(metadata=metadata).serialize(response,
|
||||
content_type)
|
||||
return webob.Response(body=body, content_type=content_type)
|
||||
|
||||
|
||||
def APIRouter(**local_config):
|
||||
@ -72,63 +26,3 @@ def _factory(global_config, **local_config):
|
||||
|
||||
|
||||
setattr(APIRouter, 'factory', _factory)
|
||||
|
||||
|
||||
class _APIRouter(base_wsgi.Router):
|
||||
|
||||
@classmethod
|
||||
def factory(cls, global_config, **local_config):
|
||||
# TODO(kevinbenton): dump this whole class
|
||||
return pecan_app.v2_factory(global_config, **local_config)
|
||||
|
||||
def __init__(self, **local_config):
|
||||
mapper = routes_mapper.Mapper()
|
||||
manager.init()
|
||||
plugin = directory.get_plugin()
|
||||
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
|
||||
ext_mgr.extend_resources("2.0", attributes.RESOURCE_ATTRIBUTE_MAP)
|
||||
|
||||
col_kwargs = dict(collection_actions=COLLECTION_ACTIONS,
|
||||
member_actions=MEMBER_ACTIONS)
|
||||
|
||||
def _map_resource(collection, resource, params, parent=None):
|
||||
allow_bulk = cfg.CONF.allow_bulk
|
||||
controller = base.create_resource(
|
||||
collection, resource, plugin, params, allow_bulk=allow_bulk,
|
||||
parent=parent, allow_pagination=True,
|
||||
allow_sorting=True)
|
||||
path_prefix = None
|
||||
if parent:
|
||||
path_prefix = "/%s/{%s_id}/%s" % (parent['collection_name'],
|
||||
parent['member_name'],
|
||||
collection)
|
||||
mapper_kwargs = dict(controller=controller,
|
||||
requirements=REQUIREMENTS,
|
||||
path_prefix=path_prefix,
|
||||
**col_kwargs)
|
||||
return mapper.collection(collection, resource,
|
||||
**mapper_kwargs)
|
||||
|
||||
mapper.connect('index', '/', controller=Index(RESOURCES))
|
||||
for resource in RESOURCES:
|
||||
_map_resource(RESOURCES[resource], resource,
|
||||
attributes.RESOURCE_ATTRIBUTE_MAP.get(
|
||||
RESOURCES[resource], dict()))
|
||||
resource_registry.register_resource_by_name(resource)
|
||||
|
||||
for resource in SUB_RESOURCES:
|
||||
_map_resource(SUB_RESOURCES[resource]['collection_name'], resource,
|
||||
attributes.RESOURCE_ATTRIBUTE_MAP.get(
|
||||
SUB_RESOURCES[resource]['collection_name'],
|
||||
dict()),
|
||||
SUB_RESOURCES[resource]['parent'])
|
||||
|
||||
# Certain policy checks require that the extensions are loaded
|
||||
# and the RESOURCE_ATTRIBUTE_MAP populated before they can be
|
||||
# properly initialized. This can only be claimed with certainty
|
||||
# once this point in the code has been reached. In the event
|
||||
# that the policies have been initialized before this point,
|
||||
# calling reset will cause the next policy check to
|
||||
# re-initialize with all of the required data in place.
|
||||
policy.reset()
|
||||
super(_APIRouter, self).__init__(mapper)
|
||||
|
@ -70,31 +70,6 @@ def _get_path(resource, id=None, action=None,
|
||||
return path
|
||||
|
||||
|
||||
class ResourceIndexTestCase(base.BaseTestCase):
|
||||
def test_index_json(self):
|
||||
index = webtest.TestApp(router.Index({'foo': 'bar'}))
|
||||
res = index.get('')
|
||||
|
||||
self.assertIn('resources', res.json)
|
||||
self.assertEqual(1, len(res.json['resources']))
|
||||
|
||||
resource = res.json['resources'][0]
|
||||
self.assertIn('collection', resource)
|
||||
self.assertEqual('bar', resource['collection'])
|
||||
|
||||
self.assertIn('name', resource)
|
||||
self.assertEqual('foo', resource['name'])
|
||||
|
||||
self.assertIn('links', resource)
|
||||
self.assertEqual(1, len(resource['links']))
|
||||
|
||||
link = resource['links'][0]
|
||||
self.assertIn('href', link)
|
||||
self.assertEqual(link['href'], 'http://localhost/bar')
|
||||
self.assertIn('rel', link)
|
||||
self.assertEqual('self', link['rel'])
|
||||
|
||||
|
||||
class APIv2TestBase(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(APIv2TestBase, self).setUp()
|
||||
|
Loading…
Reference in New Issue
Block a user