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

37 statements  

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

1# Copyright (c) 2015 Mirantis inc. 

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 ViewBuilder(common.ViewBuilder): 

20 

21 _collection_name = "quota_set" 

22 _detail_version_modifiers = [ 

23 "add_share_group_quotas", 

24 "add_share_replica_quotas", 

25 "add_per_share_gigabytes_quotas", 

26 "add_share_backup_quotas", 

27 "add_encryption_keys_quotas", 

28 ] 

29 

30 def detail_list(self, request, quota_set, project_id=None, 

31 share_type=None): 

32 """Detailed view of quota set.""" 

33 keys = ( 

34 'shares', 

35 'gigabytes', 

36 'snapshots', 

37 'snapshot_gigabytes', 

38 ) 

39 view = {key: quota_set.get(key) for key in keys} 

40 if project_id: 

41 view['id'] = project_id 

42 if share_type: 

43 # NOTE(vponomaryov): remove share groups related data for quotas 

44 # that are share-type based. 

45 quota_set.pop('share_groups', None) 

46 quota_set.pop('share_group_snapshots', None) 

47 else: 

48 view['share_networks'] = quota_set.get('share_networks') 

49 self.update_versioned_resource_dict(request, view, quota_set) 

50 return {self._collection_name: view} 

51 

52 @common.ViewBuilder.versioned_method("2.40") 

53 def add_share_group_quotas(self, context, view, quota_set): 

54 share_groups = quota_set.get('share_groups') 

55 share_group_snapshots = quota_set.get('share_group_snapshots') 

56 if share_groups is not None: 

57 view['share_groups'] = share_groups 

58 if share_group_snapshots is not None: 

59 view['share_group_snapshots'] = share_group_snapshots 

60 

61 @common.ViewBuilder.versioned_method("2.53") 

62 def add_share_replica_quotas(self, context, view, quota_class_set): 

63 view['share_replicas'] = quota_class_set.get('share_replicas') 

64 view['replica_gigabytes'] = quota_class_set.get('replica_gigabytes') 

65 

66 @common.ViewBuilder.versioned_method("2.62") 

67 def add_per_share_gigabytes_quotas(self, context, view, quota_set): 

68 view['per_share_gigabytes'] = quota_set.get('per_share_gigabytes') 

69 

70 @common.ViewBuilder.versioned_method("2.80") 

71 def add_share_backup_quotas(self, context, view, quota_set): 

72 view['backups'] = quota_set.get('backups') 

73 view['backup_gigabytes'] = quota_set.get('backup_gigabytes') 

74 

75 @common.ViewBuilder.versioned_method("2.90") 

76 def add_encryption_keys_quotas(self, context, view, quota_set): 

77 view['encryption_keys'] = quota_set.get('encryption_keys')