Coverage for manila/api/views/share_snapshot_instances.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 2016 Huawei Inc. 

2# All Rights Reserved. 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15from manila.api import common 

16 

17 

18class ViewBuilder(common.ViewBuilder): 

19 """Model the server API response as a python dictionary.""" 

20 

21 _collection_name = 'snapshot_instances' 

22 

23 def summary_list(self, request, instances): 

24 """Summary view of a list of share snapshot instances.""" 

25 return self._list_view(self.summary, request, instances) 

26 

27 def detail_list(self, request, instances): 

28 """Detailed view of a list of share snapshot instances.""" 

29 return self._list_view(self.detail, request, instances) 

30 

31 def summary(self, request, instance): 

32 """Generic, non-detailed view of a share snapshot instance.""" 

33 instance_dict = { 

34 'id': instance.get('id'), 

35 'snapshot_id': instance.get('snapshot_id'), 

36 'status': instance.get('status'), 

37 } 

38 return {'snapshot_instance': instance_dict} 

39 

40 def detail(self, request, instance): 

41 """Detailed view of a single share snapshot instance.""" 

42 instance_dict = { 

43 'id': instance.get('id'), 

44 'snapshot_id': instance.get('snapshot_id'), 

45 'created_at': instance.get('created_at'), 

46 'updated_at': instance.get('updated_at'), 

47 'status': instance.get('status'), 

48 'share_id': instance.get('share_instance').get('share_id'), 

49 'share_instance_id': instance.get('share_instance_id'), 

50 'progress': instance.get('progress'), 

51 'provider_location': instance.get('provider_location'), 

52 } 

53 

54 return {'snapshot_instance': instance_dict} 

55 

56 def _list_view(self, func, request, instances): 

57 """Provide a view for a list of share snapshot instances.""" 

58 instances_list = [func(request, instance)['snapshot_instance'] 

59 for instance in instances] 

60 

61 instances_dict = {self._collection_name: instances_list} 

62 

63 return instances_dict