Coverage for manila/api/views/share_backups.py: 100%
33 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2023 Cloudification GmbH.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from manila.api import common
17from manila import policy
20class BackupViewBuilder(common.ViewBuilder):
21 """Model a server API response as a python dictionary."""
23 _collection_name = 'share_backups'
24 _collection_links = 'share_backup_links'
26 _detail_version_modifiers = [
27 "add_backup_type_field",
28 ]
30 def summary_list(self, request, backups):
31 """Summary view of a list of backups."""
32 return self._list_view(self.summary, request, backups)
34 def detail_list(self, request, backups):
35 """Detailed view of a list of backups."""
36 return self._list_view(self.detail, request, backups)
38 def summary(self, request, backup):
39 """Generic, non-detailed view of a share backup."""
41 backup_dict = {
42 'id': backup.get('id'),
43 'name': backup.get('display_name'),
44 'share_id': backup.get('share_id'),
45 'status': backup.get('status'),
46 }
47 return {'share_backup': backup_dict}
49 def restore_summary(self, request, restore):
50 """Generic, non-detailed view of a restore."""
51 return {
52 'restore': {
53 'backup_id': restore['backup_id'],
54 'share_id': restore['share_id'],
55 },
56 }
58 def detail(self, request, backup):
59 """Detailed view of a single backup."""
60 context = request.environ['manila.context']
61 backup_dict = {
62 'id': backup.get('id'),
63 'name': backup.get('display_name'),
64 'share_id': backup.get('share_id'),
65 'status': backup.get('status'),
66 'description': backup.get('display_description'),
67 'size': backup.get('size'),
68 'created_at': backup.get('created_at'),
69 'updated_at': backup.get('updated_at'),
70 'availability_zone': backup.get('availability_zone'),
71 'progress': backup.get('progress'),
72 'restore_progress': backup.get('restore_progress'),
73 }
75 self.update_versioned_resource_dict(request, backup_dict, backup)
76 if policy.check_is_host_admin(context):
77 backup_dict['host'] = backup.get('host')
78 backup_dict['topic'] = backup.get('topic')
80 return {'share_backup': backup_dict}
82 def _list_view(self, func, request, backups):
83 """Provide a view for a list of backups."""
85 backups_list = [func(request, backup)['share_backup']
86 for backup in backups]
88 backup_links = self._get_collection_links(
89 request, backups, self._collection_name)
90 backups_dict = {self._collection_name: backups_list}
92 if backup_links:
93 backups_dict[self._collection_links] = backup_links
95 return backups_dict
97 @common.ViewBuilder.versioned_method("2.85")
98 def add_backup_type_field(self, context, backup_dict, backup):
99 backup_dict['backup_type'] = backup.get('backup_type')