Merge "Add backups v3 views"
This commit is contained in:
commit
4fcbe71aab
@ -21,6 +21,7 @@ from webob import exc
|
||||
from cinder.api.contrib import backups as backups_v2
|
||||
from cinder.api import microversions as mv
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v3.views import backups as backup_views
|
||||
from cinder.backup import api as backup_api
|
||||
from cinder import exception
|
||||
from cinder.i18n import _
|
||||
@ -32,6 +33,8 @@ LOG = logging.getLogger(__name__)
|
||||
class BackupsController(backups_v2.BackupsController):
|
||||
"""The backups API controller for the OpenStack API V3."""
|
||||
|
||||
_view_builder_class = backup_views.ViewBuilder
|
||||
|
||||
@wsgi.Controller.api_version(mv.BACKUP_UPDATE)
|
||||
def update(self, req, id, body):
|
||||
"""Update a backup."""
|
||||
|
32
cinder/api/v3/views/backups.py
Normal file
32
cinder/api/v3/views/backups.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Copyright 2017 FiberHome Telecommunication Technologies CO.,LTD
|
||||
# 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 cinder.api import microversions as mv
|
||||
from cinder.api.views import backups as views_v2
|
||||
|
||||
|
||||
class ViewBuilder(views_v2.ViewBuilder):
|
||||
"""Model a backups API V3 response as a python dictionary."""
|
||||
|
||||
def detail(self, request, backup):
|
||||
"""Detailed view of a single backup."""
|
||||
backup_ref = super(ViewBuilder, self).detail(request, backup)
|
||||
|
||||
# Add metadata if min version is greater than or equal to
|
||||
# BACKUP_METADATA.
|
||||
req_version = request.api_version_request
|
||||
if req_version.matches(mv.BACKUP_METADATA):
|
||||
backup_ref['backup']['metadata'] = backup.metadata
|
||||
return backup_ref
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
from cinder.api import common
|
||||
from cinder.api import microversions as mv
|
||||
|
||||
|
||||
class ViewBuilder(common.ViewBuilder):
|
||||
@ -78,9 +77,7 @@ class ViewBuilder(common.ViewBuilder):
|
||||
'data_timestamp': backup.data_timestamp,
|
||||
}
|
||||
}
|
||||
req_version = request.api_version_request
|
||||
if req_version.matches(mv.BACKUP_METADATA):
|
||||
backup_dict['backup']['metadata'] = backup.metadata
|
||||
|
||||
return backup_dict
|
||||
|
||||
def _list_view(self, func, request, backups, backup_count):
|
||||
|
@ -146,3 +146,18 @@ class BackupsControllerAPITestCase(test.TestCase):
|
||||
self.assertEqual(new_name, backup.display_name)
|
||||
self.assertEqual(new_description,
|
||||
backup.display_description)
|
||||
|
||||
@ddt.data(mv.get_prior_version(mv.BACKUP_METADATA),
|
||||
mv.BACKUP_METADATA)
|
||||
def test_backup_show_with_metadata(self, version):
|
||||
backup = test_utils.create_backup(
|
||||
self.ctxt, display_name='test_backup_metadata',
|
||||
status=fields.BackupStatus.AVAILABLE)
|
||||
# show backup metadata
|
||||
url = '/v3/%s/backups/%s' % (fake.PROJECT_ID, backup.id)
|
||||
req = fakes.HTTPRequest.blank(url, version=version)
|
||||
backup_get = self.controller.show(req, backup.id)['backup']
|
||||
if version == mv.get_prior_version(mv.BACKUP_METADATA):
|
||||
self.assertNotIn('metadata', backup_get)
|
||||
else:
|
||||
self.assertIn('metadata', backup_get)
|
||||
|
Loading…
x
Reference in New Issue
Block a user