6dd3b9c51f
Add ``project_id`` to response body of list group snapshots with detail and show group snapshot detail APIs. Merging the group and group snapshot response in same MV was discussed in weekly meeting[1]. [1] http://eavesdrop.openstack.org/meetings/cinder/2019/cinder.2019-02-20-16.00.log.html#l-122 Change-Id: Ided66450b5d7de32551edbce249e94f6174da2eb Implements: blueprint add-project-id-to-group-groupsnapshot-response
85 lines
3.4 KiB
Python
85 lines
3.4 KiB
Python
# Copyright (C) 2016 EMC Corporation.
|
|
# 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 common
|
|
from cinder.api import microversions as mv
|
|
from cinder.policies import group_snapshots as policy
|
|
|
|
|
|
class ViewBuilder(common.ViewBuilder):
|
|
"""Model group_snapshot API responses as a python dictionary."""
|
|
|
|
_collection_name = "group_snapshots"
|
|
|
|
def __init__(self):
|
|
"""Initialize view builder."""
|
|
super(ViewBuilder, self).__init__()
|
|
|
|
def summary_list(self, request, group_snapshots):
|
|
"""Show a list of group_snapshots without many details."""
|
|
return self._list_view(self.summary, request, group_snapshots)
|
|
|
|
def detail_list(self, request, group_snapshots):
|
|
"""Detailed view of a list of group_snapshots ."""
|
|
return self._list_view(self.detail, request, group_snapshots)
|
|
|
|
def summary(self, request, group_snapshot):
|
|
"""Generic, non-detailed view of a group_snapshot."""
|
|
return {
|
|
'group_snapshot': {
|
|
'id': group_snapshot.id,
|
|
'name': group_snapshot.name,
|
|
# NOTE(xyang): group_type_id is added for migrating CGs
|
|
# to generic volume groups
|
|
'group_type_id': group_snapshot.group_type_id,
|
|
}
|
|
}
|
|
|
|
def detail(self, request, group_snapshot):
|
|
"""Detailed view of a single group_snapshot."""
|
|
group_snapshot_ref = {
|
|
'group_snapshot': {
|
|
'id': group_snapshot.id,
|
|
'group_id': group_snapshot.group_id,
|
|
'group_type_id': group_snapshot.group_type_id,
|
|
'status': group_snapshot.status,
|
|
'created_at': group_snapshot.created_at,
|
|
'name': group_snapshot.name,
|
|
'description': group_snapshot.description
|
|
}
|
|
}
|
|
req_version = request.api_version_request
|
|
context = request.environ['cinder.context']
|
|
|
|
if req_version.matches(mv.GROUP_GROUPSNAPSHOT_PROJECT_ID, None):
|
|
if context.authorize(policy.GROUP_SNAPSHOT_ATTRIBUTES_POLICY,
|
|
fatal=False):
|
|
group_snapshot_ref['group_snapshot']['project_id'] = (
|
|
group_snapshot.project_id)
|
|
|
|
return group_snapshot_ref
|
|
|
|
def _list_view(self, func, request, group_snapshots):
|
|
"""Provide a view for a list of group_snapshots."""
|
|
group_snapshots_list = [func(request, group_snapshot)['group_snapshot']
|
|
for group_snapshot in group_snapshots]
|
|
group_snapshot_links = self._get_collection_links(
|
|
request, group_snapshots_list, self._collection_name)
|
|
group_snapshots_dict = dict(group_snapshots=group_snapshots_list)
|
|
if group_snapshot_links:
|
|
group_snapshots_dict['group_snapshot_links'] = group_snapshot_links
|
|
|
|
return group_snapshots_dict
|