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

28 statements  

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

1# Copyright 2015 Alex Meade 

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. 

15 

16from manila.api import common 

17 

18 

19class ShareGroupViewBuilder(common.ViewBuilder): 

20 """Model a share group API response as a python dictionary.""" 

21 

22 _collection_name = 'share_groups' 

23 _detail_version_modifiers = [ 

24 "add_consistent_snapshot_support_and_az_id_fields_to_sg", 

25 ] 

26 

27 def summary_list(self, request, share_groups): 

28 """Show a list of share groups without many details.""" 

29 return self._list_view(self.summary, request, share_groups) 

30 

31 def detail_list(self, request, share_groups): 

32 """Detailed view of a list of share groups.""" 

33 return self._list_view(self.detail, request, share_groups) 

34 

35 def summary(self, request, share_group): 

36 """Generic, non-detailed view of a share group.""" 

37 return { 

38 'share_group': { 

39 'id': share_group.get('id'), 

40 'name': share_group.get('name'), 

41 'links': self._get_links(request, share_group['id']) 

42 } 

43 } 

44 

45 def detail(self, request, share_group): 

46 """Detailed view of a single share group.""" 

47 context = request.environ['manila.context'] 

48 share_group_dict = { 

49 'id': share_group.get('id'), 

50 'name': share_group.get('name'), 

51 'created_at': share_group.get('created_at'), 

52 'status': share_group.get('status'), 

53 'description': share_group.get('description'), 

54 'project_id': share_group.get('project_id'), 

55 'host': share_group.get('host'), 

56 'share_group_type_id': share_group.get('share_group_type_id'), 

57 'source_share_group_snapshot_id': share_group.get( 

58 'source_share_group_snapshot_id'), 

59 'share_network_id': share_group.get('share_network_id'), 

60 'share_types': [st['share_type_id'] for st in share_group.get( 

61 'share_types')], 

62 'links': self._get_links(request, share_group['id']), 

63 } 

64 self.update_versioned_resource_dict( 

65 request, share_group_dict, share_group) 

66 if context.is_admin: 

67 share_group_dict['share_server_id'] = share_group.get( 

68 'share_server_id') 

69 return {'share_group': share_group_dict} 

70 

71 @common.ViewBuilder.versioned_method("2.34") 

72 def add_consistent_snapshot_support_and_az_id_fields_to_sg( 

73 self, context, sg_dict, sg): 

74 sg_dict['availability_zone'] = sg.get('availability_zone') 

75 sg_dict['consistent_snapshot_support'] = sg.get( 

76 'consistent_snapshot_support') 

77 

78 def _list_view(self, func, request, shares): 

79 """Provide a view for a list of share groups.""" 

80 share_group_list = [ 

81 func(request, share)['share_group'] 

82 for share in shares 

83 ] 

84 share_groups_links = self._get_collection_links( 

85 request, shares, self._collection_name) 

86 share_groups_dict = {"share_groups": share_group_list} 

87 

88 if share_groups_links: 

89 share_groups_dict['share_groups_links'] = share_groups_links 

90 

91 return share_groups_dict