Coverage for manila/common/config.py: 100%

31 statements  

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

1# Copyright 2010 United States Government as represented by the 

2# Administrator of the National Aeronautics and Space Administration. 

3# All Rights Reserved. 

4# Copyright 2012 Red Hat, Inc. 

5# 

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

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

8# a copy of the License at 

9# 

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

11# 

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

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

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

15# License for the specific language governing permissions and limitations 

16# under the License. 

17 

18"""Command-line flag library. 

19 

20Emulates gflags by wrapping cfg.ConfigOpts. 

21 

22The idea is to move fully to cfg eventually, and this wrapper is a 

23stepping stone. 

24 

25""" 

26 

27import socket 

28 

29from oslo_config import cfg 

30from oslo_log import log 

31from oslo_middleware import cors 

32from oslo_utils import netutils 

33 

34from manila.common import constants 

35from manila import exception 

36 

37CONF = cfg.CONF 

38log.register_options(CONF) 

39 

40 

41core_opts = [ 

42 cfg.StrOpt('state_path', 

43 default='/var/lib/manila', 

44 help="Top-level directory for maintaining manila's state."), 

45] 

46 

47debug_opts = [ 

48] 

49 

50CONF.register_cli_opts(core_opts) 

51CONF.register_cli_opts(debug_opts) 

52 

53global_opts = [ 

54 cfg.HostAddressOpt('my_ip', 

55 default=netutils.get_my_ipv4(), 

56 sample_default='<your_ip>', 

57 help='IP address of this host.'), 

58 cfg.StrOpt('scheduler_topic', 

59 default='manila-scheduler', 

60 help='The topic scheduler nodes listen on.'), 

61 cfg.StrOpt('share_topic', 

62 default='manila-share', 

63 help='The topic share nodes listen on.'), 

64 cfg.StrOpt('data_topic', 

65 default='manila-data', 

66 help='The topic data nodes listen on.'), 

67 cfg.BoolOpt('api_rate_limit', 

68 default=True, 

69 help='Whether to rate limit the API.'), 

70 cfg.ListOpt('osapi_share_ext_list', 

71 default=[], 

72 help='Specify list of extensions to load when using osapi_' 

73 'share_extension option with manila.api.contrib.' 

74 'select_extensions.'), 

75 cfg.ListOpt('osapi_share_extension', 

76 default=['manila.api.contrib.standard_extensions'], 

77 help='The osapi share extensions to load.'), 

78 cfg.StrOpt('scheduler_manager', 

79 default='manila.scheduler.manager.SchedulerManager', 

80 help='Full class name for the scheduler manager.'), 

81 cfg.StrOpt('share_manager', 

82 default='manila.share.manager.ShareManager', 

83 help='Full class name for the share manager.'), 

84 cfg.StrOpt('data_manager', 

85 default='manila.data.manager.DataManager', 

86 help='Full class name for the data manager.'), 

87 cfg.HostAddressOpt('host', 

88 default=socket.gethostname(), 

89 sample_default='<your_hostname>', 

90 help='Name of this node. This can be an opaque ' 

91 'identifier. It is not necessarily a hostname, ' 

92 'FQDN, or IP address.'), 

93 # NOTE(vish): default to nova for compatibility with nova installs 

94 cfg.StrOpt('storage_availability_zone', 

95 default='nova', 

96 help='Availability zone of this node.'), 

97 cfg.StrOpt('default_share_type', 

98 help='Default share type to use.'), 

99 cfg.StrOpt('default_share_group_type', 

100 help='Default share group type to use.'), 

101 cfg.StrOpt('rootwrap_config', 

102 help='Path to the rootwrap configuration file to use for ' 

103 'running commands as root.'), 

104 cfg.BoolOpt('monkey_patch', 

105 default=False, 

106 help='Whether to log monkey patching.'), 

107 cfg.ListOpt('monkey_patch_modules', 

108 default=[], 

109 help='List of modules or decorators to monkey patch.'), 

110 cfg.IntOpt('service_down_time', 

111 default=60, 

112 help='Maximum time since last check-in for up service.'), 

113 cfg.StrOpt('share_api_class', 

114 default='manila.share.api.API', 

115 help='The full class name of the share API class to use.'), 

116 cfg.StrOpt('auth_strategy', 

117 default='keystone', 

118 help='The strategy to use for auth. Supports noauth, keystone, ' 

119 'and noauthv2.'), 

120 cfg.ListOpt('enabled_share_backends', 

121 help='A list of share backend names to use. These backend ' 

122 'names should be backed by a unique [CONFIG] group ' 

123 'with its options.'), 

124 cfg.ListOpt('enabled_share_protocols', 

125 default=['NFS', 'CIFS'], 

126 help="Specify list of protocols to be allowed for share " 

127 "creation. Available values are '%s'" % 

128 list(constants.SUPPORTED_SHARE_PROTOCOLS)), 

129 cfg.IntOpt('soft_deleted_share_retention_time', 

130 default=604800, 

131 help='Maximum time (in seconds) to keep a share in the recycle ' 

132 'bin, it will be deleted automatically after this amount ' 

133 'of time has elapsed.'), 

134 cfg.IntOpt('transfer_retention_time', 

135 default=300, 

136 help='Maximum time (in seconds) to keep a share in ' 

137 'awaiting_transfer state, after timeout, the share will ' 

138 'automatically be rolled back to the available state'), 

139 cfg.ListOpt('admin_only_metadata', 

140 default=constants.AdminOnlyMetadata.SCHEDULER_FILTERS, 

141 help='Metadata keys that should only be manipulated by ' 

142 'administrators.'), 

143 cfg.ListOpt('driver_updatable_metadata', 

144 default=[], 

145 help='Metadata keys that will decide which share metadata ' 

146 '(element of the list is <driver_updatable_key>, ' 

147 'i.e max_files) can be passed to share drivers as part ' 

148 'of metadata create/update operations.'), 

149 cfg.ListOpt('driver_updatable_subnet_metadata', 

150 default=[], 

151 help='Metadata keys that will decide which share network ' 

152 'subnet metadata (element of the list is ' 

153 '<driver_updatable_key>, e.g. pnfs) can be passed to ' 

154 'share drivers as part of metadata create/update ' 

155 'operations.'), 

156 cfg.BoolOpt('update_shares_status_on_ensure', 

157 default=True, 

158 help='Whether Manila should update the status of all shares ' 

159 'within a backend during ongoing ensure_shares ' 

160 'run.'), 

161 cfg.ListOpt('admin_only_el_metadata', 

162 default=constants.AdminOnlyMetadata.EXPORT_LOCATION_KEYS, 

163 help='Metadata keys for export locations that should only be ' 

164 'manipulated by administrators.'), 

165 cfg.ListOpt('data_manager_backup_supported_share_protocols', 

166 default=['NFS'], 

167 help="Specify list of protocols to be allowed for share " 

168 "backup creation when using either the data manager " 

169 "generic backup approach, or another backup driver that " 

170 "makes use of the data manager service."), 

171] 

