def __init__(self, execute=putils.execute, *args, **kwargs): self._remotefsclient = None super(NfsDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(nfs_opts) root_helper = utils.get_root_helper() # base bound to instance is used in RemoteFsConnector. self.base = getattr(self.configuration, 'nfs_mount_point_base') self.base = os.path.realpath(self.base) opts = getattr(self.configuration, 'nfs_mount_options') nas_mount_options = getattr(self.configuration, 'nas_mount_options', None) if nas_mount_options is not None: LOG.debug('overriding nfs_mount_options with nas_mount_options') opts = nas_mount_options self._remotefsclient = remotefs_brick.RemoteFsClient( 'nfs', root_helper, execute=execute, nfs_mount_point_base=self.base, nfs_mount_options=opts) supports_auto_mosr = kwargs.get('supports_auto_mosr', False) self._sparse_copy_volume_data = True self.reserved_percentage = self.configuration.reserved_percentage self.max_over_subscription_ratio = ( vutils.get_max_over_subscription_ratio( self.configuration.max_over_subscription_ratio, supports_auto=supports_auto_mosr))
def __init__(self, driver_name, driver_protocol, **kwargs): na_utils.validate_instantiation(**kwargs) self.driver_name = driver_name self.driver_protocol = driver_protocol self.zapi_client = None self._stats = {} self.lun_table = {} self.lun_ostype = None self.host_type = None self.lun_space_reservation = 'true' self.lookup_service = fczm_utils.create_lookup_service() self.app_version = kwargs.get("app_version", "unknown") self.host = kwargs.get('host') self.backend_name = self.host.split('@')[1] self.configuration = kwargs['configuration'] self.configuration.append_config_values(na_opts.netapp_connection_opts) self.configuration.append_config_values(na_opts.netapp_basicauth_opts) self.configuration.append_config_values(na_opts.netapp_transport_opts) self.configuration.append_config_values( na_opts.netapp_provisioning_opts) self.configuration.append_config_values(na_opts.netapp_san_opts) self.max_over_subscription_ratio = ( volume_utils.get_max_over_subscription_ratio( self.configuration.max_over_subscription_ratio, supports_auto=True)) self.reserved_percentage = self._get_reserved_percentage() self.loopingcalls = loopingcalls.LoopingCalls()
def test_get_max_over_subscription_ratio(self, max_over_subscription_ratio, supports_auto): if not supports_auto and max_over_subscription_ratio == 'auto': self.assertRaises(exception.VolumeDriverException, volume_utils.get_max_over_subscription_ratio, max_over_subscription_ratio, supports_auto) elif not supports_auto: mosr = volume_utils.get_max_over_subscription_ratio( max_over_subscription_ratio, supports_auto) self.assertEqual(float(max_over_subscription_ratio), mosr) else: # supports_auto mosr = volume_utils.get_max_over_subscription_ratio( max_over_subscription_ratio, supports_auto) if max_over_subscription_ratio == 'auto': self.assertEqual(max_over_subscription_ratio, mosr) else: self.assertEqual(float(max_over_subscription_ratio), mosr)
def do_setup(self, context): self.configuration.max_over_subscription_ratio = ( vutils.get_max_over_subscription_ratio( self.configuration.max_over_subscription_ratio, supports_auto=False)) if not self.configuration.max_over_subscription_ratio > 0: msg = _("Config 'max_over_subscription_ratio' invalid. Must be > " "0: %s") % self.configuration.max_over_subscription_ratio LOG.error(msg) raise exception.NfsException(msg) packages = ('mount.nfs', '/usr/sbin/mount') for package in packages: try: self._execute(package, check_exit_code=False, run_as_root=True) break except OSError as exc: if exc.errno != errno.ENOENT: raise LOG.error('%s is not installed.', package) else: msg = utils.build_or_str(packages, '%s needs to be installed.') raise exception.NfsException(msg) lcfg = self.configuration LOG.info('Connecting to host: %s.', lcfg.san_ip) host = lcfg.san_ip user = lcfg.san_login password = lcfg.san_password https_port = lcfg.zfssa_https_port credentials = ['san_ip', 'san_login', 'san_password', 'zfssa_data_ip'] for cred in credentials: if not getattr(lcfg, cred, None): exception_msg = _('%s not set in cinder.conf') % cred LOG.error(exception_msg) raise exception.CinderException(exception_msg) self.zfssa = factory_zfssa() self.zfssa.set_host(host, timeout=lcfg.zfssa_rest_timeout) auth_str = base64.encode_as_text('%s:%s' % (user, password)) self.zfssa.login(auth_str) self.zfssa.create_project(lcfg.zfssa_nfs_pool, lcfg.zfssa_nfs_project, compression=lcfg.zfssa_nfs_share_compression, logbias=lcfg.zfssa_nfs_share_logbias) share_args = { 'sharedav': 'rw', 'sharenfs': 'rw', 'root_permissions': '777', 'compression': lcfg.zfssa_nfs_share_compression, 'logbias': lcfg.zfssa_nfs_share_logbias } self.zfssa.create_share(lcfg.zfssa_nfs_pool, lcfg.zfssa_nfs_project, lcfg.zfssa_nfs_share, share_args) share_details = self.zfssa.get_share(lcfg.zfssa_nfs_pool, lcfg.zfssa_nfs_project, lcfg.zfssa_nfs_share) mountpoint = share_details['mountpoint'] self.mount_path = lcfg.zfssa_data_ip + ':' + mountpoint https_path = 'https://' + lcfg.zfssa_data_ip + ':' + https_port + \ '/shares' + mountpoint LOG.debug('NFS mount path: %s', self.mount_path) LOG.debug('WebDAV path to the share: %s', https_path) self.shares = {} mnt_opts = self.configuration.zfssa_nfs_mount_options self.shares[self.mount_path] = mnt_opts if len(mnt_opts) > 1 else None # Initialize the WebDAV client self.zfssa.set_webdav(https_path, auth_str) # Edit http service so that WebDAV requests are always authenticated args = {'https_port': https_port, 'require_login': True} self.zfssa.modify_service('http', args) self.zfssa.enable_service('http') if lcfg.zfssa_enable_local_cache: LOG.debug('Creating local cache directory %s.', lcfg.zfssa_cache_directory) self.zfssa.create_directory(lcfg.zfssa_cache_directory)