def __init__(self, execute, config_object, **kwargs): if config_object.cephfs_ganesha_server_is_remote: execute = ganesha_utils.SSHExecutor( config_object.cephfs_ganesha_server_ip, 22, None, config_object.cephfs_ganesha_server_username, password=config_object.cephfs_ganesha_server_password, privatekey=config_object.cephfs_ganesha_path_to_private_key) else: execute = ganesha_utils.RootExecutor(execute) self.ganesha_host = config_object.cephfs_ganesha_server_ip if not self.ganesha_host: self.ganesha_host = socket.gethostname() LOG.info( "NFS-Ganesha server's location defaulted to driver's " "hostname: %s", self.ganesha_host) super(NFSProtocolHelper, self).__init__(execute, config_object, **kwargs) if not hasattr(self, 'ceph_vol_client'): self.ceph_vol_client = kwargs.pop('ceph_vol_client') self.export_ips = config_object.cephfs_ganesha_export_ips if not self.export_ips: self.export_ips = [self.ganesha_host] self.configured_ip_versions = set() self.config = config_object
def get_remote_shell_executor( ip, port, conn_timeout, login=None, password=None, privatekey=None, max_size=10): return ganesha_utils.SSHExecutor( ip=ip, port=port, conn_timeout=conn_timeout, login=login, password=password, privatekey=privatekey, max_size=max_size, )
def __init__(self, execute, config_object, **kwargs): self.gluster_manager = kwargs.pop('gluster_manager') if config_object.glusterfs_ganesha_server_ip: execute = ganesha_utils.SSHExecutor( config_object.glusterfs_ganesha_server_ip, 22, None, config_object.glusterfs_ganesha_server_username, password=config_object.glusterfs_ganesha_server_password, privatekey=config_object.glusterfs_path_to_private_key) else: execute = ganesha_utils.RootExecutor(execute) super(GaneshaNFSHelper, self).__init__(execute, config_object, **kwargs)
def make_gluster_call(self, execf): """Execute a Gluster command locally or remotely.""" if self.remote_user: gluster_execf = ganesha_utils.SSHExecutor( self.host, 22, None, self.remote_user, password=self.remote_server_password, privatekey=self.path_to_private_key) else: gluster_execf = ganesha_utils.RootExecutor(execf) return lambda *args, **kwargs: gluster_execf(*( ('gluster', ) + args), **kwargs)
def test_call_ssh_exec_object_with_run_as_root( self, run_as_root, expected_prefix): with mock.patch.object(ganesha_utils.utils, 'SSHPool'): self.execute = ganesha_utils.SSHExecutor() fake_ssh_object = mock.Mock() self.mock_object(self.execute.pool, 'get', mock.Mock(return_value=fake_ssh_object)) self.mock_object(ganesha_utils.processutils, 'ssh_execute', mock.Mock(return_value=('', ''))) ret = self.execute('ls', run_as_root=run_as_root) self.assertEqual(('', ''), ret) self.execute.pool.get.assert_called_once_with() ganesha_utils.processutils.ssh_execute.assert_called_once_with( fake_ssh_object, expected_prefix + 'ls')
def init_execute_mixin(self, *args, **kwargs): """Init method for mixin called in the end of driver's __init__().""" super(ExecuteMixin, self).init_execute_mixin(*args, **kwargs) if self.configuration.zfs_use_ssh: self.ssh_executor = ganesha_utils.SSHExecutor( ip=self.configuration.zfs_service_ip, port=22, conn_timeout=self.configuration.ssh_conn_timeout, login=self.configuration.zfs_ssh_username, password=self.configuration.zfs_ssh_user_password, privatekey=self.configuration.zfs_ssh_private_key_path, max_size=10, ) else: self.ssh_executor = None
def __init__(self, execute, config_object, **kwargs): self.gluster_manager = kwargs.pop('gluster_manager') if config_object.glusterfs_ganesha_server_ip: execute = ganesha_utils.SSHExecutor( config_object.glusterfs_ganesha_server_ip, 22, None, config_object.glusterfs_ganesha_server_username, password=config_object.glusterfs_ganesha_server_password, privatekey=config_object.glusterfs_path_to_private_key) else: execute = ganesha_utils.RootExecutor(execute) self.ganesha_host = config_object.glusterfs_ganesha_server_ip if not self.ganesha_host: self.ganesha_host = socket.gethostname() kwargs['tag'] = '-'.join(('GLUSTER', 'Ganesha', self.ganesha_host)) super(GaneshaNFSHelper, self).__init__(execute, config_object, **kwargs)
def make_gluster_call(self, execf): """Execute a Gluster command locally or remotely.""" if self.user: gluster_execf = ganesha_utils.SSHExecutor( self.host, 22, None, self.user, password=self.remote_server_password, privatekey=self.path_to_private_key) else: gluster_execf = ganesha_utils.RootExecutor(execf) def _gluster_call(*args, **kwargs): logmsg = kwargs.pop('log', None) error_policy = kwargs.pop('error_policy', 'coerce') if (error_policy not in ('raw', 'coerce', 'suppress') and not isinstance(error_policy[0], int)): raise TypeError( _("undefined error_policy %s") % repr(error_policy)) try: return gluster_execf(*(('gluster', ) + args), **kwargs) except exception.ProcessExecutionError as exc: if error_policy == 'raw': raise elif error_policy == 'coerce': pass elif (error_policy == 'suppress' or exc.exit_code in error_policy): return if logmsg: LOG.error( _LE("%s: GlusterFS instrumentation failed.") % logmsg) raise exception.GlusterfsException( _("GlusterFS management command '%(cmd)s' failed " "with details as follows:\n%(details)s.") % { 'cmd': ' '.join(args), 'details': exc }) return _gluster_call