Coverage for manila/share/drivers/macrosan/macrosan_nas.py: 100%
57 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 (c) 2022 MacroSAN Technologies Co., Ltd.
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.
16"""
17Share driver for Macrosan Storage Array.
18"""
20import functools
21from oslo_config import cfg
22from oslo_log import log
24from manila.share import driver
25from manila.share.drivers.macrosan import macrosan_helper
27macrosan_opts = [
28 cfg.HostAddressOpt('macrosan_nas_ip',
29 required=True,
30 help='IP address for the Macrosan NAS server.'),
31 cfg.PortOpt('macrosan_nas_port',
32 default=8443,
33 help='Port number for the Macrosan NAS server.'),
34 cfg.StrOpt('macrosan_nas_username',
35 default='manila',
36 help='Username for the Macrosan NAS server.'),
37 cfg.StrOpt('macrosan_nas_password',
38 secret=True,
39 help='Password for the Macrosan NAS server.'),
40 cfg.StrOpt('macrosan_nas_http_protocol',
41 default='https',
42 choices=['http', 'https'],
43 help='Http protocol for the Macrosan NAS server.'),
44 cfg.BoolOpt('macrosan_ssl_cert_verify',
45 default=False,
46 help='Defines whether the driver should check ssl cert.'),
47 cfg.StrOpt('macrosan_nas_prefix',
48 default='nas',
49 help='Url prefix for the Macrosan NAS server.'),
50 cfg.ListOpt('macrosan_share_pools',
51 required=True,
52 help='Comma separated list of Macrosan NAS pools.'),
53 cfg.IntOpt('macrosan_timeout',
54 default=60,
55 help='request timeout in seconds.')
56]
58CONF = cfg.CONF
59CONF.register_opts(macrosan_opts)
60LOG = log.getLogger(__name__)
63def debug_trace(func):
64 """Log the dirver invoke method start and leave information
66 Used in the MacrosanNasDriver class methods.
67 Ensure func have 'self' argument.
68 """
70 @functools.wraps(func)
71 def wrapper(*args, **kwargs):
72 driver = args[0]
73 method_name = "%(class_name)s.%(method)s" \
74 % {"class_name": driver.__class__.__name__,
75 "method": func.__name__}
76 backend_name = driver.configuration.share_backend_name
77 LOG.debug("[%(backend_name)s]:Start %(method_name)s",
78 {"backend_name": backend_name, "method_name": method_name})
79 result = func(*args, **kwargs)
80 LOG.debug("[%(backend_name)s]:Leave %(method_name)s",
81 {"backend_name": backend_name, "method_name": method_name})
82 return result
84 return wrapper
87class MacrosanNasDriver(driver.ShareDriver):
88 """Macrosan Share Driver
90 Driver version history:
91 V1.0.0: Initial version
92 Driver support:
93 share create/delete,
94 extend size,
95 shrink size,
96 update_access.
97 protocol: NFS/CIFS
99 """
101 VENDOR = 'Macrosan'
102 VERSION = '1.0.0'
103 PROTOCOL = 'NFS_CIFS'
105 def __init__(self, *args, **kwargs):
106 super(MacrosanNasDriver, self).__init__(False, *args, **kwargs)
107 self.configuration.append_config_values(macrosan_opts)
109 self.helper = macrosan_helper.MacrosanHelper(self.configuration)
111 @debug_trace
112 def do_setup(self, context):
113 """initialization the driver when start"""
114 self.helper.do_setup()
116 @debug_trace
117 def check_for_setup_error(self):
118 """Check prerequisites"""
119 self.helper.check_share_service()
121 @debug_trace
122 def create_share(self, context, share, share_server=None):
123 """Create a share"""
124 return self.helper.create_share(share, share_server)
126 @debug_trace
127 def delete_share(self, context, share, share_server=None):
128 """Delete a share."""
129 self.helper.delete_share(share, share_server)
131 @debug_trace
132 def extend_share(self, share, new_size, share_server=None):
133 """Extend share capacity"""
134 self.helper.extend_share(share, new_size, share_server)
136 @debug_trace
137 def shrink_share(self, share, new_size, share_server=None):
138 """Shrink share capacity"""
139 self.helper.shrink_share(share, new_size, share_server)
141 @debug_trace
142 def ensure_share(self, context, share, share_server=None):
143 """Enusre that share is exported."""
144 return self.helper.ensure_share(share, share_server)
146 @debug_trace
147 def update_access(self, context, share, access_rules, add_rules,
148 delete_rules, update_rules, share_server=None):
149 """Update access rules list.
151 :param context: Current context
152 :param share: Share model with share data.
153 :param access_rules: All access rules for given share
154 :param add_rules: Empty List or List of access rules which should be
155 added. access_rules already contains these rules.
156 :param delete_rules: Empty List or List of access rules which should be
157 removed. access_rules doesn't contain these rules.
158 :param update_rules: Empty List or List of access rules which should be
159 updated. access_rules already contains these rules.
160 :param share_server: Not used by this driver.
162 :returns: None, or a dictionary of ``access_id``, ``access_key`` as
163 key: value pairs for the rules added, where, ``access_id``
164 is the UUID (string) of the access rule, and ``access_key``
165 is the credential (string) of the entity granted access.
166 During recovery after error, the returned dictionary must
167 contain ``access_id``, ``access_key`` for all the rules that
168 the driver is ordered to resync, i.e. rules in the
169 ``access_rules`` parameter.
170 """
171 return self.helper.update_access(share, access_rules,
172 add_rules, delete_rules,
173 share_server)
175 @debug_trace
176 def _update_share_stats(self):
177 """Update backend status ,include driver and pools"""
179 data = {
180 'vendor_name': self.VENDOR,
181 'driver_version': self.VERSION,
182 'storage_protocol': self.PROTOCOL,
183 'share_backend_name':
184 self.configuration.safe_get('share_backend_name'),
185 }
186 self.helper.update_share_stats(data)
187 super(MacrosanNasDriver, self)._update_share_stats(data)