172 

173CONF.register_opts(global_opts) 

174 

175 

176def verify_share_protocols(): 

177 """Perform verification of 'enabled_share_protocols'.""" 

178 msg = None 

179 supported_protocols = constants.SUPPORTED_SHARE_PROTOCOLS 

180 data = dict(supported=', '.join(supported_protocols)) 

181 if CONF.enabled_share_protocols: 

182 for share_proto in CONF.enabled_share_protocols: 

183 if share_proto.upper() not in supported_protocols: 

184 data.update({'share_proto': share_proto}) 

185 msg = ("Unsupported share protocol '%(share_proto)s' " 

186 "is set as enabled. Available values are " 

187 "%(supported)s. ") 

188 break 

189 else: 

190 msg = ("No share protocols were specified as enabled. " 

191 "Available values are %(supported)s. ") 

192 if msg: 

193 msg += ("Please specify one or more protocols using " 

194 "configuration option 'enabled_share_protocols'.") 

195 raise exception.ManilaException(message=msg % data) 

196 

197 

198def set_lib_defaults(): 

199 """Update default configuration options for external lib namespace""" 

200 cors.set_defaults( 

201 allow_headers=['X-Auth-Token', 

202 'X-OpenStack-Request-ID', 

203 'X-Openstack-Manila-Api-Version', 

204 'X-OpenStack-Manila-API-Experimental', 

205 'X-Identity-Status', 

206 'X-Roles', 

207 'X-Service-Catalog', 

208 'X-User-Id', 

209 'X-Tenant-Id'], 

210 expose_headers=['X-Auth-Token', 

211 'X-OpenStack-Request-ID', 

212 'X-Openstack-Manila-Api-Version', 

213 'X-OpenStack-Manila-API-Experimental', 

214 'X-Subject-Token', 

215 'X-Service-Token'], 

216 allow_methods=['GET', 

217 'PUT', 

218 'POST', 

219 'DELETE', 

220 'PATCH'] 

221 )