def disambiguate_ip_address(ip, location=None): """turn multi-ip interfaces '0.0.0.0' and '*' into a connectable address Explicit IP addresses are returned unmodified. Parameters ---------- ip : IP address An IP address, or the special values 0.0.0.0, or * location: IP address, optional A public IP of the target machine. If location is an IP of the current machine, localhost will be returned, otherwise location will be returned. """ if ip in {'0.0.0.0', '*'}: if not location: # unspecified location, localhost is the only choice ip = localhost() elif is_public_ip(location): # location is a public IP on this machine, use localhost ip = localhost() elif not public_ips(): # this machine's public IPs cannot be determined, # assume `location` is not this machine warnings.warn("IPython could not determine public IPs", RuntimeWarning) ip = location else: # location is not this machine, do not use loopback ip = location return ip
def disambiguate_ip_address(ip, location=None): """turn multi-ip interfaces '0.0.0.0' and '*' into a connectable address Explicit IP addresses are returned unmodified. Parameters ---------- ip : IP address An IP address, or the special values 0.0.0.0, or * location: IP address, optional A public IP of the target machine. If location is an IP of the current machine, localhost will be returned, otherwise location will be returned. """ if ip in {"0.0.0.0", "*"}: if not location: # unspecified location, localhost is the only choice ip = localhost() elif is_public_ip(location): # location is a public IP on this machine, use localhost ip = localhost() elif not public_ips(): # this machine's public IPs cannot be determined, # assume `location` is not this machine warnings.warn("IPython could not determine public IPs", RuntimeWarning) ip = location else: # location is not this machine, do not use loopback ip = location return ip
def start(self): """Initialize workdir, logging, etc. in preparation for running jobs. """ # make a working directory for each job for job in self.jobs: job["workdir"] = os.path.join(self.workdir, job["description"]) fs.maybe_mkdir(job["workdir"]) # temporary ipython profile directory self.ipythondir = os.path.join(self.workdir, ".ipython") fs.maybe_mkdir(self.ipythondir) # log dir self.logdir = os.path.join(self.workdir, "log") fs.maybe_mkdir(self.logdir) # determine which IP we are going to listen on for logging try: self.listen_ip = localinterfaces.public_ips()[0] except: raise ValueError("This machine appears not to have" " any publicly visible IP addresses") # setup ZMQ logging self.handler = FileHandler(os.path.join(self.logdir, "dish.log")) self.listen_port = str(randint(5000, 10000)) self.subscriber = ZeroMQPullSubscriber("tcp://" + self.listen_ip + ":" + self.listen_port) self.controller = self.subscriber.dispatch_in_background(self.handler) self.logger = Logger("dish_master")
def disambiguate_ip_address(ip, location=None): """turn multi-ip interfaces '0.0.0.0' and '*' into connectable ones, based on the location (default interpretation of location is localhost).""" if ip in ('0.0.0.0', '*'): if location is None or is_public_ip(location) or not public_ips(): # If location is unspecified or cannot be determined, assume local ip = localhost() elif location: return location return ip
def save_connection_dict(self, fname, cdict): """save a connection dict to json file.""" c = self.config url = cdict['registration'] location = cdict['location'] if not location: if public_ips(): location = public_ips()[-1] else: self.log.warn("Could not identify this machine's IP, assuming %s." " You may need to specify '--location=<external_ip_address>' to help" " IPython decide when to connect via loopback." % localhost() ) location = localhost() cdict['location'] = location fname = os.path.join(self.profile_dir.security_dir, fname) self.log.info("writing connection info to %s", fname) with open(fname, 'w') as f: f.write(json.dumps(cdict, indent=2)) os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR)
def save_connection_dict(self, fname, cdict): """save a connection dict to json file.""" c = self.config url = cdict['registration'] location = cdict['location'] if not location: if public_ips(): location = public_ips()[-1] else: self.log.warn( "Could not identify this machine's IP, assuming %s." " You may need to specify '--location=<external_ip_address>' to help" " IPython decide when to connect via loopback." % localhost()) location = localhost() cdict['location'] = location fname = os.path.join(self.profile_dir.security_dir, fname) self.log.info("writing connection info to %s", fname) with open(fname, 'w') as f: f.write(json.dumps(cdict, indent=2)) os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR)
# Configuration file for Jupyter Hub c = get_config() # spawn with Docker c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner' # The docker instances need access to the Hub, so the default loopback port doesn't work: from IPython.utils.localinterfaces import public_ips c.JupyterHub.hub_ip = public_ips()[0] # OAuth with GitHub c.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator' c.Authenticator.whitelist = whitelist = set() c.Authenticator.admin_users = admin = set() import os join = os.path.join here = os.path.dirname(__file__) with open(join(here, 'userlist')) as f: for line in f: if not line: continue parts = line.split() name = parts[0] whitelist.add(name) if len(parts) > 1 and parts[1] == 'admin': admin.add(name)
# Configuration file for jupyterhub. import os c = get_config() c.JupyterHub.proxy_auth_token = 'c33333285d894fffce37e87705e811ecc06f7ad3e9c2c92a62dba7f1f6c7' c.JupyterHub.authenticator_class = 'textauthenticator.TextAuthenticator' # The docker instances need access to the Hub, so the default loopback port doesn't work: from IPython.utils.localinterfaces import public_ips c.JupyterHub.hub_ip = public_ips()[0] c.JupyterHub.data_files_path = '/datahub' c.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner' c.DockerSpawner.container_image = os.environ.get( 'CONTAINER_IMAGE', 'diasepfl/jupyterhub-singleuser') home_volume = os.environ.get('HOME_VOLUME', '') if home_volume: c.DockerSpawner.volumes = {home_volume: '/home/'} c.TextAuthenticator.passwdfile = passwdfile = os.environ.get( 'PASSWD_FILE', '/data/users.txt') c.JupyterHub.admin_users = admin = set() #adds admin users from the user list file with open(passwdfile) as f: users = [line.split() for line in f if line]
c = get_config() c.JupyterHub.authenticator_class = 'carinahub.CarinaAuth' c.JupyterHub.spawner_class = 'carinahub.CarinaSpawner' c.Spawner.use_docker_client_env = True c.Spawner.container_ip = '192.168.99.100' c.Spawner.remove_containers = True from IPython.utils.localinterfaces import public_ips c.JupyterHub.ip = public_ips()[0] c.JupyterHub.hub_ip = public_ips()[0] c.JupyterHub.hub_api_ip = public_ips()[0]
# Use GitHub OAuth to authenticate users config.JupyterHub.authenticator_class = 'oauthenticator.GitHubOAuthenticator' config.GitHubOAuthenticator.oauth_callback_url = 'https://206.12.96.12/hub/oauth_callback' config.GitHubOAuthenticator.client_id = 'a4b7e7154c6f9d8497fc' config.GitHubOAuthenticator.client_secret = '83784c5306df793900143b8d44aef24a379041ce' # set of usernames of admin users config.Authenticator.admin_users = ["fherwig", "syang", "lsiemens"] config.Authenticator.whitelist = config.Authenticator.admin_users # Spawn users in dockers config.JupyterHub.spawner_class = 'dockerspawner.DockerSpawner' config.DockerSpawner.container_image = "lsiemens/singleuser" config.DockerSpawner.extra_start_kwargs = {"network_mode":"host"} #create with --net=host # the docker instances need to access the HUB, to the default loopback port doesn't workd: from IPython.utils.localinterfaces import public_ips config.JupyterHub.hub_ip = public_ips()[-1] # ussing ssl so set to 443 config.JupyterHub.port = 443 config.JupyterHub.ssl_cert = '/etc/jupyterhub/SSL/ssl.crt' config.JupyterHub.ssl_key = '/etc/jupyterhub/SSL/ssl.key' # make cookie secret and auth token cookie = subprocess.Popen(["openssl", "rand", "2049"], stdout=subprocess.PIPE) token = subprocess.Popen(["openssl", "rand", "-hex", "129"], stdout=subprocess.PIPE) config.JupyterHub.cookie_secret = cookie.communicate()[0][:-1] config.JupyterHub.proxy_auth_token = token.communicate()[0][:-1]