Coverage for manila/share/drivers/nexenta/ns4/nexenta_nas.py: 91%

60 statements  

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

1# Copyright 2016 Nexenta Systems, 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 oslo_log import log 

17 

18from manila import exception 

19from manila.i18n import _ 

20from manila.share import driver 

21from manila.share.drivers.nexenta.ns4 import nexenta_nfs_helper 

22from manila.share.drivers.nexenta import options 

23 

24 

25VERSION = '1.0' 

26LOG = log.getLogger(__name__) 

27 

28 

29class NexentaNasDriver(driver.ShareDriver): 

30 """Nexenta Share Driver. 

31 

32 Executes commands relating to Shares. 

33 API version history: 

34 1.0 - Initial version. 

35 """ 

36 

37 def __init__(self, *args, **kwargs): 

38 """Do initialization.""" 

39 LOG.debug('Initializing Nexenta driver.') 

40 super(NexentaNasDriver, self).__init__(False, *args, **kwargs) 

41 self.configuration = kwargs.get('configuration') 

42 if self.configuration: 42 ↛ 51line 42 didn't jump to line 51 because the condition on line 42 was always true

43 self.configuration.append_config_values( 

44 options.nexenta_connection_opts) 

45 self.configuration.append_config_values( 

46 options.nexenta_nfs_opts) 

47 self.configuration.append_config_values( 

48 options.nexenta_dataset_opts) 

49 self.helper = nexenta_nfs_helper.NFSHelper(self.configuration) 

50 else: 

51 raise exception.BadConfigurationException( 

52 reason=_('Nexenta configuration missing.')) 

53 

54 @property 

55 def share_backend_name(self): 

56 if not hasattr(self, '_share_backend_name'): 56 ↛ 63line 56 didn't jump to line 63 because the condition on line 56 was always true

57 self._share_backend_name = None 

58 if self.configuration: 58 ↛ 61line 58 didn't jump to line 61 because the condition on line 58 was always true

59 self._share_backend_name = self.configuration.safe_get( 

60 'share_backend_name') 

61 if not self._share_backend_name: 61 ↛ 62line 61 didn't jump to line 62 because the condition on line 61 was never true

62 self._share_backend_name = 'NexentaStor4' 

63 return self._share_backend_name 

64 

65 def do_setup(self, context): 

66 """Any initialization the Nexenta NAS driver does while starting.""" 

67 LOG.debug('Setting up the NexentaStor4 plugin.') 

68 return self.helper.do_setup() 

69 

70 def check_for_setup_error(self): 

71 """Returns an error if prerequisites aren't met.""" 

72 self.helper.check_for_setup_error() 

73 

74 def create_share(self, context, share, share_server=None): 

75 """Create a share.""" 

76 LOG.debug('Creating share %s.', share['name']) 

77 return self.helper.create_filesystem(share) 

78 

79 def create_share_from_snapshot(self, context, share, snapshot, 

80 share_server=None, parent_share=None): 

81 """Is called to create share from snapshot.""" 

82 LOG.debug('Creating share from snapshot %s.', snapshot['name']) 

83 return self.helper.create_share_from_snapshot(share, snapshot) 

84 

85 def delete_share(self, context, share, share_server=None): 

86 """Delete a share.""" 

87 LOG.debug('Deleting share %s.', share['name']) 

88 self.helper.delete_share(share['name']) 

89 

90 def extend_share(self, share, new_size, share_server=None): 

91 """Extends a share.""" 

92 LOG.debug('Extending share %(name)s to %(size)sG.', { 

93 'name': share['name'], 'size': new_size}) 

94 self.helper.set_quota(share['name'], new_size) 

95 

96 def create_snapshot(self, context, snapshot, share_server=None): 

97 """Create a snapshot.""" 

98 LOG.debug('Creating a snapshot of share %s.', snapshot['share_name']) 

99 snap_id = self.helper.create_snapshot( 

100 snapshot['share_name'], snapshot['name']) 

101 LOG.info('Created snapshot %s.', snap_id) 

102 

103 def delete_snapshot(self, context, snapshot, share_server=None): 

104 """Delete a snapshot.""" 

105 LOG.debug('Deleting snapshot %(shr_name)s@%(snap_name)s.', { 

106 'shr_name': snapshot['share_name'], 

107 'snap_name': snapshot['name']}) 

108 self.helper.delete_snapshot(snapshot['share_name'], snapshot['name']) 

109 

110 def update_access(self, context, share, access_rules, add_rules, 

111 delete_rules, update_rules, share_server=None): 

112 """Update access rules for given share. 

113 

114 :param context: The `context.RequestContext` object for the request 

115 :param share: Share that will have its access rules updated. 

116 :param access_rules: All access rules for given share. This list 

117 is enough to update the access rules for given share. 

118 :param add_rules: Empty List or List of access rules which should be 

119 added. access_rules already contains these rules. Not used 

120 by this driver. 

121 :param delete_rules: Empty List or List of access rules which should be 

122 removed. access_rules doesn't contain these rules. Not used by 

123 this driver. 

124 :param update_rules: Empty List or List of access rules which should be 

125 updated. access_rules already contains these rules. 

126 :param share_server: Data structure with share server information. 

127 Not used by this driver. 

128 """ 

129 self.helper.update_access(share['name'], access_rules) 

130 

131 def _update_share_stats(self, data=None): 

132 super(NexentaNasDriver, self)._update_share_stats() 

133 data = self.helper.update_share_stats() 

134 data['driver_version'] = VERSION 

135 data['share_backend_name'] = self.share_backend_name 

136 self._stats.update(data)