def _find_furl(self, profile='default', cluster_dir=None, furl_or_file=None, furl_file_name=None, ipython_dir=None): """Find a FURL file. If successful, this returns a FURL file that exists on the file system. The contents of the file have not been checked though. This is because we often have to deal with FURL file whose buffers have not been flushed. This raises an :exc:`~IPython.kernel.fcutil.FURLError` exception if a FURL file can't be found. This tries the following: 1. By the name ``furl_or_file``. 2. By ``cluster_dir`` and ``furl_file_name``. 3. By cluster profile with a default of ``default``. This uses ``ipython_dir``. """ # Try by furl_or_file if furl_or_file is not None: if is_valid_furl_or_file(furl_or_file): return furl_or_file if furl_file_name is None: raise FURLError('A furl_file_name must be provided if furl_or_file is not') # Try by cluster_dir if cluster_dir is not None: cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir) sdir = cluster_dir_obj.security_dir furl_file = os.path.join(sdir, furl_file_name) validate_furl_or_file(furl_file) return furl_file # Try by profile if ipython_dir is None: ipython_dir = get_ipython_dir() if profile is not None: cluster_dir_obj = ClusterDir.find_cluster_dir_by_profile( ipython_dir, profile) sdir = cluster_dir_obj.security_dir furl_file = os.path.join(sdir, furl_file_name) validate_furl_or_file(furl_file) return furl_file raise FURLError('Could not find a valid FURL file.')
def connect_to_controller(self, engine_service, furl_or_file, delay=0.1, max_tries=10): """ Make a connection to a controller specified by a furl. This method takes an `IEngineBase` instance and a foolcap URL and uses the `tub` attribute to make a connection to the controller. The foolscap URL contains all the information needed to connect to the controller, including the ip and port as well as any encryption and authentication information needed for the connection. After getting a reference to the controller, this method calls the `register_engine` method of the controller to actually register the engine. This method will try to connect to the controller multiple times with a delay in between. Each time the FURL file is read anew. Parameters __________ engine_service : IEngineBase An instance of an `IEngineBase` implementer furl_or_file : str A furl or a filename containing a furl delay : float The intial time to wait between connection attempts. Subsequent attempts have increasing delays. max_tries : int The maximum number of connection attempts. Returns ------- A deferred to the registered client or a failure to an error like :exc:`FURLError`. """ if not self.tub.running: self.tub.startService() self.engine_service = engine_service self.engine_reference = IFCEngine(self.engine_service) validate_furl_or_file(furl_or_file) d = self._try_to_connect(furl_or_file, delay, max_tries, attempt=0) d.addCallback(self._register) return d